fix(community-members): fix pending request buttons + updates

Fixes #9973

The buttons didn't work because we weren't using the right model + the section model didn't expose the PendingMemberRequestsModel.
I also fixed the service to update the community correctly and send the event. It should feel snappy-er to approve someone now.
This commit is contained in:
Jonathan Rainville 2023-03-22 09:52:25 -04:00
parent d759bda81d
commit caebc9b93f
6 changed files with 30 additions and 10 deletions

View File

@ -298,7 +298,6 @@ proc init*(self: Controller) =
if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenMetadataAdded(args.communityId, args.tokenMetadata)
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args):
self.delegate.onWalletAccountTokensRebuilt()

View File

@ -1,3 +1,5 @@
import strformat
type
PendingRequestItem* = ref object
id: string
@ -40,3 +42,13 @@ proc state*(self: PendingRequestItem): int =
proc our*(self: PendingRequestItem): string =
self.our
proc `$`*(self: PendingRequestItem): string =
result = fmt"""PendingRequestItem(
id: {self.id},
publicKey: {$self.publicKey},
chatId: {$self.chatId},
communityId: {$self.communityId},
state: {$self.state},
our: {$self.our},
]"""

View File

@ -287,6 +287,7 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
channelGroup.permissions.access,
channelGroup.permissions.ensOnly,
channelGroup.muted,
# members
channelGroup.members.map(proc(member: ChatMember): MemberItem =
let contactDetails = self.controller.getContactDetails(member.id)
result = initMemberItem(
@ -303,6 +304,7 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
isVerified = contactDetails.details.isContactVerified(),
isAdmin = member.admin
)),
# pendingRequestsToJoin
if (isCommunity): communityDetails.pendingRequestsToJoin.map(x => pending_request_item.initItem(
x.id,
x.publicKey,
@ -313,6 +315,7 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
)) else: @[],
communityDetails.settings.historyArchiveSupportEnabled,
communityDetails.adminSettings.pinMessageAllMembersEnabled,
# bannedMembers
channelGroup.bannedMembersIds.map(proc(bannedMemberId: string): MemberItem=
let contactDetails = self.controller.getContactDetails(bannedMemberId)
result = initMemberItem(
@ -329,6 +332,7 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
isVerified = contactDetails.details.isContactVerified()
)
),
# pendingMemberRequests
if (isCommunity): communityDetails.pendingRequestsToJoin.map(proc(requestDto: CommunityMembershipRequestDto): MemberItem =
let contactDetails = self.controller.getContactDetails(requestDto.publicKey)
result = initMemberItem(
@ -346,6 +350,7 @@ proc createChannelGroupItem[T](self: Module[T], channelGroup: ChannelGroupDto):
requestToJoinId = requestDto.id
)
) else: @[],
# declinedMemberRequests
if (isCommunity): communityDetails.declinedRequestsToJoin.map(proc(requestDto: CommunityMembershipRequestDto): MemberItem =
let contactDetails = self.controller.getContactDetails(requestDto.publicKey)
result = initMemberItem(

View File

@ -191,7 +191,7 @@ QtObject:
proc declinedRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
proc canceledRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
proc getPendingRequestIndex(self: Service, communityId: string, requestId: string): int
proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string): string
proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string, updatedCommunity: CommunityDto): string
proc getUserPubKeyFromPendingRequest*(self: Service, communityId: string, requestId: string): string
proc delete*(self: Service) =
@ -1356,12 +1356,14 @@ QtObject:
self.events.emit(SIGNAL_ACCEPT_REQUEST_TO_JOIN_FAILED, CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
return
discard self.removeMembershipRequestFromCommunityAndGetMemberPubkey(communityId, requestId)
discard self.removeMembershipRequestFromCommunityAndGetMemberPubkey(communityId, requestId,
rpcResponseObj["response"]["result"]["communities"][0].toCommunityDto)
if (userKey == ""):
error "Did not find pubkey in the pending request"
return
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: self.communities[communityId]))
self.events.emit(SIGNAL_COMMUNITY_MEMBER_APPROVED, CommunityMemberArgs(communityId: communityId, pubKey: userKey, requestId: requestId))
except Exception as e:
@ -1491,7 +1493,8 @@ QtObject:
i.inc()
return -1
proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string): string =
proc removeMembershipRequestFromCommunityAndGetMemberPubkey*(self: Service, communityId: string, requestId: string,
updatedCommunity: CommunityDto): string =
let indexPending = self.getPendingRequestIndex(communityId, requestId)
let indexDeclined = self.getDeclinedRequestIndex(communityId, requestId)
@ -1507,6 +1510,7 @@ QtObject:
result = community.declinedRequestsToJoin[indexDeclined].publicKey
community.declinedRequestsToJoin.delete(indexDeclined)
community.members = updatedCommunity.members
self.communities[communityId] = community
proc moveRequestToDeclined*(self: Service, communityId: string, requestId: string) =
@ -1515,10 +1519,10 @@ QtObject:
raise newException(RpcException, fmt"Community request not found: {requestId}")
var community = self.communities[communityId]
if (indexPending != -1):
let itemToMove = community.pendingRequestsToJoin[indexPending]
community.declinedRequestsToJoin.add(itemToMove)
community.pendingRequestsToJoin.delete(indexPending)
let itemToMove = community.pendingRequestsToJoin[indexPending]
community.declinedRequestsToJoin.add(itemToMove)
community.pendingRequestsToJoin.delete(indexPending)
self.communities[communityId] = community

View File

@ -222,7 +222,7 @@ StatusSectionLayout {
onAirdropTokensClicked: { /* TODO in future */ }
onBackUpClicked: {
Global.openPopup(transferOwnershipPopup, {
privateKey: root.chatCommunitySectionModule.exportCommunity(root.communityId),
privateKey: root.chatCommunitySectionModule.exportCommunity(root.community.id),
})
}
onPreviousPageNameChanged: root.backButtonName = previousPageName

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit becc49ac24383bc1096ad77a24093fdfc43f60ba
Subproject commit 329f5c831682f73b8182db955716ed3e713670fa