From 36ff742b52f2bce6c880c44c5281155237b14cd3 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Mon, 22 Aug 2022 23:01:34 +0200 Subject: [PATCH] fix(@community/members): handle members removal fixes: #6813 --- .../chat_section/chat_content/users/controller.nim | 12 ++++++------ .../chat_section/chat_content/users/io_interface.nim | 7 +++++-- .../main/chat_section/chat_content/users/module.nim | 12 +++++++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/users/controller.nim b/src/app/modules/main/chat_section/chat_content/users/controller.nim index 5837c12e9d..10f2b74492 100644 --- a/src/app/modules/main/chat_section/chat_content/users/controller.nim +++ b/src/app/modules/main/chat_section/chat_content/users/controller.nim @@ -58,7 +58,12 @@ proc handleCommunityOnlyConnections(self: Controller) = if (community.id != self.sectionId): continue let membersPubKeys = community.members.map(x => x.id) - self.delegate.onChatMembersAdded(membersPubKeys) + self.delegate.onChatMembersAddedOrRemoved(membersPubKeys) + + self.events.on(SIGNAL_COMMUNITY_MEMBER_REMOVED) do(e: Args): + let args = CommunityMemberArgs(e) + if (args.communityId == self.sectionId): + self.delegate.onChatMemberRemoved(args.pubKey) proc init*(self: Controller) = # Events that are needed for all chats because of mentions @@ -144,11 +149,6 @@ proc init*(self: Controller) = if (self.belongsToCommunity): self.handleCommunityOnlyConnections() - self.events.on(SIGNAL_COMMUNITY_MEMBER_REMOVED) do(e: Args): - let args = CommunityMemberArgs(e) - if (args.communityId == self.sectionId): - self.delegate.onChatMemberRemoved(args.pubKey) - proc getChat*(self: Controller): ChatDto = return self.chatService.getChatById(self.chatId) diff --git a/src/app/modules/main/chat_section/chat_content/users/io_interface.nim b/src/app/modules/main/chat_section/chat_content/users/io_interface.nim index 7599ef5acc..2962590935 100644 --- a/src/app/modules/main/chat_section/chat_content/users/io_interface.nim +++ b/src/app/modules/main/chat_section/chat_content/users/io_interface.nim @@ -37,13 +37,16 @@ method loggedInUserImageChanged*(self: AccessInterface) {.base.} = method addChatMember*(self: AccessInterface, member: ChatMember) {.base.} = raise newException(ValueError, "No implementation available") +method onChatMembersAddedOrRemoved*(self: AccessInterface, ids: seq[string]) {.base.} = + raise newException(ValueError, "No implementation available") + method onChatMembersAdded*(self: AccessInterface, ids: seq[string]) {.base.} = raise newException(ValueError, "No implementation available") -method onChatUpdated*(self: AccessInterface, chat: ChatDto) {.base.} = +method onChatMemberRemoved*(self: AccessInterface, ids: string) {.base.} = raise newException(ValueError, "No implementation available") -method onChatMemberRemoved*(self: AccessInterface, ids: string) {.base.} = +method onChatUpdated*(self: AccessInterface, chat: ChatDto) {.base.} = raise newException(ValueError, "No implementation available") method onChatMemberUpdated*(self: AccessInterface, id: string, admin: bool, joined: bool) {.base.} = diff --git a/src/app/modules/main/chat_section/chat_content/users/module.nim b/src/app/modules/main/chat_section/chat_content/users/module.nim index 035ad74799..eadb680c12 100644 --- a/src/app/modules/main/chat_section/chat_content/users/module.nim +++ b/src/app/modules/main/chat_section/chat_content/users/module.nim @@ -1,4 +1,4 @@ -import NimQml, strutils +import NimQml, strutils, sequtils, sugar import io_interface import ../io_interface as delegate_interface import view, controller @@ -176,6 +176,16 @@ method onChatUpdated*(self: Module, chat: ChatDto) = method onChatMemberRemoved*(self: Module, id: string) = self.view.model().removeItemById(id) +method onChatMembersAddedOrRemoved*(self: Module, ids: seq[string]) = + let modelIDs = self.view.model().getItemIds() + let membersAdded = filter(ids, id => not modelIDs.contains(id)) + let membersRemoved = filter(modelIDs, id => not ids.contains(id)) + + self.onChatMembersAdded(membersAdded) + for id in membersRemoved: + self.onChatMemberRemoved(id) + + method onChatMemberUpdated*(self: Module, publicKey: string, admin: bool, joined: bool) = let contactDetails = self.controller.getContactDetails(publicKey) self.view.model().updateItem(