Fix tracker compilation first part

This commit is contained in:
Vitaliy 2020-12-08 20:38:28 +02:00
parent e625e4d101
commit 8f19b7cdb4
2 changed files with 47 additions and 35 deletions

View file

@ -386,7 +386,7 @@ class ShareLocationHelper(private val app: TelegramApplication) {
} }
app.locationMessages.removeBufferedMessage(locationMessage) app.locationMessages.removeBufferedMessage(locationMessage)
if ((shareInfo.shouldSendViaBotTextMessage || shareInfo.shouldSendViaBotMapMessage) && osmandBotId != -1 && device != null) { if ((shareInfo.shouldSendViaBotTextMessage || shareInfo.shouldSendViaBotMapMessage) && osmandBotId != -1 && device != null) {
app.telegramHelper.sendViaBotLocationMessage(osmandBotId, shareInfo, TdApi.Location(locationMessage.lat, locationMessage.lon), device, shareType) app.telegramHelper.sendViaBotLocationMessage(osmandBotId, shareInfo, TdApi.Location(locationMessage.lat, locationMessage.lon, locationMessage.hdop), device, shareType)
shareInfo.shouldSendViaBotTextMessage = false shareInfo.shouldSendViaBotTextMessage = false
shareInfo.shouldSendViaBotMapMessage = false shareInfo.shouldSendViaBotMapMessage = false
} }

View file

