feat(communities): User is able to cancel membership request

Part of: #7072
This commit is contained in:
Boris Melnik 2022-10-21 13:09:17 +03:00
parent 76968df721
commit 42234c7d49
10 changed files with 124 additions and 15 deletions

View File

@ -86,6 +86,9 @@ proc getCuratedCommunities*(self: Controller): seq[CuratedCommunity] =
proc spectateCommunity*(self: Controller, communityId: string): string = proc spectateCommunity*(self: Controller, communityId: string): string =
self.communityService.spectateCommunity(communityId) self.communityService.spectateCommunity(communityId)
proc cancelRequestToJoinCommunity*(self: Controller, communityId: string) =
self.communityService.cancelRequestToJoinCommunity(communityId)
proc requestToJoinCommunity*(self: Controller, communityId: string, ensName: string) = proc requestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
self.communityService.requestToJoinCommunity(communityId, ensName) self.communityService.requestToJoinCommunity(communityId, ensName)

View File

@ -62,6 +62,9 @@ method userCanJoin*(self: AccessInterface, communityId: string): bool {.base.} =
method isCommunityRequestPending*(self: AccessInterface, communityId: string): bool {.base.} = method isCommunityRequestPending*(self: AccessInterface, communityId: string): bool {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method cancelRequestToJoinCommunity*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} = method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -272,6 +272,9 @@ method discordCategoriesAndChannelsExtracted*(self: Module, categories: seq[Disc
self.view.setDiscordImportErrorsCount(errorsCount) self.view.setDiscordImportErrorsCount(errorsCount)
self.view.discordChannelsModel().hasSelectedItemsChanged() self.view.discordChannelsModel().hasSelectedItemsChanged()
method cancelRequestToJoinCommunity*(self: Module, communityId: string) =
self.controller.cancelRequestToJoinCommunity(communityId)
method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) = method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) =
self.controller.requestToJoinCommunity(communityId, ensName) self.controller.requestToJoinCommunity(communityId, ensName)

View File

@ -418,6 +418,9 @@ QtObject:
proc reorderCommunityChannel*(self: View, communityId: string, categoryId: string, chatId: string, position: int): string {.slot} = proc reorderCommunityChannel*(self: View, communityId: string, categoryId: string, chatId: string, position: int): string {.slot} =
self.delegate.reorderCommunityChannel(communityId, categoryId, chatId, position) self.delegate.reorderCommunityChannel(communityId, categoryId, chatId, position)
proc cancelRequestToJoinCommunity*(self: View, communityId: string) {.slot.} =
self.delegate.cancelRequestToJoinCommunity(communityId)
proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} = proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunity(communityId, ensName) self.delegate.requestToJoinCommunity(communityId, ensName)

View File

@ -8,9 +8,10 @@ include ../../../common/json_utils
import ../../chat/dto/chat import ../../chat/dto/chat
type RequestToJoinType* {.pure.}= enum type RequestToJoinType* {.pure.}= enum
Pending = 0, Pending = 1,
Declined = 1, Declined = 2,
Accepted = 2 Accepted = 3,
Canceled = 4
type Member* = object type Member* = object
id*: string id*: string
@ -72,6 +73,7 @@ type CommunityDto* = object
bannedMembersIds*: seq[string] bannedMembersIds*: seq[string]
declinedRequestsToJoin*: seq[CommunityMembershipRequestDto] declinedRequestsToJoin*: seq[CommunityMembershipRequestDto]
encrypted*: bool encrypted*: bool
canceledRequestsToJoin*: seq[CommunityMembershipRequestDto]
type CuratedCommunity* = object type CuratedCommunity* = object
available*: bool available*: bool

View File

