Fix chats order

This commit is contained in:
Vitaliy 2020-12-08 21:29:23 +02:00
parent 8f19b7cdb4
commit e47fd457a7
2 changed files with 36 additions and 26 deletions

View file

@ -1086,7 +1086,7 @@ class TelegramHelper private constructor() {
}
}
private fun setChatPositions(chat: TdApi.Chat, positions: Array<TdApi.ChatPosition>) {
private fun setChatPositions(chat: TdApi.Chat, positions: Array<TdApi.ChatPosition?>) {
synchronized(chatList) {
synchronized(chat) {
val isChannel = isChannel(chat)
@ -1337,23 +1337,33 @@ class TelegramHelper private constructor() {
//listener?.onTelegramChatsChanged()
}
}
TdApi.UpdateChatOrder.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatOrder
TdApi.UpdateChatPosition.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatPosition
if (updateChat.position.list.constructor == TdApi.ChatListMain.CONSTRUCTOR) {
val chat = chats[updateChat.chatId]
if (chat != null) {
synchronized(chat) {
setChatOrder(chat, updateChat.order)
}
listener?.onTelegramChatsChanged()
var index = 0
for (i in chat.positions.indices) {
if (chat.positions[i].list.constructor == TdApi.ChatListMain.CONSTRUCTOR) {
index = i
break
}
}
TdApi.UpdateChatIsPinned.CONSTRUCTOR -> {
val updateChat = obj as TdApi.UpdateChatIsPinned
val chat = chats[updateChat.chatId]
if (chat != null) {
synchronized(chat) {
chat.isPinned = updateChat.isPinned
setChatOrder(chat, updateChat.order)
val length = chat.positions.size + (if (updateChat.position.order == 0L) 0 else 1) - if (index < chat.positions.size) 1 else 0
val newPositions = arrayOfNulls<TdApi.ChatPosition>(length)
var pos = 0
if (updateChat.position.order != 0L) {
newPositions[pos++] = updateChat.position
}
for (j in chat.positions.indices) {
if (j != index) {
newPositions[pos++] = chat.positions[j];
}
}
setChatPositions(chat, newPositions)
}
}
//listener?.onTelegramChatsChanged()
}

View file

@ -99,15 +99,15 @@ object OsmandLocationUtils {
fun getSenderMessageId(message: TdApi.Message): Int {
val forwardInfo = message.forwardInfo
return if (forwardInfo != null) {
val origin: TdApi.MessageForwardOrigin? = forwardInfo.origin
if (origin != null && origin is TdApi.MessageForwardOriginUser) {
origin.senderUserId
return if (forwardInfo != null && forwardInfo.origin is TdApi.MessageForwardOriginUser) {
(forwardInfo.origin as TdApi.MessageForwardOriginUser).senderUserId
} else {
message.senderUserId
val sender = message.sender
if (sender is TdApi.MessageSenderUser) {
sender.userId
} else {
0
}
} else {
message.senderUserId
}
}