diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt index 96cc14cb69..f54f74a1aa 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt @@ -253,6 +253,14 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis } } + override fun onDeleteChatLocationMessages(chatId: Long, messages: List) { + // TODO: handle notification? + val app = app() + if (app.settings.isShowingChatOnMap(chatId)) { + DeleteMessagesTask(app).executeOnExecutor(executor, messages) + } + } + override fun updateLocationMessages() { UpdateMessagesTask(app()).executeOnExecutor(executor) } @@ -267,6 +275,16 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis } } + private class DeleteMessagesTask(private val app: TelegramApplication) : AsyncTask, Void, Void?>() { + + override fun doInBackground(vararg messages: List): Void? { + for (list in messages) { + app.showLocationHelper.hideMessages(list) + } + return null + } + } + private class UpdateMessagesTask(private val app: TelegramApplication) : AsyncTask() { override fun doInBackground(vararg params: Void?): Void? { diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index 2676fc1aed..8c82b8665f 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -107,12 +107,15 @@ class ShowLocationHelper(private val app: TelegramApplication) { } fun hideChatMessages(chatId: Long) { + hideMessages(telegramHelper.getChatMessages(chatId)) + } + + fun hideMessages(messages: List) { execOsmandApi { - val messages = telegramHelper.getChatMessages(chatId) for (message in messages) { val user = telegramHelper.getUser(message.senderUserId) if (user != null) { - removeMapPoint(chatId, message) + removeMapPoint(message.chatId, message) } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index cf72e507b5..3cd053c849 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -174,6 +174,7 @@ class TelegramHelper private constructor() { interface TelegramIncomingMessagesListener { fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message) + fun onDeleteChatLocationMessages(chatId: Long, messages: List) fun updateLocationMessages() } @@ -913,10 +914,16 @@ class TelegramHelper private constructor() { val updateDeleteMessages = obj as TdApi.UpdateDeleteMessages if (updateDeleteMessages.isPermanent) { val chatId = updateDeleteMessages.chatId + val deletedMessages = mutableListOf() for (messageId in updateDeleteMessages.messageIds) { if (chatLiveMessages[chatId] == messageId) { chatLiveMessages.remove(chatId) - break + } + usersLocationMessages.remove(messageId)?.also { deletedMessages.add(it) } + } + if (deletedMessages.isNotEmpty()) { + incomingMessagesListeners.forEach { + it.onDeleteChatLocationMessages(chatId, deletedMessages) } } } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt index d93ac18973..34fbc8355c 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/ui/LiveNowTabFragment.kt @@ -124,6 +124,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage app.runInUIThread { updateList() } } + override fun onDeleteChatLocationMessages(chatId: Long, messages: List) { + app.runInUIThread { updateList() } + } + override fun updateLocationMessages() {} override fun updateLocation(location: Location?) {