@ -114,6 +114,7 @@ const SIGNAL_COMMUNITY_CATEGORY_REORDERED* = "communityCategoryReordered"
const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved" const SIGNAL_COMMUNITY_MEMBER_APPROVED* = "communityMemberApproved"
const SIGNAL_COMMUNITY_MEMBER_REMOVED* = "communityMemberRemoved" const SIGNAL_COMMUNITY_MEMBER_REMOVED* = "communityMemberRemoved"
const SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY* = "newRequestToJoinCommunity" const SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY* = "newRequestToJoinCommunity"
const SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED* = "requestToJoinCommunityCanceled"
const SIGNAL_CURATED_COMMUNITY_FOUND* = "curatedCommunityFound" const SIGNAL_CURATED_COMMUNITY_FOUND* = "curatedCommunityFound"
const SIGNAL_COMMUNITY_MUTED* = "communityMuted" const SIGNAL_COMMUNITY_MUTED* = "communityMuted"
const SIGNAL_CATEGORY_MUTED* = "categoryMuted" const SIGNAL_CATEGORY_MUTED* = "categoryMuted"
@ -142,10 +143,13 @@ QtObject:
proc loadCuratedCommunities(self: Service): seq[CuratedCommunity] proc loadCuratedCommunities(self: Service): seq[CuratedCommunity]
proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto] proc loadCommunitiesSettings(self: Service): seq[CommunitySettingsDto]
proc loadMyPendingRequestsToJoin*(self: Service) proc loadMyPendingRequestsToJoin*(self: Service)
proc loadMyCanceledRequestsToJoin*(self: Service)
proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto]) proc handleCommunityUpdates(self: Service, communities: seq[CommunityDto], updatedChats: seq[ChatDto])
proc handleCommunitiesSettingsUpdates(self: Service, communitiesSettings: seq[CommunitySettingsDto]) proc handleCommunitiesSettingsUpdates(self: Service, communitiesSettings: seq[CommunitySettingsDto])
proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto]
proc declinedRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] 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 delete*(self: Service) = proc delete*(self: Service) =
discard discard
@ -199,11 +203,25 @@ QtObject:
error "Received a membership request for an unknown community", communityId=membershipRequest.communityId error "Received a membership request for an unknown community", communityId=membershipRequest.communityId
continue continue
var community = self.joinedCommunities[membershipRequest.communityId] var community = self.joinedCommunities[membershipRequest.communityId]
community.pendingRequestsToJoin.add(membershipRequest)
self.joinedCommunities[membershipRequest.communityId] = community
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
self.events.emit(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY, CommunityRequestArgs(communityRequest: membershipRequest)) case RequestToJoinType(membershipRequest.state):
of RequestToJoinType.Pending:
community.pendingRequestsToJoin.add(membershipRequest)
self.joinedCommunities[membershipRequest.communityId] = community
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
self.events.emit(SIGNAL_NEW_REQUEST_TO_JOIN_COMMUNITY, CommunityRequestArgs(communityRequest: membershipRequest))
of RequestToJoinType.Canceled:
let indexPending = self.getPendingRequestIndex(membershipRequest.communityId, membershipRequest.id)
if (indexPending != -1):
community.pendingRequestsToJoin.delete(indexPending)
self.joinedCommunities[membershipRequest.communityId] = community
self.events.emit(SIGNAL_COMMUNITY_EDITED, CommunityArgs(community: community))
of RequestToJoinType.Declined:
break
of RequestToJoinType.Accepted:
break
self.events.on(SignalType.DiscordCategoriesAndChannelsExtracted.event) do(e: Args): self.events.on(SignalType.DiscordCategoriesAndChannelsExtracted.event) do(e: Args):
var receivedData = DiscordCategoriesAndChannelsExtractedSignal(e) var receivedData = DiscordCategoriesAndChannelsExtractedSignal(e)
@ -264,6 +282,7 @@ QtObject:
# therefore, we must keep the old one # therefore, we must keep the old one
community.pendingRequestsToJoin = self.joinedCommunities[community.id].pendingRequestsToJoin community.pendingRequestsToJoin = self.joinedCommunities[community.id].pendingRequestsToJoin
community.declinedRequestsToJoin = self.joinedCommunities[community.id].declinedRequestsToJoin community.declinedRequestsToJoin = self.joinedCommunities[community.id].declinedRequestsToJoin
community.canceledRequestsToJoin = self.joinedCommunities[community.id].canceledRequestsToJoin
# Update the joinded community list with the new data # Update the joinded community list with the new data
self.joinedCommunities[community.id] = community self.joinedCommunities[community.id] = community
@ -407,6 +426,7 @@ QtObject:
if (community.admin): if (community.admin):
self.joinedCommunities[community.id].pendingRequestsToJoin = self.pendingRequestsToJoinForCommunity(community.id) self.joinedCommunities[community.id].pendingRequestsToJoin = self.pendingRequestsToJoinForCommunity(community.id)
self.joinedCommunities[community.id].declinedRequestsToJoin = self.declinedRequestsToJoinForCommunity(community.id) self.joinedCommunities[community.id].declinedRequestsToJoin = self.declinedRequestsToJoinForCommunity(community.id)
self.joinedCommunities[community.id].canceledRequestsToJoin = self.canceledRequestsToJoinForCommunity(community.id)
let allCommunities = self.loadAllCommunities() let allCommunities = self.loadAllCommunities()
for community in allCommunities: for community in allCommunities:
@ -646,6 +666,29 @@ QtObject:
except Exception as e: except Exception as e:
error "Error fetching my community requests", msg = e.msg error "Error fetching my community requests", msg = e.msg
proc loadMyCanceledRequestsToJoin*(self: Service) =
try:
let response = status_go.myCanceledRequestsToJoin()
if response.result.kind != JNull:
for jsonCommunityReqest in response.result:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_ADDED, CommunityRequestArgs(communityRequest: communityRequest))
except Exception as e:
error "Error fetching my community requests", msg = e.msg
proc canceledRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] =
try:
let response = status_go.canceledRequestsToJoinForCommunity(communityId)
result = @[]
if response.result.kind != JNull:
for jsonCommunityReqest in response.result:
result.add(jsonCommunityReqest.toCommunityMembershipRequestDto())
except Exception as e:
error "Error fetching community requests", msg = e.msg
proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] = proc pendingRequestsToJoinForCommunity*(self: Service, communityId: string): seq[CommunityMembershipRequestDto] =
try: try:
let response = status_go.pendingRequestsToJoinForCommunity(communityId) let response = status_go.pendingRequestsToJoinForCommunity(communityId)
@ -1215,6 +1258,25 @@ QtObject:
self.joinedCommunities[communityId] = community self.joinedCommunities[communityId] = community
proc cancelRequestToJoinCommunity*(self: Service, communityId: string) =
try:
var i = 0
for communityRequest in self.myCommunityRequests:
if (communityRequest.communityId == communityId):
let response = status_go.cancelRequestToJoinCommunity(communityRequest.id)
if (not response.error.isNil):
let msg = response.error.message & " communityId=" & communityId
error "error while cancel membership request ", msg
return
self.myCommunityRequests.delete(i)
self.activityCenterService.parseACNotificationResponse(response)
i.inc()
self.events.emit(SIGNAL_REQUEST_TO_JOIN_COMMUNITY_CANCELED, Args())
except Exception as e:
error "Error canceled request to join community", msg = e.msg
proc acceptRequestToJoinCommunity*(self: Service, communityId: string, requestId: string) = proc acceptRequestToJoinCommunity*(self: Service, communityId: string, requestId: string) =
try: try:
let response = status_go.acceptRequestToJoinCommunity(requestId) let response = status_go.acceptRequestToJoinCommunity(requestId)

