From 3dadc7ebbc280bd721f38af16ca592ee4520b20d Mon Sep 17 00:00:00 2001 From: Pascal Precht <445106+PascalPrecht@users.noreply.github.com> Date: Tue, 31 May 2022 13:16:11 +0200 Subject: [PATCH] refactor: always request access to join community We no longer send community invites to users, instead we just share the community and let users request access. That request will either be automatically or manually accepted by the owner/admin. Depends on https://github.com/status-im/status-go/pull/2682 Closes #5115 --- src/app/modules/main/communities/view.nim | 6 ++++-- src/app_service/service/community/service.nim | 8 +++++--- src/backend/communities.nim | 6 ++++++ .../Chat/popups/community/CommunityDetailPopup.qml | 2 +- ui/app/AppLayouts/Chat/stores/RootStore.qml | 6 +++--- ui/imports/shared/views/chat/InvitationBubbleView.qml | 2 +- vendor/status-go | 2 +- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index 068b6be857..7214721f66 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -90,8 +90,10 @@ QtObject: self.observedItem.setActiveSectionData(item) self.observedItemChanged() - proc joinCommunity*(self: View, communityId: string): string {.slot.} = - result = self.delegate.joinCommunity(communityId) + proc joinCommunity*(self: View, communityId: string, ensName: string) {.slot.} = + # Users always have to request to join a community but might + # get automatically accepted. + self.delegate.requestToJoinCommunity(communityId, ensName) proc createCommunity*(self: View, name: string, description: string, introMessage: string, outroMessage: string, diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index cc0acd729e..a2117c6f98 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -1066,11 +1066,13 @@ QtObject: var pubKeys: seq[string] = @[] for pubKey in pubKeysParsed: pubKeys.add(pubKey.getStr) - let response = status_go.inviteUsersToCommunity(communityId, pubKeys) + # We no longer send invites, but merely share the community so + # users can request access (with automatic acception) + let response = status_go.shareCommunityToUsers(communityId, pubKeys) discard self.chatService.processMessageUpdateAfterSend(response) except Exception as e: - error "Error inviting to community", msg = e.msg - result = "Error exporting community: " & e.msg + error "Error sharing community", msg = e.msg + result = "Error sharing community: " & e.msg proc removeUserFromCommunity*(self: Service, communityId: string, pubKey: string) = try: diff --git a/src/backend/communities.nim b/src/backend/communities.nim index d1ce9046ed..1f65c13b6b 100644 --- a/src/backend/communities.nim +++ b/src/backend/communities.nim @@ -260,5 +260,11 @@ proc inviteUsersToCommunity*(communityId: string, pubKeys: seq[string]): RpcResp "users": pubKeys }]) +proc shareCommunityToUsers*(communityId: string, pubKeys: seq[string]): RpcResponse[JsonNode] {.raises: [Exception].} = + return callPrivateRPC("shareCommunity".prefix, %*[{ + "communityId": communityId, + "users": pubKeys + }]) + proc getCommunitiesSettings*(): RpcResponse[JsonNode] {.raises: [Exception].} = return callPrivateRPC("getCommunitiesSettings".prefix, %*[]) diff --git a/ui/app/AppLayouts/Chat/popups/community/CommunityDetailPopup.qml b/ui/app/AppLayouts/Chat/popups/community/CommunityDetailPopup.qml index 8abf65ea8e..4578f76b24 100644 --- a/ui/app/AppLayouts/Chat/popups/community/CommunityDetailPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/community/CommunityDetailPopup.qml @@ -216,7 +216,7 @@ StatusModal { // text = qsTrId("invite-chat-pending") // } } else { - error = root.store.communitiesModuleInst.joinCommunity(root.communityId) + error = root.store.communitiesModuleInst.joinCommunity(root.communityId, root.store.userProfileInst.ensName) } if (error) { diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index ac88ae8ef9..75f6ac2606 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -341,8 +341,8 @@ QtObject { chatCommunitySectionModule.reorderCommunityChat(categoryId, chatId, to) } - function joinCommunity(id) { - return communitiesModuleInst.joinCommunity(id) + function joinCommunity(id, ensName) { + return communitiesModuleInst.joinCommunity(id, ensName) } function requestToJoinCommunity(id, ensName) { @@ -425,7 +425,7 @@ QtObject { const userCanJoin = userCanJoin(communityId) // TODO find what to do when you can't join if (userCanJoin) { - joinCommunity(communityId, true) + joinCommunity(communityId, userProfileInst.ensName) } } return result diff --git a/ui/imports/shared/views/chat/InvitationBubbleView.qml b/ui/imports/shared/views/chat/InvitationBubbleView.qml index 74f3ce8ddf..6624951855 100644 --- a/ui/imports/shared/views/chat/InvitationBubbleView.qml +++ b/ui/imports/shared/views/chat/InvitationBubbleView.qml @@ -275,7 +275,7 @@ Item { } if (rectangleBubble.state === "unjoined") { Global.openPopup(communityIntroDialog, { joinMethod: () => { - let error = root.store.joinCommunity(communityId) + let error = root.store.joinCommunity(communityId, userProfile.name) if (error) joiningError.showError(error) } }); } diff --git a/vendor/status-go b/vendor/status-go index 23d745fe0a..8ccb3ece6f 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit 23d745fe0a61501b847af9c54479d5fa763a51d0 +Subproject commit 8ccb3ece6ffb433b5c313a4a89efeafce8e82d3c