fix(@desktop/chat): make `join` invite transition to `pending`

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.
This commit is contained in:
Patryk Osmaczko 2022-09-15 18:10:03 +02:00 committed by osmaczko
parent d1b3e7af9e
commit e3363e269a
2 changed files with 26 additions and 15 deletions

View File

@ -517,6 +517,17 @@ QtObject:
return false return false
return self.allCommunities[communityId].canJoin 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 = proc joinCommunity*(self: Service, communityId: string): string =
result = "" result = ""
try: try:
@ -541,6 +552,9 @@ QtObject:
error "error: ", procName="joinCommunity", errDesription = "no 'communitiesSettings' key in response" error "error: ", procName="joinCommunity", errDesription = "no 'communitiesSettings' key in response"
return return
if not self.processRequestsToJoinCommunity(response.result):
error "error: ", procName="joinCommunity", errDesription = "no 'requestsToJoinCommunity' key in response"
var updatedCommunity = response.result["communities"][0].toCommunityDto() var updatedCommunity = response.result["communities"][0].toCommunityDto()
let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto() let communitySettings = response.result["communitiesSettings"][0].toCommunitySettingsDto()
@ -570,11 +584,9 @@ QtObject:
try: try:
let response = status_go.requestToJoinCommunity(communityId, ensName) let response = status_go.requestToJoinCommunity(communityId, ensName)
if response.result{"requestsToJoinCommunity"} != nil and response.result{"requestsToJoinCommunity"}.kind != JNull: if not self.processRequestsToJoinCommunity(response.result):
for jsonCommunityReqest in response.result["requestsToJoinCommunity"]: error "error: ", procName="requestToJoinCommunity", errDesription = "no 'requestsToJoinCommunity' key in response"
let communityRequest = jsonCommunityReqest.toCommunityMembershipRequestDto()
self.myCommunityRequests.add(communityRequest)
self.events.emit(SIGNAL_COMMUNITY_MY_REQUEST_ADDED, CommunityRequestArgs(communityRequest: communityRequest))
except Exception as e: except Exception as e:
error "Error requesting to join the community", msg = e.msg, communityId, ensName error "Error requesting to join the community", msg = e.msg, communityId, ensName

View File

@ -99,6 +99,15 @@ Item {
border.width: 1 border.width: 1
states: [ states: [
State {
name: "pending"
when: d.invitationPending
PropertyChanges {
target: joinBtn
text: qsTr("Pending")
enabled: false
}
},
State { State {
name: "requiresEns" name: "requiresEns"
when: d.invitedCommunity.ensOnly && !userProfile.ensName when: d.invitedCommunity.ensOnly && !userProfile.ensName
@ -117,16 +126,6 @@ Item {
enabled: false enabled: false
} }
}, },
State {
name: "pending"
when: d.invitedCommunity.access === Constants.communityChatOnRequestAccess &&
d.invitationPending
PropertyChanges {
target: joinBtn
text: qsTr("Pending")
enabled: false
}
},
State { State {
name: "joined" name: "joined"
when: (d.invitedCommunity.joined && d.invitedCommunity.isMember) || when: (d.invitedCommunity.joined && d.invitedCommunity.isMember) ||