Handle deletion of location messages

This commit is contained in:
Alex Sytnyk 2018-08-02 17:30:59 +03:00
parent d3b1900185
commit 3660357148
4 changed files with 35 additions and 3 deletions

View file

@ -253,6 +253,14 @@ class TelegramService : Service(), LocationListener, TelegramIncomingMessagesLis
}
}
override fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>) {
// 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<List<TdApi.Message>, Void, Void?>() {
override fun doInBackground(vararg messages: List<TdApi.Message>): Void? {
for (list in messages) {
app.showLocationHelper.hideMessages(list)
}
return null
}
}
private class UpdateMessagesTask(private val app: TelegramApplication) : AsyncTask<Void, Void, Void?>() {
override fun doInBackground(vararg params: Void?): Void? {

View file

@ -107,12 +107,15 @@ class ShowLocationHelper(private val app: TelegramApplication) {
}
fun hideChatMessages(chatId: Long) {
hideMessages(telegramHelper.getChatMessages(chatId))
}
fun hideMessages(messages: List<TdApi.Message>) {
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)
}
}
}

View file

@ -174,6 +174,7 @@ class TelegramHelper private constructor() {
interface TelegramIncomingMessagesListener {
fun onReceiveChatLocationMessages(chatId: Long, vararg messages: TdApi.Message)
fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>)
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<TdApi.Message>()
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)
}
}
}

View file

@ -124,6 +124,10 @@ class LiveNowTabFragment : Fragment(), TelegramListener, TelegramIncomingMessage
app.runInUIThread { updateList() }
}
override fun onDeleteChatLocationMessages(chatId: Long, messages: List<TdApi.Message>) {
app.runInUIThread { updateList() }
}
override fun updateLocationMessages() {}
override fun updateLocation(location: Location?) {