View File

@ -40,12 +40,23 @@ proc requestToJoinCommunity*(communityId: string, ensName: string): RpcResponse[
proc myPendingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} = proc myPendingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myPendingRequestsToJoin".prefix) result = callPrivateRPC("myPendingRequestsToJoin".prefix)
proc myCanceledRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("myCanceledRequestsToJoin".prefix)
proc pendingRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc pendingRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("pendingRequestsToJoinForCommunity".prefix, %*[communityId]) result = callPrivateRPC("pendingRequestsToJoinForCommunity".prefix, %*[communityId])
proc declinedRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc declinedRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("declinedRequestsToJoinForCommunity".prefix, %*[communityId]) result = callPrivateRPC("declinedRequestsToJoinForCommunity".prefix, %*[communityId])
proc canceledRequestsToJoinForCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("canceledRequestsToJoinForCommunity".prefix, %*[communityId])
proc cancelRequestToJoinCommunity*(requestId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("cancelRequestToJoinCommunity".prefix, %*[{
"id": requestId
}])
proc leaveCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} = proc leaveCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = callPrivateRPC("leaveCommunity".prefix, %*[communityId]) result = callPrivateRPC("leaveCommunity".prefix, %*[communityId])

View File

@ -335,6 +335,10 @@ QtObject {
return communitiesModuleInst.isCommunityRequestPending(id) return communitiesModuleInst.isCommunityRequestPending(id)
} }
function cancelPendingRequest(id: string) {
communitiesModuleInst.cancelRequestToJoinCommunity(id)
}
function getSectionNameById(id) { function getSectionNameById(id) {
return communitiesList.getSectionNameById(id) return communitiesList.getSectionNameById(id)
} }

