Merge pull request #6129 from osmandapp/TelegramFixes

Fix sending many location messages after adding sharing time
This commit is contained in:
Alexander Sytnyk 2018-10-03 18:08:19 +03:00 committed by GitHub
commit ab1fc95168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View file

@ -71,6 +71,8 @@ class TelegramHelper private constructor() {
private val chats = ConcurrentHashMap<Long, TdApi.Chat>()
private val chatList = TreeSet<OrderedChat>()
private val chatLiveMessages = ConcurrentHashMap<Long, TdApi.Message>()
private val pausedLiveChatIds = mutableListOf<Long>()
private val downloadChatFilesMap = ConcurrentHashMap<String, TdApi.Chat>()
private val downloadUserFilesMap = ConcurrentHashMap<String, TdApi.User>()
@ -595,6 +597,28 @@ class TelegramHelper private constructor() {
needRefreshActiveLiveLocationMessages = true
}
fun pauseSendingLiveLocationToChat(chatId: Long) {
synchronized(pausedLiveChatIds) {
pausedLiveChatIds.add(chatId)
}
}
fun resumeSendingLiveLocationToChat(chatId: Long) {
synchronized(pausedLiveChatIds) {
pausedLiveChatIds.remove(chatId)
}
}
fun deleteLiveLocationMessage(chatId: Long) {
val msgId = chatLiveMessages[chatId]?.id
if (msgId != null && msgId != 0L) {
val array = LongArray(1)
array[0] = msgId
client?.send(TdApi.DeleteMessages(chatId, array, true), UpdatesHandler())
}
needRefreshActiveLiveLocationMessages = true
}
fun stopSendingLiveLocationMessages() {
chatLiveMessages.forEach { (chatId, _ )->
stopSendingLiveLocationToChat(chatId)
@ -632,6 +656,11 @@ class TelegramHelper private constructor() {
private fun sendLiveLocationImpl(chatLivePeriods: Map<Long, Long>, latitude: Double, longitude: Double) {
val location = TdApi.Location(latitude, longitude)
chatLivePeriods.forEach { (chatId, livePeriod) ->
synchronized(pausedLiveChatIds) {
if (pausedLiveChatIds.contains(chatId)) {
return@forEach
}
}
val content = TdApi.InputMessageLocation(location, livePeriod.toInt())
val msgId = chatLiveMessages[chatId]?.id
if (msgId != null) {

View file

@ -581,10 +581,10 @@ class MyLocationTabFragment : Fragment(), TelegramListener {
setOnClickListener {
val chatNextAddTime = settings.getChatNextAddActiveTime(chat.id)
val newLivePeriod = settings.getChatLiveMessageExpireTime(chat.id) + settings.getChatAddActiveTime(chat.id)
settings.shareLocationToChat(chat.id, false)
telegramHelper.stopSendingLiveLocationToChat(chat.id)
settings.shareLocationToChat(chat.id, true, newLivePeriod, chatNextAddTime)
app.forceUpdateMyLocation()
telegramHelper.pauseSendingLiveLocationToChat(chat.id)
telegramHelper.deleteLiveLocationMessage(chat.id)
telegramHelper.resumeSendingLiveLocationToChat(chat.id)
notifyItemChanged(position)
}
}