Merge branch 'master' of ssh://github.com/osmandapp/Osmand into TelegramUiImprovements
# Conflicts: # OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt
This commit is contained in:
commit
4c44b70b00
1 changed files with 32 additions and 52 deletions
|
@ -7,7 +7,6 @@ import org.drinkless.td.libcore.telegram.Client
|
||||||
import org.drinkless.td.libcore.telegram.Client.ResultHandler
|
import org.drinkless.td.libcore.telegram.Client.ResultHandler
|
||||||
import org.drinkless.td.libcore.telegram.TdApi
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
import org.drinkless.td.libcore.telegram.TdApi.AuthorizationState
|
import org.drinkless.td.libcore.telegram.TdApi.AuthorizationState
|
||||||
import org.json.JSONObject
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
@ -28,6 +27,9 @@ class TelegramHelper private constructor() {
|
||||||
private const val UPDATE_LIVE_MESSAGES_INTERVAL_SEC = 30L
|
private const val UPDATE_LIVE_MESSAGES_INTERVAL_SEC = 30L
|
||||||
private const val MESSAGE_ACTIVE_TIME_SEC = 24 * 60 * 60 // 24 hours
|
private const val MESSAGE_ACTIVE_TIME_SEC = 24 * 60 * 60 // 24 hours
|
||||||
|
|
||||||
|
private const val DEVICE_PREFIX = "Device: "
|
||||||
|
private const val LOCATION_PREFIX = "Location: "
|
||||||
|
|
||||||
// min and max values for the Telegram API
|
// min and max values for the Telegram API
|
||||||
const val MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 61
|
const val MIN_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 61
|
||||||
const val MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 60 * 60 * 24 - 1 // one day
|
const val MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC = 60 * 60 * 24 - 1 // one day
|
||||||
|
@ -636,67 +638,45 @@ class TelegramHelper private constructor() {
|
||||||
val content = content
|
val content = content
|
||||||
return when (content) {
|
return when (content) {
|
||||||
is TdApi.MessageLocation -> true
|
is TdApi.MessageLocation -> true
|
||||||
is TdApi.MessageText -> {
|
is TdApi.MessageText -> isOsmAndBot(senderUserId) || isOsmAndBot(viaBotUserId)
|
||||||
if (content.text.text.startsWith("{")) {
|
|
||||||
// TODO: get user from library if null
|
|
||||||
if (isOsmAndBot(senderUserId)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseOsmAndBotLocation(json: String): MessageOsmAndBotLocation {
|
private fun parseOsmAndBotLocation(text: String): MessageOsmAndBotLocation {
|
||||||
val obj = JSONObject(json)
|
val res = MessageOsmAndBotLocation()
|
||||||
return MessageOsmAndBotLocation(
|
for (s in text.lines()) {
|
||||||
obj.optString("name", ""),
|
when {
|
||||||
obj.optDouble("lat", -1.0),
|
s.startsWith(DEVICE_PREFIX) -> {
|
||||||
obj.optDouble("lon", -1.0),
|
res.name = s.removePrefix(DEVICE_PREFIX)
|
||||||
obj.optDouble("alt", -1.0),
|
}
|
||||||
obj.optDouble("azi", -1.0),
|
s.startsWith(LOCATION_PREFIX) -> {
|
||||||
obj.optDouble("spd", -1.0),
|
val locStr = s.removePrefix(LOCATION_PREFIX)
|
||||||
obj.optInt("updAgo", -1),
|
try {
|
||||||
obj.optInt("locAgo", -1),
|
val (latS, lonS) = locStr.split(" ")
|
||||||
obj.optInt("updId", -1),
|
res.lat = latS.dropLast(1).toDouble()
|
||||||
obj.optInt("updTime", -1)
|
res.lon = lonS.toDouble()
|
||||||
)
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseOsmAndBotLocation(message: TdApi.Message): MessageOsmAndBotLocation {
|
class MessageOsmAndBotLocation : TdApi.MessageContent() {
|
||||||
val messageLocation = message.content as TdApi.MessageLocation
|
|
||||||
return MessageOsmAndBotLocation(
|
|
||||||
getOsmAndBotDeviceName(message),
|
|
||||||
messageLocation.location.latitude,
|
|
||||||
messageLocation.location.longitude,
|
|
||||||
-1.0,
|
|
||||||
-1.0,
|
|
||||||
-1.0,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
class MessageOsmAndBotLocation internal constructor(
|
var name: String = ""
|
||||||
val name: String,
|
internal set
|
||||||
val lat: Double,
|
var lat: Double = Double.NaN
|
||||||
val lon: Double,
|
internal set
|
||||||
val alt: Double,
|
var lon: Double = Double.NaN
|
||||||
val azi: Double,
|
internal set
|
||||||
val spd: Double,
|
|
||||||
val updAgo: Int,
|
|
||||||
val locAgo: Int,
|
|
||||||
val updId: Int,
|
|
||||||
val updTime: Int
|
|
||||||
) : TdApi.MessageContent() {
|
|
||||||
|
|
||||||
override fun getConstructor() = -1
|
override fun getConstructor() = -1
|
||||||
|
|
||||||
fun isValid() = name != "" && lat != -1.0 && lon != -1.0
|
fun isValid() = name != "" && lat != Double.NaN && lon != Double.NaN
|
||||||
}
|
}
|
||||||
|
|
||||||
class OrderedChat internal constructor(internal val order: Long, internal val chatId: Long, internal val isChannel: Boolean) : Comparable<OrderedChat> {
|
class OrderedChat internal constructor(internal val order: Long, internal val chatId: Long, internal val isChannel: Boolean) : Comparable<OrderedChat> {
|
||||||
|
|
Loading…
Reference in a new issue