Merge pull request #5778 from osmandapp/TelegramUiImprovements
Parse new map locations
This commit is contained in:
commit
dcac4cb6a8
1 changed files with 28 additions and 0 deletions
|
@ -255,6 +255,19 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getOsmAndBotDeviceName(message: TdApi.Message): String {
|
||||||
|
var deviceName = ""
|
||||||
|
if (message.replyMarkup is TdApi.ReplyMarkupInlineKeyboard) {
|
||||||
|
val replyMarkup = message.replyMarkup as TdApi.ReplyMarkupInlineKeyboard
|
||||||
|
try {
|
||||||
|
deviceName = replyMarkup.rows[0][1].text.split("\\s".toRegex())[1]
|
||||||
|
} catch (e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceName
|
||||||
|
}
|
||||||
|
|
||||||
fun isOsmAndBot(userId: Int) = users[userId]?.username == OSMAND_BOT_USERNAME
|
fun isOsmAndBot(userId: Int) = users[userId]?.username == OSMAND_BOT_USERNAME
|
||||||
|
|
||||||
fun isBot(userId: Int) = users[userId]?.type is TdApi.UserTypeBot
|
fun isBot(userId: Int) = users[userId]?.type is TdApi.UserTypeBot
|
||||||
|
@ -386,6 +399,9 @@ class TelegramHelper private constructor() {
|
||||||
val oldContent = message.content
|
val oldContent = message.content
|
||||||
if (oldContent is TdApi.MessageText) {
|
if (oldContent is TdApi.MessageText) {
|
||||||
message.content = parseOsmAndBotLocation(oldContent.text.text)
|
message.content = parseOsmAndBotLocation(oldContent.text.text)
|
||||||
|
} else if (oldContent is TdApi.MessageLocation &&
|
||||||
|
(isOsmAndBot(message.senderUserId) || isOsmAndBot(message.viaBotUserId))) {
|
||||||
|
message.content = parseOsmAndBotLocation(message)
|
||||||
}
|
}
|
||||||
removeOldMessages(message.senderUserId, message.chatId)
|
removeOldMessages(message.senderUserId, message.chatId)
|
||||||
usersLocationMessages[message.id] = message
|
usersLocationMessages[message.id] = message
|
||||||
|
@ -634,6 +650,15 @@ class TelegramHelper private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun parseOsmAndBotLocation(message: TdApi.Message): MessageOsmAndBotLocation {
|
||||||
|
val messageLocation = message.content as TdApi.MessageLocation
|
||||||
|
val res = MessageOsmAndBotLocation()
|
||||||
|
res.name = getOsmAndBotDeviceName(message)
|
||||||
|
res.lat = messageLocation.location.latitude
|
||||||
|
res.lon = messageLocation.location.longitude
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
private fun parseOsmAndBotLocation(text: String): MessageOsmAndBotLocation {
|
private fun parseOsmAndBotLocation(text: String): MessageOsmAndBotLocation {
|
||||||
val res = MessageOsmAndBotLocation()
|
val res = MessageOsmAndBotLocation()
|
||||||
for (s in text.lines()) {
|
for (s in text.lines()) {
|
||||||
|
@ -877,6 +902,9 @@ class TelegramHelper private constructor() {
|
||||||
val newContent = updateMessageContent.newContent
|
val newContent = updateMessageContent.newContent
|
||||||
message.content = if (newContent is TdApi.MessageText) {
|
message.content = if (newContent is TdApi.MessageText) {
|
||||||
parseOsmAndBotLocation(newContent.text.text)
|
parseOsmAndBotLocation(newContent.text.text)
|
||||||
|
} else if (newContent is TdApi.MessageLocation &&
|
||||||
|
(isOsmAndBot(message.senderUserId) || isOsmAndBot(message.viaBotUserId))) {
|
||||||
|
parseOsmAndBotLocation(message)
|
||||||
} else {
|
} else {
|
||||||
newContent
|
newContent
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue