fix(@community/members): handle members removal

fixes: #6813
This commit is contained in:
Patryk Osmaczko 2022-08-22 23:01:34 +02:00 committed by osmaczko
parent 2ef6e04b0a
commit 36ff742b52
3 changed files with 22 additions and 9 deletions

View File

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

View File

@ -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.} =

View File

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