From dd346319ffd7aae64638d9cd2dc65f50ceda1edc Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 1 Aug 2023 14:32:10 -0400 Subject: [PATCH] feat(communities): add spectatedCommunityPermissionModel to communities Fixes #11746 --- .../modules/main/communities/controller.nim | 3 +++ .../modules/main/communities/io_interface.nim | 3 +++ src/app/modules/main/communities/module.nim | 11 ++++++++++ src/app/modules/main/communities/view.nim | 21 ++++++++++++++++++- .../Communities/stores/CommunitiesStore.qml | 4 ++++ .../shared/popups/ImportCommunityPopup.qml | 4 +--- 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index c8fb3d894d..8a3921ff2a 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -187,6 +187,9 @@ proc getCommunityTags*(self: Controller): string = proc getAllCommunities*(self: Controller): seq[CommunityDto] = result = self.communityService.getAllCommunities() +proc getCommunityById*(self: Controller, communityId: string): CommunityDto = + result = self.communityService.getCommunityById(communityId) + proc getCuratedCommunities*(self: Controller): seq[CommunityDto] = result = self.communityService.getCuratedCommunities() diff --git a/src/app/modules/main/communities/io_interface.nim b/src/app/modules/main/communities/io_interface.nim index c1e9f436f4..d2cb534b66 100644 --- a/src/app/modules/main/communities/io_interface.nim +++ b/src/app/modules/main/communities/io_interface.nim @@ -200,3 +200,6 @@ method authenticateWithCallback*(self: AccessInterface) {.base.} = method callbackFromAuthentication*(self: AccessInterface, authenticated: bool) {.base.} = raise newException(ValueError, "No implementation available") + +method prepareTokenModelForCommunity*(self: AccessInterface, communityId: string) {.base.} = + raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 0ed3b73ef3..b414078775 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -500,3 +500,14 @@ method authenticateWithCallback*(self: Module) = method callbackFromAuthentication*(self: Module, authenticated: bool) = self.view.callbackFromAuthentication(authenticated) + +method prepareTokenModelForCommunity*(self: Module, communityId: string) = + let community = self.controller.getCommunityById(communityId) + var tokenPermissionsItems: seq[TokenPermissionItem] = @[] + + for id, tokenPermission in community.tokenPermissions: + let chats = self.controller.getChatDetailsByIds(tokenPermission.chatIDs) + let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats) + tokenPermissionsItems.add(tokenPermissionItem) + + self.view.spectatedCommunityPermissionModel.setItems(tokenPermissionsItems) \ No newline at end of file diff --git a/src/app/modules/main/communities/view.nim b/src/app/modules/main/communities/view.nim index c0f7dc1f39..d720ccb810 100644 --- a/src/app/modules/main/communities/view.nim +++ b/src/app/modules/main/communities/view.nim @@ -1,7 +1,8 @@ import NimQml, json, strutils, sequtils import ./io_interface -import ../../shared_models/[section_model, section_item, section_details, token_list_model, token_list_item] +import ../../shared_models/[section_model, section_item, section_details, token_list_model, token_list_item, + token_permissions_model] import ./models/curated_community_model import ./models/discord_file_list_model import ./models/discord_file_item @@ -17,6 +18,8 @@ QtObject: delegate: io_interface.AccessInterface model: SectionModel modelVariant: QVariant + spectatedCommunityPermissionModel: TokenPermissionsModel + spectatedCommunityPermissionModelVariant: QVariant curatedCommunitiesModel: CuratedCommunityModel curatedCommunitiesModelVariant: QVariant curatedCommunitiesLoading: bool @@ -51,6 +54,8 @@ QtObject: proc delete*(self: View) = self.model.delete self.modelVariant.delete + self.spectatedCommunityPermissionModel.delete + self.spectatedCommunityPermissionModelVariant.delete self.curatedCommunitiesModel.delete self.curatedCommunitiesModelVariant.delete self.discordFileListModel.delete @@ -75,6 +80,8 @@ QtObject: result.delegate = delegate result.model = newModel() result.modelVariant = newQVariant(result.model) + result.spectatedCommunityPermissionModel = newTokenPermissionsModel() + result.spectatedCommunityPermissionModelVariant = newQVariant(result.spectatedCommunityPermissionModel) result.curatedCommunitiesModel = newCuratedCommunityModel() result.curatedCommunitiesModelVariant = newQVariant(result.curatedCommunitiesModel) result.curatedCommunitiesLoading = false @@ -301,6 +308,18 @@ QtObject: QtProperty[QVariant] model: read = getModel + proc spectatedCommunityPermissionModel*(self: View): TokenPermissionsModel = + result = self.spectatedCommunityPermissionModel + + proc prepareTokenModelForCommunity(self: View, communityId: string) {.slot.} = + self.delegate.prepareTokenModelForCommunity(communityId) + + proc getSpectatedCommunityPermissionModel(self: View): QVariant {.slot.} = + return self.spectatedCommunityPermissionModelVariant + + QtProperty[QVariant] spectatedCommunityPermissionModel: + read = getSpectatedCommunityPermissionModel + proc curatedCommunitiesModel*(self: View): CuratedCommunityModel = result = self.curatedCommunitiesModel diff --git a/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml b/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml index 8a6c5e1b17..07fff2d640 100644 --- a/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml +++ b/ui/app/AppLayouts/Communities/stores/CommunitiesStore.qml @@ -111,6 +111,10 @@ QtObject { root.communitiesModuleInst.spectateCommunity(publicKey, ""); } + function prepareTokenModelForCommunity(publicKey) { + root.communitiesModuleInst.prepareTokenModelForCommunity(publicKey); + } + function getCommunityDetails(communityId, importing = false) { const publicKey = Utils.isCompressedPubKey(communityId) ? Utils.changeCommunityKeyCompression(communityId) diff --git a/ui/imports/shared/popups/ImportCommunityPopup.qml b/ui/imports/shared/popups/ImportCommunityPopup.qml index dbe9e08a66..df3e1c69c6 100644 --- a/ui/imports/shared/popups/ImportCommunityPopup.qml +++ b/ui/imports/shared/popups/ImportCommunityPopup.qml @@ -24,9 +24,7 @@ StatusDialog { id: d property string importErrorMessage readonly property bool communityFound: (d.isPublicKey && !!d.communityDetails) - readonly property var communityDetails: { - return root.store.getCommunityDetails(Utils.getCompressedPk(publicKey)); - } + readonly property var communityDetails: root.store.getCommunityDetails(publicKey) readonly property string inputErrorMessage: isInputValid ? "" : qsTr("Invalid key") readonly property string errorMessage: importErrorMessage || inputErrorMessage readonly property string inputKey: keyInput.text.trim()