From 3793405843779f779ded2b3c57fd12b4bf3ce862 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 25 Oct 2024 10:36:42 -0400 Subject: [PATCH] fix(requests): fix member requests not showing in list (#16604) Fixes #16600 There was no update to the model when we get a signal that a membership request is received. We also didn't send an event when one is canceled. --- .../modules/main/chat_section/controller.nim | 2 +- src/app/modules/main/controller.nim | 4 ++++ src/app/modules/main/io_interface.nim | 3 +++ src/app/modules/main/module.nim | 12 ++++++++++- .../modules/shared_models/section_model.nim | 16 ++++++++++++-- src/app_service/service/community/service.nim | 21 ++++++++++++++++++- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index d264d56f8c..b099adfa3b 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -410,7 +410,7 @@ proc init*(self: Controller) = self.delegate.updateRequestToJoinState(RequestToJoinState.Requested) self.events.on(SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED) do(e:Args): - let args = community_service.CommunityIdArgs(e) + let args = community_service.CanceledCommunityRequestArgs(e) if args.communityId == self.sectionId: self.delegate.updateRequestToJoinState(RequestToJoinState.None) diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index 3cf34e2e5a..ce0bc6efbb 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -309,6 +309,10 @@ proc init*(self: Controller) = var args = CommunityRequestArgs(e) self.delegate.newCommunityMembershipRequestReceived(args.communityRequest) + self.events.on(SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED) do(e:Args): + let args = community_service.CanceledCommunityRequestArgs(e) + self.delegate.communityMembershipRequestCanceled(args.communityId, args.requestId, args.pubKey) + self.events.on(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY_ACCEPTED) do(e: Args): var args = CommunityRequestArgs(e) self.delegate.communityMemberRevealedAccountsAdded(args.communityRequest) diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index 70b3d3684b..3a0f011dff 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -219,6 +219,9 @@ method newCommunityMembershipRequestReceived*(self: AccessInterface, membershipR {.base.} = raise newException(ValueError, "No implementation available") +method communityMembershipRequestCanceled*(self: AccessInterface, communityId: string, requestId: string, pubKey: string) {.base.} = + raise newException(ValueError, "No implementation available") + method meMentionedCountChanged*(self: AccessInterface, allMentions: int) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 7f681c93c1..57aa559eb2 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -1367,7 +1367,17 @@ method newCommunityMembershipRequestReceived*[T](self: Module[T], membershipRequ let (contactName, _, _) = self.controller.getContactNameAndImage(membershipRequest.publicKey) let community = self.controller.getCommunityById(membershipRequest.communityId) singletonInstance.globalEvents.newCommunityMembershipRequestNotification("New membership request", - fmt "{contactName} asks to join {community.name}", community.id) + fmt "{contactName} asks to join {community.name}", community.id) + + self.view.model().addPendingMember(membershipRequest.communityId, self.createMemberItem( + membershipRequest.publicKey, + membershipRequest.id, + MembershipRequestState(membershipRequest.state), + MemberRole.None, + )) + +method communityMembershipRequestCanceled*[T](self: Module[T], communityId: string, requestId: string, pubKey: string) = + self.view.model().removePendingMember(communityId, pubKey) method meMentionedCountChanged*[T](self: Module[T], allMentions: int) = singletonInstance.globalEvents.meMentionedIconBadgeNotification(allMentions) diff --git a/src/app/modules/shared_models/section_model.nim b/src/app/modules/shared_models/section_model.nim index 2d85c82f46..ee59fb2e37 100644 --- a/src/app/modules/shared_models/section_model.nim +++ b/src/app/modules/shared_models/section_model.nim @@ -2,7 +2,7 @@ import NimQml, Tables, strutils, stew/shims/strformat import json -import section_item, member_model +import section_item, member_model, member_item import ../main/communities/tokens/models/[token_item, token_model] type @@ -468,7 +468,7 @@ QtObject: } return $jsonObj - proc setMembersAirdropAddress*(self: SectionModel, id: string, communityMembersAirdropAddress: Table[string, string]) = + proc setMembersAirdropAddress*(self: SectionModel, id: string, communityMembersAirdropAddress: Table[string, string]) = let index = self.getItemIndex(id) if (index == -1): return @@ -482,3 +482,15 @@ QtObject: return self.items[index].communityTokens.setItems(communityTokensItems) + + proc addPendingMember*(self: SectionModel, communityId: string, memberItem: MemberItem) = + let i = self.getItemIndex(communityId) + if i == -1: + return + self.items[i].pendingMemberRequests.addItem(memberItem) + + proc removePendingMember*(self: SectionModel, communityId: string, memberId: string) = + let i = self.getItemIndex(communityId) + if i == -1: + return + self.items[i].pendingMemberRequests.removeItemById(memberId) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index dd2936a3de..86df15a974 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -55,6 +55,11 @@ type CommunityRequestArgs* = ref object of Args communityRequest*: CommunityMembershipRequestDto + CanceledCommunityRequestArgs* = ref object of Args + communityId*: string + requestId*: string + pubKey*: string + CommunityRequestFailedArgs* = ref object of Args communityId*: string error*: string @@ -1976,6 +1981,14 @@ QtObject: # If the state is now declined, add to the declined requests if newState == RequestToJoinType.Declined: community.declinedRequestsToJoin.add(community.pendingRequestsToJoin[indexPending]) + elif newState == RequestToJoinType.Canceled: + self.events.emit(SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED, + CanceledCommunityRequestArgs( + communityId: communityId, + requestId: requestId, + pubKey: community.pendingRequestsToJoin[indexPending].publicKey, + ) + ) # If the state is no longer pending, delete the request community.pendingRequestsToJoin.delete(indexPending) @@ -2013,9 +2026,15 @@ QtObject: error "error while cancel membership request ", msg return + self.events.emit(SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED, + CanceledCommunityRequestArgs( + communityId: communityId, + requestId: myPendingRequest.id, + pubKey: community.pendingRequestsToJoin[i].publicKey, + ) + ) community.pendingRequestsToJoin.delete(i) self.communities[communityId] = community - self.events.emit(SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED, CommunityIdArgs(communityId: communityId)) checkAndEmitACNotificationsFromResponse(self.events, response.result{"activityCenterNotifications"}) return