From 51b661386a4310ed299115eaa3e16beab95fde9a 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 d19637b196..a22c38769e 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -1072,11 +1072,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 muteCategory*(self: Service, communityId: string, categoryId: string) = try: diff --git a/src/backend/communities.nim b/src/backend/communities.nim index 4bd6f21737..47413c4647 100644 --- a/src/backend/communities.nim +++ b/src/backend/communities.nim @@ -268,5 +268,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 50172a8f5f..5972ff2476 100644 --- a/ui/app/AppLayouts/Chat/popups/community/CommunityDetailPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/community/CommunityDetailPopup.qml @@ -202,7 +202,7 @@ StatusModal { // text = qsTr("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 43d2380e5b..0e6d60377f 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) { @@ -423,7 +423,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 fd2dd05792..970c0c26c8 100644 --- a/ui/imports/shared/views/chat/InvitationBubbleView.qml +++ b/ui/imports/shared/views/chat/InvitationBubbleView.qml @@ -262,7 +262,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 d17b076bc2..f6c9ec7838 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit d17b076bc2371e51b1882432cd5a0a0ef44b20e6 +Subproject commit f6c9ec7838b91aba325351bda2903f25a8ba5547