Skip to content

Commit

Permalink
fix(@desktop/chat): make join invite transition to pending
Browse files Browse the repository at this point in the history
User should see `pending` state after he `join`s the community, even if
that community does not require explicit admin approval. That's because
currently, each member has to be accepted by admin, either automatically
or manually. That means, if admin is gone, no one will be ever joined to
community, even if this community states it does not require request to
join.
  • Loading branch information
osmaczko committed Sep 21, 2022
1 parent d1b3e7a commit e3363e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
22 changes: 17 additions & 5 deletions src/app_service/service/community/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,17 @@ QtObject:
return false
return self.allCommunities[communityId].canJoin

proc processRequestsToJoinCommunity(self: Service, responseResult: JsonNode): bool =
if responseResult{"requestsToJoinCommunity"} == nil or responseResult{"requestsToJoinCommunity"}.kind == JNull:
return false

for jsonCommunityReqest in responseResult["requestsToJoinCommunity"]:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_ADDED, CommunityRequestArgs(communityRequest: communityRequest))

return true

proc joinCommunity*(self: Service, communityId: string): string =
result = ""
try:
Expand All @@ -541,6 +552,9 @@ QtObject:
error "error: ", procName="joinCommunity", errDesription = "no 'communitiesSettings' key in response"
return

if not self.processRequestsToJoinCommunity(response.result):
error "error: ", procName="joinCommunity", errDesription = "no 'requestsToJoinCommunity' key in response"

var updatedCommunity = response.result["communities"][0].toCommunityDto()
let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()

Expand Down Expand Up @@ -570,11 +584,9 @@ QtObject:
try:
let response = status_go.requestToJoinCommunity(communityId, ensName)

if response.result{"requestsToJoinCommunity"} != nil and response.result{"requestsToJoinCommunity"}.kind != JNull:
for jsonCommunityReqest in response.result["requestsToJoinCommunity"]:
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_ADDED, CommunityRequestArgs(communityRequest: communityRequest))
if not self.processRequestsToJoinCommunity(response.result):
error "error: ", procName="requestToJoinCommunity", errDesription = "no 'requestsToJoinCommunity' key in response"

except Exception as e:
error "Error requesting to join the community", msg = e.msg, communityId, ensName

Expand Down
19 changes: 9 additions & 10 deletions ui/imports/shared/views/chat/InvitationBubbleView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,29 @@ Item {

states: [
State {
name: "requiresEns"
when: d.invitedCommunity.ensOnly && !userProfile.ensName
name: "pending"
when: d.invitationPending
PropertyChanges {
target: joinBtn
text: qsTr("Membership requires an ENS username")
text: qsTr("Pending")
enabled: false
}
},
State {
name: "inviteOnly"
when: d.invitedCommunity.access === Constants.communityChatInvitationOnlyAccess
name: "requiresEns"
when: d.invitedCommunity.ensOnly && !userProfile.ensName
PropertyChanges {
target: joinBtn
text: qsTr("You need to be invited")
text: qsTr("Membership requires an ENS username")
enabled: false
}
},
State {
name: "pending"
when: d.invitedCommunity.access === Constants.communityChatOnRequestAccess &&
d.invitationPending
name: "inviteOnly"
when: d.invitedCommunity.access === Constants.communityChatInvitationOnlyAccess
PropertyChanges {
target: joinBtn
text: qsTr("Pending")
text: qsTr("You need to be invited")
enabled: false
}
},
Expand Down

0 comments on commit e3363e2

Please sign in to comment.