From 9151cbe849e173e264e458e06bf71db3e58ea788 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 22 Jul 2020 15:43:14 -0400 Subject: [PATCH] fix: avoid moving the channel to top when switching a channel or marking it as read --- src/app/chat/event_handling.nim | 4 ++++ src/app/chat/view.nim | 7 ++++--- src/app/chat/views/channels_list.nim | 14 ++++++++------ src/status/chat.nim | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/app/chat/event_handling.nim b/src/app/chat/event_handling.nim index c2c6213a81..11162096bb 100644 --- a/src/app/chat/event_handling.nim +++ b/src/app/chat/event_handling.nim @@ -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) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index d94e00746a..8cf6601943 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -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.} = diff --git a/src/app/chat/views/channels_list.nim b/src/app/chat/views/channels_list.nim index 80a59a83b2..4773ee4d33 100644 --- a/src/app/chat/views/channels_list.nim +++ b/src/app/chat/views/channels_list.nim @@ -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]) diff --git a/src/status/chat.nim b/src/status/chat.nim index 3b88ca3902..a1c5963038 100644 --- a/src/status/chat.nim +++ b/src/status/chat.nim @@ -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) =