add ability to stop sending live messages in telegram

This commit is contained in:
Chumva 2018-08-13 16:08:03 +03:00
parent cc256f6a35
commit 4985db672b
2 changed files with 30 additions and 1 deletions

View file

@ -535,6 +535,33 @@ class TelegramHelper private constructor() {
return false
}
fun stopSendingLiveLocationToChat(chatId: Long) {
val msgId = chatLiveMessages[chatId]?.id
if (msgId != null) {
if (msgId != 0L) {
client?.send(
TdApi.EditMessageLiveLocation(chatId, msgId, null, null),
liveLocationMessageUpdatesHandler
)
}
}
chatLiveMessages.remove(chatId)
needRefreshActiveLiveLocationMessages = true
}
fun stopSendingLiveLocationMessages() {
chatLiveMessages.forEach { chatId, message ->
if (message.id != 0L) {
client?.send(
TdApi.EditMessageLiveLocation(chatId, message.id, null, null),
liveLocationMessageUpdatesHandler
)
}
}
chatLiveMessages.clear()
needRefreshActiveLiveLocationMessages = true
}
private fun getActiveLiveLocationMessages(onComplete: (() -> Unit)?) {
requestingActiveLiveLocationMessages = true
client?.send(TdApi.GetActiveLiveLocationMessages()) { obj ->

View file

@ -180,6 +180,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
sharingMode = isChecked
app.settings.stopSharingLocationToChats()
app.shareLocationHelper.stopSharingLocation()
telegramHelper.stopSendingLiveLocationMessages()
updateContent()
}
}
@ -484,7 +485,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
setOnCheckedChangeListener { _, isChecked ->
if (!isChecked) {
app.settings.shareLocationToChat(chat.id, false)
app.shareLocationHelper.stopSharingLocation()
telegramHelper.stopSendingLiveLocationToChat(chat.id)
removeItem(chat)
}
}
@ -551,6 +552,7 @@ class MyLocationTabFragment : Fragment(), TelegramListener, ChatLiveMessagesList
if (chats.isEmpty()) {
sharingMode = false
updateContent()
app.shareLocationHelper.stopSharingLocation()
} else {
adapter.notifyDataSetChanged()
}