From 518b7e455eeedcba1f4f80a9d680f89e55135038 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 24 Jan 2022 14:02:10 -0500 Subject: [PATCH] fix(userlist): member added to userlist on approve and duplicate member Fixes #4523 and #4542 --- .../chat_content/users/controller.nim | 19 +++++++++++++------ .../chat_content/users/module.nim | 2 ++ src/app_service/service/community/service.nim | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 10 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 51d2ce125d..bb86a024cc 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 @@ -42,7 +42,8 @@ proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter method delete*(self: Controller) = discard -method init*(self: Controller) = +method init*(self: Controller) = + # TODO call this function again if isUsersListAvailable changes if(self.isUsersListAvailable): self.events.on(SIGNAL_MESSAGES_LOADED) do(e:Args): let args = MessagesLoadedArgs(e) @@ -52,30 +53,36 @@ method init*(self: Controller) = self.delegate.newMessagesLoaded(args.messages) self.events.on(SIGNAL_CONTACT_NICKNAME_CHANGED) do(e: Args): - var args = ContactArgs(e) + let args = ContactArgs(e) self.delegate.contactNicknameChanged(args.contactId) self.events.on(SIGNAL_CONTACTS_STATUS_UPDATED) do(e: Args): - var args = ContactsStatusUpdatedArgs(e) + let args = ContactsStatusUpdatedArgs(e) self.delegate.contactsStatusUpdated(args.statusUpdates) self.events.on(SIGNAL_CONTACT_UPDATED) do(e: Args): - var args = ContactArgs(e) + let args = ContactArgs(e) self.delegate.contactUpdated(args.contactId) self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args): self.delegate.loggedInUserImageChanged() self.events.on(SIGNAL_CHAT_MEMBERS_ADDED) do(e: Args): - var args = ChatMembersAddedArgs(e) + let args = ChatMembersAddedArgs(e) if (args.chatId == self.chatId): self.delegate.onChatMembersAdded(args.ids) self.events.on(SIGNAL_CHAT_MEMBER_REMOVED) do(e: Args): - var args = ChatMemberRemovedArgs(e) + let args = ChatMemberRemovedArgs(e) if (args.chatId == self.chatId): self.delegate.onChatMemberRemoved(args.id) + if (self.belongsToCommunity): + self.events.on(SIGNAL_COMMUNITY_MEMBER_APPROVED) do(e: Args): + let args = CommunityMemberArgs(e) + if (args.communityId == self.sectionId): + self.delegate.onChatMembersAdded(@[args.pubKey]) + method getMembersPublicKeys*(self: Controller): seq[string] = # in case of 1:1 chat, there is no a members list if(not self.belongsToCommunity): 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 403d45da2e..9cdaca8a7b 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 @@ -52,6 +52,8 @@ method viewDidLoad*(self: Module) = # add other memebers let usersKeys = self.controller.getMembersPublicKeys() for k in usersKeys: + if (k == singletonInstance.userProfile.getPubKey()): + continue let (name, image, isIdenticon) = self.controller.getContactNameAndImage(k) let statusUpdateDto = self.controller.getStatusForContact(k) let status = statusUpdateDto.statusType.int.OnlineStatus diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 40a7939832..b40af9766c 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -46,6 +46,10 @@ type category*: Category channels*: seq[string] + CommunityMemberArgs* = ref object of Args + communityId*: string + pubKey*: string + # Signals which may be emitted by this service: const SIGNAL_COMMUNITY_JOINED* = "communityJoined" const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded" @@ -60,6 +64,7 @@ const SIGNAL_COMMUNITY_CHANNEL_DELETED* = "communityChannelDeleted" const SIGNAL_COMMUNITY_CATEGORY_CREATED* = "communityCategoryCreated" const SIGNAL_COMMUNITY_CATEGORY_EDITED* = "communityCategoryEdited" const SIGNAL_COMMUNITY_CATEGORY_DELETED* = "communityCategoryDeleted" +const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved" QtObject: type @@ -646,13 +651,14 @@ QtObject: i.inc() return -1 - proc removeMembershipRequestFromCommunity*(self: Service, communityId: string, requestId: string) = + proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string): string = let index = self.getPendingRequestIndex(communityId, requestId) if (index == -1): raise newException(RpcException, fmt"Community request not found: {requestId}") var community = self.joinedCommunities[communityId] + result = community.pendingRequestsToJoin[index].publicKey community.pendingRequestsToJoin.delete(index) self.joinedCommunities[communityId] = community @@ -661,9 +667,13 @@ QtObject: try: discard status_go.acceptRequestToJoinCommunity(requestId) - self.removeMembershipRequestFromCommunity(communityId, requestId) + let newMemberPubkey = self.removeMembershipRequestFromCommunityAndGetMemberPubkey(communityId, requestId) - self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.joinedCommunities[communityId])) + if (newMemberPubkey == ""): + error "Did not find pubkey in the pending request" + return + + self.events.emit(SIGNAL_COMMUNITY_MEMBER_APPROVED, CommunityMemberArgs(communityId: communityId, pubKey: newMemberPubkey)) except Exception as e: error "Error accepting request to join community", msg = e.msg @@ -671,7 +681,7 @@ QtObject: try: discard status_go.declineRequestToJoinCommunity(requestId) - self.removeMembershipRequestFromCommunity(communityId, requestId) + discard self.removeMembershipRequestFromCommunityAndGetMemberPubkey(communityId, requestId) self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.joinedCommunities[communityId])) except Exception as e: