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

@ -91,8 +91,8 @@ class LocationMessages(val app: TelegramApplication) {
val content = OsmandLocationUtils.parseMessageContent(message, app.telegramHelper) val content = OsmandLocationUtils.parseMessageContent(message, app.telegramHelper)
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,29 +605,27 @@ 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")
if (locations.isNotEmpty()) { processScannedLocationsForChat(chatId, locations)
locations.sortBy { message -> OsmandLocationUtils.getLastUpdatedTime(message) }
updateLastMessage(locations.last())
incomingMessagesListeners.forEach {
it.onReceiveChatLocationMessages(chatId, *locations.toTypedArray())
}
}
} }
} }
} }
} }
} }
private fun processScannedLocationsForChat(chatId: Long, locations: MutableList<TdApi.Message>) {
if (locations.isNotEmpty()) {
locations.sortBy { message -> OsmandLocationUtils.getLastUpdatedTime(message) }
updateLastMessage(locations.last())
incomingMessagesListeners.forEach {
it.onReceiveChatLocationMessages(chatId, *locations.toTypedArray())
}
}
}
private fun requestUser(id: Int) { private fun requestUser(id: Int) {
client?.send(TdApi.GetUser(id)) { obj -> client?.send(TdApi.GetUser(id)) { obj ->
when (obj.constructor) { when (obj.constructor) {