From 9de0b95c3d531c8bed25a24123d56bc7217bbb57 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 26 Jul 2021 18:00:09 -0400 Subject: [PATCH] fix: group member list --- src/app/chat/event_handling.nim | 7 ++- src/app/chat/view.nim | 4 +- src/app/chat/views/chat_members.nim | 2 +- src/app/chat/views/message_list.nim | 9 ++- src/app/chat/views/messages.nim | 6 +- src/app/chat/views/user_list.nim | 58 ++++++++++++++++++- .../Chat/components/GroupInfoPopup.qml | 16 ++--- 7 files changed, 84 insertions(+), 18 deletions(-) diff --git a/src/app/chat/event_handling.nim b/src/app/chat/event_handling.nim index 25b36c1398..45fa0508bd 100644 --- a/src/app/chat/event_handling.nim +++ b/src/app/chat/event_handling.nim @@ -4,7 +4,8 @@ import # std libs import # status-desktop libs ../../status/chat/chat as status_chat, ./views/communities, ../../status/tasks/marathon, - ../../status/tasks/marathon/mailserver/worker + ../../status/tasks/marathon/mailserver/worker, + ./views/messages proc handleChatEvents(self: ChatController) = # Display already saved messages @@ -36,7 +37,7 @@ proc handleChatEvents(self: ChatController) = self.view.hideLoadingIndicator() self.view.updateUsernames(evArgs.contacts) self.view.updateChats(evArgs.chats) - self.view.pushMessages(evArgs.messages) + self.view.pushMessages(evArgs.messages, evArgs.chats) # TODO: update current user status (once it's possible to switch between ONLINE and DO_NOT_DISTURB) @@ -102,6 +103,8 @@ proc handleChatEvents(self: ChatController) = # Do not add community chats to the normal chat list 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) 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 1abded1c4c..f86c71c295 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -438,8 +438,8 @@ QtObject: let task = RequestMessagesTaskArg( `method`: "requestMoreMessages", chatId: self.channelView.activeChannel.id) mailserverWorker.start(task) - proc pushMessages*(self: ChatsView, messages: var seq[Message]) = - self.messageView.pushMessages(messages) + proc pushMessages*(self: ChatsView, messages: var seq[Message], chats: seq[Chat] = @[]) = + self.messageView.pushMessages(messages, chats) proc pushPinnedMessages*(self: ChatsView, pinnedMessages: var seq[Message]) = self.messageView.pushPinnedMessages(pinnedMessages) diff --git a/src/app/chat/views/chat_members.nim b/src/app/chat/views/chat_members.nim index e7d52d2758..696dc8326d 100644 --- a/src/app/chat/views/chat_members.nim +++ b/src/app/chat/views/chat_members.nim @@ -58,7 +58,7 @@ QtObject: method roleNames(self: ChatMembersView): Table[int, string] = { ChatMemberRoles.UserName.int:"userName", - ChatMemberRoles.PubKey.int:"pubKey", + ChatMemberRoles.PubKey.int:"publicKey", ChatMemberRoles.IsAdmin.int: "isAdmin", ChatMemberRoles.Joined.int: "joined", ChatMemberRoles.Identicon.int: "identicon", diff --git a/src/app/chat/views/message_list.nim b/src/app/chat/views/message_list.nim index d66e504a5b..e1eef72245 100644 --- a/src/app/chat/views/message_list.nim +++ b/src/app/chat/views/message_list.nim @@ -1,8 +1,8 @@ import NimQml, Tables, sets, json, sugar, chronicles, sequtils import ../../../status/status import ../../../status/accounts -import ../../../status/chat -import ../../../status/chat/[message,stickers] +import ../../../status/chat as status_chat +import ../../../status/chat/[message,stickers,chat] import ../../../status/profile/profile import ../../../status/ens import strutils @@ -287,6 +287,11 @@ 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 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 9a86d8ad02..feadd518c1 100644 --- a/src/app/chat/views/messages.nim +++ b/src/app/chat/views/messages.nim @@ -229,7 +229,7 @@ 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]) = + proc pushMessages*(self:MessageView, messages: var seq[Message], chats: seq[Chat] = @[]) = for msg in messages.mitems: self.upsertChannel(msg.chatId) msg.userName = self.status.chat.getUserName(msg.fromAuthor, msg.alias) @@ -263,6 +263,10 @@ 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 501db110af..81f268db47 100644 --- a/src/app/chat/views/user_list.nim +++ b/src/app/chat/views/user_list.nim @@ -1,8 +1,10 @@ import NimQml, Tables, json, chronicles, sequtils import ../../../status/status import ../../../status/accounts -import ../../../status/chat -import ../../../status/chat/[message] +import ../../../status/chat as status_chat +import ../../../status/chat/[message, chat] +import ../../../status/ens + import strutils type @@ -70,6 +72,58 @@ QtObject: UserListRoles.Identicon.int:"identicon" }.toTable + proc add*(self: UserListView, members: seq[ChatMember]) = + # Adding chat members + for m in members: + let pk = m.id + if self.userDetails.hasKey(pk): continue + + var userName: string + var alias: string + var identicon: string + var localName: string + + if self.status.chat.contacts.hasKey(pk): + userName = ens.userNameOrAlias(self.status.chat.contacts[pk]) + alias = self.status.chat.contacts[pk].alias + identicon = self.status.chat.contacts[pk].identicon + localName = self.status.chat.contacts[pk].localNickname + else: + userName = m.username + alias = m.username + identicon = m.identicon + localName = "" + + self.beginInsertRows(newQModelIndex(), self.users.len, self.users.len) + self.userDetails[pk] = User( + userName: userName, + alias: alias, + localName: localName, + lastSeen: "0", + identicon: identicon + ) + self.users.add(pk) + self.endInsertRows() + + # Checking for removed members + var toDelete: seq[string] + for userPublicKey in self.users: + var found = false + for m in members: + if m.id == userPublicKey: + found = true + break + if not found: + toDelete.add(userPublicKey) + + # Removing deleted members + if toDelete.len > 0: + self.beginResetModel() + for pkToDelete in toDelete: + self.users.del(self.users.find(pkToDelete)) + self.userDetails.del(pkToDelete) + self.endResetModel() + proc add*(self: UserListView, message: Message) = if self.userDetails.hasKey(message.fromAuthor): self.beginResetModel() diff --git a/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml b/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml index 419d040fd5..ae6e31f0d0 100644 --- a/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml +++ b/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml @@ -31,7 +31,7 @@ ModalPopup { const contacts = getContactListObject() contacts.forEach(function (contact) { - if(popup.channel.contains(contact.pubKey) || + if(popup.channel.contains(contact.publicKey) || !contact.isContact) { return; } @@ -278,12 +278,12 @@ ModalPopup { width: parent.width height: identicon.height - property string nickname: appMain.getUserNickname(model.pubKey) + property string nickname: appMain.getUserNickname(model.publicKey) StatusImageIdenticon { id: identicon anchors.left: parent.left - source: appMain.getProfileImage(model.pubKey)|| model.identicon + source: appMain.getProfileImage(model.publicKey)|| model.identicon } StyledText { @@ -295,7 +295,7 @@ ModalPopup { font.pixelSize: 17 StyledText { - visible: model.pubKey === profileModel.profile.pubKey + visible: model.publicKey === profileModel.profile.pubKey anchors.left: parent.right anchors.leftMargin: 5 //% "(You)" @@ -307,8 +307,8 @@ ModalPopup { anchors.fill: parent cursorShape: Qt.PointingHandCursor onClicked: { - const userProfileImage = appMain.getProfileImage(model.pubKey) - openProfilePopup(model.userName, model.pubKey, userProfileImage || model.identicon, '', contactRow.nickname, popup) + const userProfileImage = appMain.getProfileImage(model.publicKey) + openProfilePopup(model.userName, model.publicKey, userProfileImage || model.identicon, '', contactRow.nickname, popup) } } } @@ -348,7 +348,7 @@ ModalPopup { icon.height: 16 //% "Make Admin" text: qsTrId("make-admin") - onTriggered: chatsModel.groups.makeAdmin(popup.channel.id, model.pubKey) + onTriggered: chatsModel.groups.makeAdmin(popup.channel.id, model.publicKey) } Action { icon.source: "../../../img/remove-from-group.svg" @@ -357,7 +357,7 @@ ModalPopup { icon.color: Style.current.red //% "Remove From Group" text: qsTrId("remove-from-group") - onTriggered: chatsModel.groups.kickMember(popup.channel.id, model.pubKey) + onTriggered: chatsModel.groups.kickMember(popup.channel.id, model.publicKey) } } }