From f743d2f059421e31631f68c4dc068610fd987bfd Mon Sep 17 00:00:00 2001 From: Mykhailo Prakhov Date: Thu, 11 Apr 2024 11:29:00 +0200 Subject: [PATCH] chore: do not show permissions change notifications if permission is private or we are not a community member (#14386) --- src/app/modules/main/chat_section/controller.nim | 4 ++-- src/app/modules/main/chat_section/io_interface.nim | 2 +- src/app/modules/main/chat_section/module.nim | 13 +++++++++---- src/app_service/service/community/service.nim | 7 +------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 8cc38fb9c3..74341ca731 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -285,9 +285,9 @@ proc init*(self: Controller) = self.delegate.onCommunityTokenPermissionUpdateFailed(args.communityId) self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED) do(e: Args): - let args = CommunityTokenPermissionRemovedArgs(e) + let args = CommunityTokenPermissionArgs(e) if (args.communityId == self.sectionId): - self.delegate.onCommunityTokenPermissionDeleted(args.communityId, args.permissionId) + self.delegate.onCommunityTokenPermissionDeleted(args.communityId, args.tokenPermission) self.asyncCheckPermissions() self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETION_FAILED) do(e: Args): diff --git a/src/app/modules/main/chat_section/io_interface.nim b/src/app/modules/main/chat_section/io_interface.nim index d0dd4c118c..bb09facf59 100644 --- a/src/app/modules/main/chat_section/io_interface.nim +++ b/src/app/modules/main/chat_section/io_interface.nim @@ -354,7 +354,7 @@ method onCommunityTokenPermissionUpdated*(self: AccessInterface, communityId: st method onCommunityTokenPermissionUpdateFailed*(self: AccessInterface, communityId: string) {.base.} = raise newException(ValueError, "No implementation available") -method onCommunityTokenPermissionDeleted*(self: AccessInterface, communityId: string, permissionId: string) {.base.} = +method onCommunityTokenPermissionDeleted*(self: AccessInterface, communityId: string, tokenPermission: CommunityTokenPermissionDto) {.base.} = raise newException(ValueError, "No implementation available") method onCommunityTokenPermissionDeletionFailed*(self: AccessInterface, communityId: string) {.base.} = diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 01afcefa94..55eff0282e 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -396,6 +396,9 @@ proc initCommunityTokenPermissionsModel(self: Module, channelGroup: ChannelGroup proc convertPubKeysToJson(self: Module, pubKeys: string): seq[string] = return map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr) +proc showPermissionUpdateNotification(self: Module, community: CommunityDto, tokenPermission: CommunityTokenPermissionDto): bool = + return tokenPermission.state == TokenPermissionState.Approved and (community.isControlNode or not tokenPermission.isPrivate) and community.isMember + method initListOfMyContacts*(self: Module, pubKeys: string) = var myContacts: seq[UserItem] let contacts = self.controller.getContacts(ContactsGroup.MyMutualContacts) @@ -904,9 +907,11 @@ method changeMutedOnChat*(self: Module, chatId: string, muted: bool) = proc changeCanPostValues*(self: Module, chatId: string, canPostReactions, viewersCanPostReactions: bool) = self.view.chatsModel().changeCanPostValues(chatId, canPostReactions, viewersCanPostReactions) -method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, permissionId: string) = +method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = self.rebuildCommunityTokenPermissionsModel() - singletonInstance.globalEvents.showCommunityTokenPermissionDeletedNotification(communityId, "Community permission deleted", "A token permission has been removed") + let community = self.controller.getMyCommunity() + if self.showPermissionUpdateNotification(community, tokenPermission): + singletonInstance.globalEvents.showCommunityTokenPermissionDeletedNotification(communityId, "Community permission deleted", "A token permission has been removed") method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = let community = self.controller.getMyCommunity() @@ -915,7 +920,7 @@ method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tok self.view.tokenPermissionsModel.addItem(tokenPermissionItem) self.reevaluateRequiresTokenPermissionToJoin() - if tokenPermission.state == TokenPermissionState.Approved: + if self.showPermissionUpdateNotification(community, tokenPermission): singletonInstance.globalEvents.showCommunityTokenPermissionCreatedNotification(communityId, "Community permission created", "A token permission has been added") # Returns true if there was an update @@ -1036,7 +1041,7 @@ method onCommunityTokenPermissionUpdated*(self: Module, communityId: string, tok self.view.tokenPermissionsModel.updateItem(tokenPermission.id, tokenPermissionItem) self.reevaluateRequiresTokenPermissionToJoin() - if tokenPermission.state == TokenPermissionState.Approved: + if self.showPermissionUpdateNotification(community, tokenPermission): singletonInstance.globalEvents.showCommunityTokenPermissionUpdatedNotification(communityId, "Community permission updated", "A token permission has been updated") method onCommunityTokenPermissionCreationFailed*(self: Module, communityId: string) = diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index d0e1c2ca59..db7360dcb8 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -103,10 +103,6 @@ type communityId*: string tokenMetadata*: CommunityTokensMetadataDto - CommunityTokenPermissionRemovedArgs* = ref object of Args - communityId*: string - permissionId*: string - DiscordCategoriesAndChannelsArgs* = ref object of Args categories*: seq[DiscordCategoryDto] channels*: seq[DiscordChannelDto] @@ -687,8 +683,7 @@ QtObject: if not community.tokenPermissions.hasKey(id): self.communities[community.id].tokenPermissions.del(id) self.events.emit(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED, - CommunityTokenPermissionRemovedArgs(communityId: community.id, permissionId: id)) - + CommunityTokenPermissionArgs(communityId: community.id, tokenPermission: prvTokenPermission)) else: for id, tokenPermission in community.tokenPermissions: if not prevCommunity.tokenPermissions.hasKey(id):