View File

@ -108,15 +108,16 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
visible: !communityData.joined visible: !communityData.joined
enabled: !invitationPending
text: { text: {
if (invitationPending) return qsTr("Pending") if (invitationPending) return qsTr("Membership request pending...")
return root.communityData.access === Constants.communityChatOnRequestAccess ? return root.communityData.access === Constants.communityChatOnRequestAccess ?
qsTr("Request to join") : qsTr("Join Community") qsTr("Request to join") : qsTr("Join Community")
} }
onClicked: communityIntroDialog.open() onClicked: {
communityIntroDialog.open()
}
Connections { Connections {
target: root.store.communitiesModuleInst target: root.store.communitiesModuleInst
@ -130,12 +131,17 @@ Item {
CommunityIntroDialog { CommunityIntroDialog {
id: communityIntroDialog id: communityIntroDialog
isInvitationPending: joinCommunityButton.invitationPending
name: communityData.name name: communityData.name
introMessage: communityData.introMessage introMessage: communityData.introMessage
imageSrc: communityData.image imageSrc: communityData.image
accessType: communityData.access accessType: communityData.access
onJoined: root.store.requestToJoinCommunity(communityData.id, root.store.userProfileInst.name) onJoined: root.store.requestToJoinCommunity(communityData.id, root.store.userProfileInst.name)
onCancelMembershipRequest: {
root.store.cancelPendingRequest(communityData.id)
joinCommunityButton.invitationPending = root.store.isCommunityRequestPending(communityData.id)
}
} }
} }

View File

@ -18,20 +18,31 @@ StatusDialog {
property string introMessage property string introMessage
property int accessType property int accessType
property url imageSrc property url imageSrc
property bool isInvitationPending: false
signal joined signal joined
signal cancelMembershipRequest
title: qsTr("Welcome to %1").arg(name) title: qsTr("Welcome to %1").arg(name)
footer: StatusDialogFooter { footer: StatusDialogFooter {
rightButtons: ObjectModel { rightButtons: ObjectModel {
StatusButton { StatusButton {
text: root.accessType === Constants.communityChatOnRequestAccess text: root.isInvitationPending ? qsTr("Cancel Membership Request")
? qsTr("Request to join %1").arg(root.name) : (root.accessType === Constants.communityChatOnRequestAccess
: qsTr("Join %1").arg(root.name) ? qsTr("Request to join %1").arg(root.name)
enabled: checkBox.checked : qsTr("Join %1").arg(root.name) )
type: root.isInvitationPending ? StatusBaseButton.Type.Danger
: StatusBaseButton.Type.Normal
enabled: checkBox.checked || root.isInvitationPending
onClicked: { onClicked: {
root.joined() if (root.isInvitationPending) {
root.cancelMembershipRequest()
} else {
root.joined()
}
root.close() root.close()
} }
} }
@ -71,6 +82,7 @@ StatusDialog {
StatusCheckBox { StatusCheckBox {
id: checkBox id: checkBox
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
visible: !root.isInvitationPending
text: qsTr("I agree with the above") text: qsTr("I agree with the above")
} }
} }