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

View file

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