@ -443,7 +443,7 @@ class TelegramHelper private constructor() {
var offsetChatId: Long = 0 var offsetChatId: Long = 0
if (!chatList.isEmpty()) { if (!chatList.isEmpty()) {
val last = chatList.last() val last = chatList.last()
offsetOrder = last.order offsetOrder = last.position.order
offsetChatId = last.chatId offsetChatId = last.chatId
} }
client?.send(TdApi.GetChats(TdApi.ChatListMain(), offsetOrder, offsetChatId, CHATS_LIMIT - chatList.size)) { obj -> client?.send(TdApi.GetChats(TdApi.ChatListMain(), offsetOrder, offsetChatId, CHATS_LIMIT - chatList.size)) { obj ->
@ -533,8 +533,8 @@ class TelegramHelper private constructor() {
} }
resultArticles.forEach { resultArticles.forEach {
shareInfo.lastTextMessageHandled = false shareInfo.lastTextMessageHandled = false
val sendOptions = TdApi.SendMessageOptions(true, true, null) val sendOptions = TdApi.MessageSendOptions(true, true, null)
client?.send(TdApi.SendInlineQueryResultMessage(shareInfo.chatId, 0, sendOptions, client?.send(TdApi.SendInlineQueryResultMessage(shareInfo.chatId, 0, 0, sendOptions,
inlineQueryResults.inlineQueryId, it.id, false)) { obj -> inlineQueryResults.inlineQueryId, it.id, false)) { obj ->
handleTextLocationMessageUpdate(obj, shareInfo, true) handleTextLocationMessageUpdate(obj, shareInfo, true)
} }
@ -843,7 +843,12 @@ class TelegramHelper private constructor() {
if (!shareInfo.isMapMessageIdPresent() && shareInfo.chatId != -1L) { if (!shareInfo.isMapMessageIdPresent() && shareInfo.chatId != -1L) {
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt() shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
client?.send( client?.send(
TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId, null, null)) { obj -> TdApi.EditMessageLiveLocation(
shareInfo.chatId, shareInfo.currentMapMessageId,
null, null, 0, 0
)
)
{ obj ->
handleMapLocationMessageUpdate(obj, shareInfo, false) handleMapLocationMessageUpdate(obj, shareInfo, false)
} }
} }
@ -863,8 +868,8 @@ class TelegramHelper private constructor() {
shareInfo.pendingTdLibText++ shareInfo.pendingTdLibText++
shareInfo.lastSendTextMessageTime = (System.currentTimeMillis() / 1000).toInt() shareInfo.lastSendTextMessageTime = (System.currentTimeMillis() / 1000).toInt()
log.error("sendNewTextLocation ${shareInfo.pendingTdLibText}") log.error("sendNewTextLocation ${shareInfo.pendingTdLibText}")
val sendOptions = TdApi.SendMessageOptions(false, true, null) val sendOptions = TdApi.MessageSendOptions(false, true, null)
client?.send(TdApi.SendMessage(shareInfo.chatId, 0, sendOptions, null, content)) { obj -> client?.send(TdApi.SendMessage(shareInfo.chatId, 0, 0, sendOptions, null, content)) { obj ->
handleTextLocationMessageUpdate(obj, shareInfo, false) handleTextLocationMessageUpdate(obj, shareInfo, false)
} }
} }
@ -883,21 +888,21 @@ class TelegramHelper private constructor() {
fun sendNewMapLocation(shareInfo: ShareChatInfo, locationMessage: LocationMessages.BufferMessage) { fun sendNewMapLocation(shareInfo: ShareChatInfo, locationMessage: LocationMessages.BufferMessage) {
needRefreshActiveLiveLocationMessages = true needRefreshActiveLiveLocationMessages = true
val location = TdApi.Location(locationMessage.lat, locationMessage.lon) val location = TdApi.Location(locationMessage.lat, locationMessage.lon, locationMessage.hdop)
val livePeriod = val livePeriod =
if (shareInfo.currentMessageLimit > (shareInfo.start + MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC)) { if (shareInfo.currentMessageLimit > (shareInfo.start + MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC)) {
MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC MAX_LOCATION_MESSAGE_LIVE_PERIOD_SEC
} else { } else {
shareInfo.livePeriod.toInt() shareInfo.livePeriod.toInt()
} }
val content = TdApi.InputMessageLocation(location, livePeriod) val content = TdApi.InputMessageLocation(location, livePeriod, locationMessage.bearing.toInt(), 0)
if (!shareInfo.pendingMapMessage) { if (!shareInfo.pendingMapMessage) {
shareInfo.pendingMapMessage = true shareInfo.pendingMapMessage = true
shareInfo.pendingTdLibMap++ shareInfo.pendingTdLibMap++
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt() shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
log.error("sendNewMapLocation ${shareInfo.pendingTdLibMap}") log.error("sendNewMapLocation ${shareInfo.pendingTdLibMap}")
val sendOptions = TdApi.SendMessageOptions(false, true, null) val sendOptions = TdApi.MessageSendOptions(false, true, null)
client?.send(TdApi.SendMessage(shareInfo.chatId, 0, sendOptions, null, content)) { obj -> client?.send(TdApi.SendMessage(shareInfo.chatId, 0, 0, sendOptions, null, content)) { obj ->
handleMapLocationMessageUpdate(obj, shareInfo, false) handleMapLocationMessageUpdate(obj, shareInfo, false)
} }
} }
@ -905,12 +910,13 @@ class TelegramHelper private constructor() {
fun editMapLocation(shareInfo: ShareChatInfo, locationMessage: LocationMessages.BufferMessage) { fun editMapLocation(shareInfo: ShareChatInfo, locationMessage: LocationMessages.BufferMessage) {
needRefreshActiveLiveLocationMessages = true needRefreshActiveLiveLocationMessages = true
val location = TdApi.Location(locationMessage.lat, locationMessage.lon) val location = TdApi.Location(locationMessage.lat, locationMessage.lon, locationMessage.hdop)
if (shareInfo.currentMapMessageId!=-1L) { if (shareInfo.currentMapMessageId!=-1L) {
shareInfo.pendingTdLibMap++ shareInfo.pendingTdLibMap++
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt() shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
log.info("editMapLocation ${shareInfo.currentMapMessageId} pendingTdLibMap: ${shareInfo.pendingTdLibMap}") log.info("editMapLocation ${shareInfo.currentMapMessageId} pendingTdLibMap: ${shareInfo.pendingTdLibMap}")
client?.send(TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId, null, location)) { obj -> client?.send(TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId,
null, location, locationMessage.bearing.toInt(), 0)) { obj ->
handleMapLocationMessageUpdate(obj, shareInfo, false) handleMapLocationMessageUpdate(obj, shareInfo, false)
} }
} }
@ -1080,18 +1086,21 @@ class TelegramHelper private constructor() {
} }
} }
private fun setChatOrder(chat: TdApi.Chat, order: Long) { private fun setChatPositions(chat: TdApi.Chat, positions: Array<TdApi.ChatPosition>) {
synchronized(chatList) { synchronized(chatList) {
synchronized(chat) {
val isChannel = isChannel(chat) val isChannel = isChannel(chat)
for (position in chat.positions) {
if (chat.order != 0L) { if (position.list.constructor == TdApi.ChatListMain.CONSTRUCTOR) {
chatList.remove(OrderedChat(chat.order, chat.id, isChannel)) chatList.remove(OrderedChat(chat.id, position, isChannel))
}
}
chat.positions = positions
for (position in chat.positions) {
if (position.list.constructor == TdApi.ChatListMain.CONSTRUCTOR) {
chatList.add(OrderedChat(chat.id, position, isChannel))
}
} }
chat.order = order
if (chat.order != 0L) {
chatList.add(OrderedChat(chat.order, chat.id, isChannel))
} }
} }
} }
@ -1188,11 +1197,15 @@ class TelegramHelper private constructor() {
} }
} }
class OrderedChat internal constructor(internal val order: Long, internal val chatId: Long, internal val isChannel: Boolean) : Comparable<OrderedChat> { class OrderedChat internal constructor(
internal val chatId: Long,
internal val position: TdApi.ChatPosition,
internal val isChannel: Boolean
) : Comparable<OrderedChat> {
override fun compareTo(other: OrderedChat): Int { override fun compareTo(other: OrderedChat): Int {
if (this.order != other.order) { if (this.position.order != other.position.order) {
return if (other.order < this.order) -1 else 1 return if (other.position.order < this.position.order) -1 else 1
} }
return if (this.chatId != other.chatId) { return if (this.chatId != other.chatId) {
if (other.chatId < this.chatId) -1 else 1 if (other.chatId < this.chatId) -1 else 1
@ -1206,12 +1219,11 @@ class TelegramHelper private constructor() {
if (other !is OrderedChat) { if (other !is OrderedChat) {
return false return false
} }
val o = other as OrderedChat? return this.chatId == other.chatId && this.position.order == other.position.order;
return this.order == o!!.order && this.chatId == o.chatId
} }
override fun hashCode(): Int { override fun hashCode(): Int {
return (order + chatId).hashCode() return (position.order + chatId).hashCode()
} }
} }
@ -1288,9 +1300,9 @@ class TelegramHelper private constructor() {
} }
} }
} }
val order = chat.order val positions = chat.positions
chat.order = 0 chat.positions = arrayOfNulls(0)
setChatOrder(chat, order) setChatPositions(chat, positions)
} }
listener?.onTelegramChatsChanged() listener?.onTelegramChatsChanged()
} }
@ -1320,7 +1332,7 @@ class TelegramHelper private constructor() {
if (chat != null) { if (chat != null) {
synchronized(chat) { synchronized(chat) {
chat.lastMessage = updateChat.lastMessage chat.lastMessage = updateChat.lastMessage
setChatOrder(chat, updateChat.order) setChatPositions(chat, updateChat.positions);
} }
//listener?.onTelegramChatsChanged() //listener?.onTelegramChatsChanged()
} }
@ -1453,7 +1465,7 @@ class TelegramHelper private constructor() {
if (chat != null) { if (chat != null) {
synchronized(chat) { synchronized(chat) {
chat.draftMessage = updateChat.draftMessage chat.draftMessage = updateChat.draftMessage
setChatOrder(chat, updateChat.order) setChatPositions(chat, updateChat.positions)
} }
//listener?.onTelegramChatsChanged() //listener?.onTelegramChatsChanged()
} }