diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index e787c6036c..73489acfdf 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -144,15 +144,17 @@ class TelegramHelper private constructor() { fun getChatLiveMessages() = chatLiveMessages - fun getMessagesByChatIds(): Map> { + fun getMessagesByChatIds(messageExpTime: Long): Map> { val res = mutableMapOf>() for (message in usersLocationMessages.values) { - var messages = res[message.chatId] - if (messages != null) { - messages.add(message) - } else { - messages = mutableListOf(message) - res[message.chatId] = messages + if (System.currentTimeMillis() / 1000 - getLastUpdatedTime(message) < messageExpTime) { + var messages = res[message.chatId] + if (messages != null) { + messages.add(message) + } else { + messages = mutableListOf(message) + res[message.chatId] = messages + } } } return res @@ -178,9 +180,18 @@ class TelegramHelper private constructor() { return chat.type is TdApi.ChatTypeSupergroup || chat.type is TdApi.ChatTypeBasicGroup } - fun getLastUpdatedTime(message: TdApi.Message) = Math.max(message.editDate, message.date) + fun getLastUpdatedTime(message: TdApi.Message): Int { + val content = message.content + return if (content is MessageOsmAndBotLocation) { + content.lastUpdated + } else { + Math.max(message.editDate, message.date) + } + } fun isPrivateChat(chat: TdApi.Chat): Boolean = chat.type is TdApi.ChatTypePrivate + + fun isSecretChat(chat: TdApi.Chat): Boolean = chat.type is TdApi.ChatTypeSecret private fun isChannel(chat: TdApi.Chat): Boolean { return chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel @@ -322,6 +333,12 @@ class TelegramHelper private constructor() { return deviceName } + fun getUserIdFromChatType(type: TdApi.ChatType) = when (type) { + is TdApi.ChatTypePrivate -> type.userId + is TdApi.ChatTypeSecret -> type.userId + else -> 0 + } + fun isOsmAndBot(userId: Int) = users[userId]?.username == OSMAND_BOT_USERNAME fun isBot(userId: Int) = users[userId]?.type is TdApi.UserTypeBot @@ -882,8 +899,6 @@ class TelegramHelper private constructor() { internal set var lastUpdated: Int = 0 internal set - var created: Int = 0 - internal set override fun getConstructor() = -1 diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt index 2146140780..96a40db3fa 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramUiHelper.kt @@ -53,7 +53,7 @@ object TelegramUiHelper { } val type = chat.type if (type is TdApi.ChatTypePrivate || type is TdApi.ChatTypeSecret) { - val userId = getUserIdFromChatType(type) + val userId = helper.getUserIdFromChatType(type) val chatWithBot = helper.isBot(userId) res.privateChat = true res.chatWithBot = chatWithBot @@ -82,12 +82,6 @@ object TelegramUiHelper { return res } - private fun getUserIdFromChatType(type: TdApi.ChatType) = when (type) { - is TdApi.ChatTypePrivate -> type.userId - is TdApi.ChatTypeSecret -> type.userId - else -> 0 - } - fun getUserName(user: TdApi.User): String { var name = "${user.firstName} ${user.lastName}".trim() if (name.isEmpty()) { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index 184fc5896e..dc87f0ca2b 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -212,13 +212,13 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage private fun updateLocationUi() { if (locationUiUpdateAllowed) { - app.runInUIThread { adapter.notifyDataSetChanged() } + app.runInUIThread { updateList() } } } private fun updateList() { val res = mutableListOf() - for ((id, messages) in telegramHelper.getMessagesByChatIds()) { + for ((id, messages) in telegramHelper.getMessagesByChatIds(settings.locHistoryTime)) { telegramHelper.getChat(id)?.also { chat -> res.add(TelegramUiHelper.chatToChatItem(telegramHelper, chat, messages)) val type = chat.type