Refactor TelegramHelper#addNewMessage

This commit is contained in:
Alex Sytnyk 2018-08-16 12:23:50 +03:00
parent 36cfa5d42d
commit 4ca99c10ee

View file

@ -481,13 +481,14 @@ class TelegramHelper private constructor() {
private fun addNewMessage(message: TdApi.Message) { private fun addNewMessage(message: TdApi.Message) {
if (message.isAppropriate()) { if (message.isAppropriate()) {
val fromBot = isOsmAndBot(message.senderUserId)
val viaBot = isOsmAndBot(message.viaBotUserId)
val oldContent = message.content val oldContent = message.content
if (oldContent is TdApi.MessageText) { if (oldContent is TdApi.MessageText) {
val messageOsmAndBotLocation = parseOsmAndBotLocation(oldContent.text.text) message.content = parseOsmAndBotLocation(oldContent.text.text).apply {
messageOsmAndBotLocation.created = message.date created = message.date
message.content = messageOsmAndBotLocation }
} else if (oldContent is TdApi.MessageLocation && } else if (oldContent is TdApi.MessageLocation && (fromBot || viaBot)) {
(isOsmAndBot(message.senderUserId) || isOsmAndBot(message.viaBotUserId))) {
message.content = parseOsmAndBotLocation(message) message.content = parseOsmAndBotLocation(message)
} }
removeOldMessages(message.senderUserId, message.chatId) removeOldMessages(message.senderUserId, message.chatId)