fix: avoid moving the channel to top when switching a channel or marking it as read

This commit is contained in:
Richard Ramos 2020-07-22 15:43:14 -04:00 committed by Iuri Matias
parent c4eb92b5e8
commit 9151cbe849
4 changed files with 17 additions and 10 deletions

View File

@ -14,6 +14,10 @@ proc handleChatEvents(self: ChatController) =
self.view.updateChats(evArgs.chats)
self.view.pushMessages(evArgs.messages)
self.status.events.on("channelUpdate") do(e: Args):
var evArgs = ChatUpdateArgs(e)
self.view.updateChats(evArgs.chats, false)
self.status.events.on("chatHistoryCleared") do(e: Args):
var args = ChannelArgs(e)
self.view.clearMessages(args.chat.id)

View File

@ -287,14 +287,15 @@ QtObject:
self.unreadMessageCnt = unreadTotal
self.unreadMessagesCntChanged()
proc updateChats*(self: ChatsView, chats: seq[Chat]) =
proc updateChats*(self: ChatsView, chats: seq[Chat], triggerChange:bool = true) =
for chat in chats:
self.upsertChannel(chat.id)
self.chats.updateChat(chat)
self.chats.updateChat(chat, triggerChange)
if(self.activeChannel.id == chat.id):
self.activeChannel.setChatItem(chat)
self.currentSuggestions.setNewData(self.status.contacts.getContacts())
self.activeChannelChanged()
if triggerChange:
self.activeChannelChanged()
self.calculateUnreadMessages()
proc renameGroup*(self: ChatsView, newName: string) {.slot.} =

View File

@ -113,17 +113,19 @@ QtObject:
if chat.name == name:
return chat.color
proc updateChat*(self: ChannelsList, channel: Chat) =
proc updateChat*(self: ChannelsList, channel: Chat, moveToTop: bool = true) =
let idx = self.upsertChannel(channel)
if idx == -1: return
let topLeft = self.createIndex(0, 0, nil)
let bottomRight = self.createIndex(self.chats.len, 0, nil)
if idx != 0: # Move last updated chat to the top of the list
self.chats.delete(idx)
self.chats.insert(channel, 0)
else:
self.chats[0] = channel
if moveToTop:
if idx != 0: # Move last updated chat to the top of the list
self.chats.delete(idx)
self.chats.insert(channel, 0)
else:
self.chats[0] = channel
self.dataChanged(topLeft, bottomRight, @[ChannelsRoles.Name.int, ChannelsRoles.ContentType.int, ChannelsRoles.LastMessage.int, ChannelsRoles.Timestamp.int, ChannelsRoles.UnreadMessages.int, ChannelsRoles.Identicon.int, ChannelsRoles.ChatType.int, ChannelsRoles.Color.int, ChannelsRoles.HasMentions.int])

View File

@ -257,7 +257,7 @@ proc markAllChannelMessagesRead*(self: ChatModel, chatId: string): JsonNode =
result = parseJson(response)
if self.channels.hasKey(chatId):
self.channels[chatId].unviewedMessagesCount = 0
self.events.emit("chatUpdate", ChatUpdateArgs(messages: @[], chats: @[self.channels[chatId]], contacts: @[]))
self.events.emit("channelUpdate", ChatUpdateArgs(messages: @[], chats: @[self.channels[chatId]], contacts: @[]))
proc confirmJoiningGroup*(self: ChatModel, chatId: string) =