Create processScannedLocationsForChat for scanned locations

This commit is contained in:
Chumva 2019-02-15 15:15:42 +02:00
parent 8cb762cde2
commit 2dbb2b657e
2 changed files with 14 additions and 16 deletions

View file

@ -92,7 +92,7 @@ class LocationMessages(val app: TelegramApplication) {
if (content != null) { if (content != null) {
val deviceName = if (content is OsmandLocationUtils.MessageOsmAndBotLocation) content.deviceName else "" val deviceName = if (content is OsmandLocationUtils.MessageOsmAndBotLocation) content.deviceName else ""
val previousLocationMessage = lastLocationPoints.sortedBy { it.time }.firstOrNull { val previousLocationMessage = lastLocationPoints.sortedBy { it.time }.firstOrNull {
it.userId == senderId && it.chatId == message.chatId && it.type == type && it.deviceName == deviceName it.userId == senderId && it.chatId == message.chatId && it.deviceName == deviceName && it.type == type
} }
if (previousLocationMessage == null || content.lastUpdated * 1000L > previousLocationMessage.time) { if (previousLocationMessage == null || content.lastUpdated * 1000L > previousLocationMessage.time) {
log.debug("addNewLocationMessage passed ${message.id}") log.debug("addNewLocationMessage passed ${message.id}")

View file

@ -605,16 +605,18 @@ class TelegramHelper private constructor() {
log.debug("scanChatHistory searchMessageId: ${lastMessage.id}") log.debug("scanChatHistory searchMessageId: ${lastMessage.id}")
} else { } else {
log.debug("scanChatHistory finishForChat: $chatId") log.debug("scanChatHistory finishForChat: $chatId")
if (locations.isNotEmpty()) { processScannedLocationsForChat(chatId, locations)
locations.sortBy { message -> OsmandLocationUtils.getLastUpdatedTime(message) }
updateLastMessage(locations.last())
incomingMessagesListeners.forEach {
it.onReceiveChatLocationMessages(chatId, *locations.toTypedArray())
}
}
} }
} else { } else {
log.debug("scanChatHistory finishForChat: $chatId") log.debug("scanChatHistory finishForChat: $chatId")
processScannedLocationsForChat(chatId, locations)
}
}
}
}
}
private fun processScannedLocationsForChat(chatId: Long, locations: MutableList<TdApi.Message>) {
if (locations.isNotEmpty()) { if (locations.isNotEmpty()) {
locations.sortBy { message -> OsmandLocationUtils.getLastUpdatedTime(message) } locations.sortBy { message -> OsmandLocationUtils.getLastUpdatedTime(message) }
updateLastMessage(locations.last()) updateLastMessage(locations.last())
@ -623,10 +625,6 @@ class TelegramHelper private constructor() {
} }
} }
} }
}
}
}
}
private fun requestUser(id: Int) { private fun requestUser(id: Int) {
client?.send(TdApi.GetUser(id)) { obj -> client?.send(TdApi.GetUser(id)) { obj ->