From 1551c941353030fe1d83898be1457585dff6385c Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 28 Jul 2021 09:12:55 -0400 Subject: [PATCH] fix: code review --- src/app/chat/event_handling.nim | 5 +++-- src/app/chat/view.nim | 7 +++++-- src/app/chat/views/message_list.nim | 6 ++---- src/app/chat/views/messages.nim | 11 ++++++----- src/app/chat/views/user_list.nim | 7 ++++--- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/app/chat/event_handling.nim b/src/app/chat/event_handling.nim index 45fa0508bd..e64a04344e 100644 --- a/src/app/chat/event_handling.nim +++ b/src/app/chat/event_handling.nim @@ -37,7 +37,8 @@ proc handleChatEvents(self: ChatController) = self.view.hideLoadingIndicator() self.view.updateUsernames(evArgs.contacts) self.view.updateChats(evArgs.chats) - self.view.pushMessages(evArgs.messages, evArgs.chats) + self.view.pushMessages(evArgs.messages) + self.view.pushMembers(evArgs.chats) # TODO: update current user status (once it's possible to switch between ONLINE and DO_NOT_DISTURB) @@ -104,7 +105,7 @@ proc handleChatEvents(self: ChatController) = elif channel.chat.chatType != ChatType.Profile and channel.chat.chatType != status_chat.ChatType.CommunityChat: discard self.view.channelView.chats.addChatItemToList(channel.chat) self.view.messageView.upsertChannel(channel.chat.id) - self.view.messageView.messageList[channel.chat.id].addChatUpdate(channel.chat) + self.view.messageView.messageList[channel.chat.id].addChatMembers(channel.chat.members) if channel.chat.chatType == status_chat.ChatType.CommunityChat: self.view.communities.updateCommunityChat(channel.chat) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index f86c71c295..a2cc45b5a1 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -438,8 +438,11 @@ QtObject: let task = RequestMessagesTaskArg( `method`: "requestMoreMessages", chatId: self.channelView.activeChannel.id) mailserverWorker.start(task) - proc pushMessages*(self: ChatsView, messages: var seq[Message], chats: seq[Chat] = @[]) = - self.messageView.pushMessages(messages, chats) + proc pushMessages*(self: ChatsView, messages: var seq[Message]) = + self.messageView.pushMessages(messages) + + proc pushMembers*(self: ChatsView, chats: seq[Chat]) = + self.messageView.pushMembers(chats) proc pushPinnedMessages*(self: ChatsView, pinnedMessages: var seq[Message]) = self.messageView.pushPinnedMessages(pinnedMessages) diff --git a/src/app/chat/views/message_list.nim b/src/app/chat/views/message_list.nim index e1eef72245..b1caa30400 100644 --- a/src/app/chat/views/message_list.nim +++ b/src/app/chat/views/message_list.nim @@ -287,10 +287,8 @@ QtObject: proc contains*(self: ChatMessageList, message: Message):bool = return self.messageIndex.hasKey(message.id) - proc addChatUpdate*(self: ChatMessageList, chat: Chat) = - # Using chat update to add/remove members to a group chat - if chat.chatType == ChatType.PrivateGroupChat: - self.userList.add(chat.members) + proc addChatMembers*(self: ChatMessageList, members: seq[ChatMember]) = + self.userList.add(members) proc add*(self: ChatMessageList, message: Message) = if self.messageIndex.hasKey(message.id) and message.editedAt == "0": return # duplicated msg diff --git a/src/app/chat/views/messages.nim b/src/app/chat/views/messages.nim index feadd518c1..5673312880 100644 --- a/src/app/chat/views/messages.nim +++ b/src/app/chat/views/messages.nim @@ -229,7 +229,12 @@ QtObject: proc messageNotificationPushed*(self: MessageView, chatId: string, text: string, contentType: int, chatType: int, timestamp: string, identicon: string, username: string, hasMention: bool, isAddedContact: bool, channelName: string) {.signal.} - proc pushMessages*(self:MessageView, messages: var seq[Message], chats: seq[Chat] = @[]) = + proc pushMembers*(self:MessageView, chats: seq[Chat]) = + for chat in chats: + if chat.chatType == ChatType.PrivateGroupChat and self.messageList.hasKey(chat.id): + self.messageList[chat.id].addChatMembers(chat.members) + + proc pushMessages*(self:MessageView, messages: var seq[Message]) = for msg in messages.mitems: self.upsertChannel(msg.chatId) msg.userName = self.status.chat.getUserName(msg.fromAuthor, msg.alias) @@ -263,10 +268,6 @@ QtObject: if not channel.muted and not isEdit and not isGroupSelf: let isAddedContact = channel.chatType.isOneToOne and self.isAddedContact(channel.id) self.messageNotificationPushed(msg.chatId, escape_html(msg.text), msg.contentType.int, channel.chatType.int, msg.timestamp, msg.identicon, msg.userName, msg.hasMention, isAddedContact, channel.name) - - for chat in chats: - if chat.chatType == ChatType.PrivateGroupChat and self.messageList.hasKey(chat.id): - self.messageList[chat.id].addChatUpdate(chat) proc markMessageAsSent*(self:MessageView, chat: string, messageId: string) = if self.messageList.contains(chat): diff --git a/src/app/chat/views/user_list.nim b/src/app/chat/views/user_list.nim index 81f268db47..dc24b3999d 100644 --- a/src/app/chat/views/user_list.nim +++ b/src/app/chat/views/user_list.nim @@ -118,11 +118,12 @@ QtObject: # Removing deleted members if toDelete.len > 0: - self.beginResetModel() for pkToDelete in toDelete: - self.users.del(self.users.find(pkToDelete)) + let idx = self.users.find(pkToDelete) + self.beginRemoveRows(newQModelIndex(), idx, idx) + self.users.del(idx) self.userDetails.del(pkToDelete) - self.endResetModel() + self.endRemoveRows() proc add*(self: UserListView, message: Message) = if self.userDetails.hasKey(message.fromAuthor):