fix: code review

This commit is contained in:
Richard Ramos 2021-07-28 09:12:55 -04:00 committed by Iuri Matias
parent 9de0b95c3d
commit 1551c94135
5 changed files with 20 additions and 16 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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):

View File

@ -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):