Fix chats order
This commit is contained in:
parent
8f19b7cdb4
commit
e47fd457a7
2 changed files with 36 additions and 26 deletions
|
@ -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
|
||||||
|
if (updateChat.position.list.constructor == TdApi.ChatListMain.CONSTRUCTOR) {
|
||||||
val chat = chats[updateChat.chatId]
|
val chat = chats[updateChat.chatId]
|
||||||
if (chat != null) {
|
if (chat != null) {
|
||||||
synchronized(chat) {
|
synchronized(chat) {
|
||||||
setChatOrder(chat, updateChat.order)
|
var index = 0
|
||||||
}
|
for (i in chat.positions.indices) {
|
||||||
listener?.onTelegramChatsChanged()
|
if (chat.positions[i].list.constructor == TdApi.ChatListMain.CONSTRUCTOR) {
|
||||||
|
index = i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TdApi.UpdateChatIsPinned.CONSTRUCTOR -> {
|
val length = chat.positions.size + (if (updateChat.position.order == 0L) 0 else 1) - if (index < chat.positions.size) 1 else 0
|
||||||
val updateChat = obj as TdApi.UpdateChatIsPinned
|
val newPositions = arrayOfNulls<TdApi.ChatPosition>(length)
|
||||||
val chat = chats[updateChat.chatId]
|
|
||||||
if (chat != null) {
|
var pos = 0
|
||||||
synchronized(chat) {
|
if (updateChat.position.order != 0L) {
|
||||||
chat.isPinned = updateChat.isPinned
|
newPositions[pos++] = updateChat.position
|
||||||
setChatOrder(chat, updateChat.order)
|
}
|
||||||
|
for (j in chat.positions.indices) {
|
||||||
|
if (j != index) {
|
||||||
|
newPositions[pos++] = chat.positions[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setChatPositions(chat, newPositions)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//listener?.onTelegramChatsChanged()
|
//listener?.onTelegramChatsChanged()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
} else {
|
||||||
message.senderUserId
|
val sender = message.sender
|
||||||
|
if (sender is TdApi.MessageSenderUser) {
|
||||||
|
sender.userId
|
||||||
|
} else {
|
||||||
|
0
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
message.senderUserId
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue