chore: do not show permissions change notifications if permission is private or we are not a community member (#14386)

This commit is contained in:
Mykhailo Prakhov 2024-04-11 11:29:00 +02:00 committed by GitHub
parent ced5a9bb4b
commit f743d2f059
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 13 deletions

View File

@ -285,9 +285,9 @@ proc init*(self: Controller) =
self.delegate.onCommunityTokenPermissionUpdateFailed(args.communityId) self.delegate.onCommunityTokenPermissionUpdateFailed(args.communityId)
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED) do(e: Args):
let args = CommunityTokenPermissionRemovedArgs(e) let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId): if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionDeleted(args.communityId, args.permissionId) self.delegate.onCommunityTokenPermissionDeleted(args.communityId, args.tokenPermission)
self.asyncCheckPermissions() self.asyncCheckPermissions()
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETION_FAILED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETION_FAILED) do(e: Args):

View File

@ -354,7 +354,7 @@ method onCommunityTokenPermissionUpdated*(self: AccessInterface, communityId: st
method onCommunityTokenPermissionUpdateFailed*(self: AccessInterface, communityId: string) {.base.} = method onCommunityTokenPermissionUpdateFailed*(self: AccessInterface, communityId: string) {.base.} =
raise newException(ValueError, "No implementation available") 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") raise newException(ValueError, "No implementation available")
method onCommunityTokenPermissionDeletionFailed*(self: AccessInterface, communityId: string) {.base.} = method onCommunityTokenPermissionDeletionFailed*(self: AccessInterface, communityId: string) {.base.} =

View File

@ -396,6 +396,9 @@ proc initCommunityTokenPermissionsModel(self: Module, channelGroup: ChannelGroup
proc convertPubKeysToJson(self: Module, pubKeys: string): seq[string] = proc convertPubKeysToJson(self: Module, pubKeys: string): seq[string] =
return map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr) 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) = method initListOfMyContacts*(self: Module, pubKeys: string) =
var myContacts: seq[UserItem] var myContacts: seq[UserItem]
let contacts = self.controller.getContacts(ContactsGroup.MyMutualContacts) 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) = proc changeCanPostValues*(self: Module, chatId: string, canPostReactions, viewersCanPostReactions: bool) =
self.view.chatsModel().changeCanPostValues(chatId, canPostReactions, viewersCanPostReactions) 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() 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) = method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =
let community = self.controller.getMyCommunity() let community = self.controller.getMyCommunity()
@ -915,7 +920,7 @@ method onCommunityTokenPermissionCreated*(self: Module, communityId: string, tok
self.view.tokenPermissionsModel.addItem(tokenPermissionItem) self.view.tokenPermissionsModel.addItem(tokenPermissionItem)
self.reevaluateRequiresTokenPermissionToJoin() 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") singletonInstance.globalEvents.showCommunityTokenPermissionCreatedNotification(communityId, "Community permission created", "A token permission has been added")
# Returns true if there was an update # 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.view.tokenPermissionsModel.updateItem(tokenPermission.id, tokenPermissionItem)
self.reevaluateRequiresTokenPermissionToJoin() 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") singletonInstance.globalEvents.showCommunityTokenPermissionUpdatedNotification(communityId, "Community permission updated", "A token permission has been updated")
method onCommunityTokenPermissionCreationFailed*(self: Module, communityId: string) = method onCommunityTokenPermissionCreationFailed*(self: Module, communityId: string) =

View File

@ -103,10 +103,6 @@ type
communityId*: string communityId*: string
tokenMetadata*: CommunityTokensMetadataDto tokenMetadata*: CommunityTokensMetadataDto
CommunityTokenPermissionRemovedArgs* = ref object of Args
communityId*: string
permissionId*: string
DiscordCategoriesAndChannelsArgs* = ref object of Args DiscordCategoriesAndChannelsArgs* = ref object of Args
categories*: seq[DiscordCategoryDto] categories*: seq[DiscordCategoryDto]
channels*: seq[DiscordChannelDto] channels*: seq[DiscordChannelDto]
@ -687,8 +683,7 @@ QtObject:
if not community.tokenPermissions.hasKey(id): if not community.tokenPermissions.hasKey(id):
self.communities[community.id].tokenPermissions.del(id) self.communities[community.id].tokenPermissions.del(id)
self.events.emit(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED, self.events.emit(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED,
CommunityTokenPermissionRemovedArgs(communityId: community.id, permissionId: id)) CommunityTokenPermissionArgs(communityId: community.id, tokenPermission: prvTokenPermission))
else: else:
for id, tokenPermission in community.tokenPermissions: for id, tokenPermission in community.tokenPermissions:
if not prevCommunity.tokenPermissions.hasKey(id): if not prevCommunity.tokenPermissions.hasKey(id):