fix(@desktop/permission): fix permissions lock icon visibility (#15049)

Fix permissions lock icon visibility on channel permissions,
fixes #14746
This commit is contained in:
Godfrain Jacques 2024-06-07 08:04:23 -07:00 committed by GitHub
parent 3010fb58cb
commit ca1ec5281c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 9 deletions

View File

@ -576,7 +576,7 @@ proc updateChatLocked(self: Module, chatId: string) =
let locked = self.controller.checkChatIsLocked(communityId, chatId) let locked = self.controller.checkChatIsLocked(communityId, chatId)
self.view.chatsModel().setItemLocked(chatId, locked) self.view.chatsModel().setItemLocked(chatId, locked)
proc updateChatRequiresPermissions(self: Module, chatId: string) = proc updatePermissionsRequiredOnChat(self: Module, chatId: string) =
if not self.controller.isCommunity(): if not self.controller.isCommunity():
return return
let communityId = self.controller.getMySectionId let communityId = self.controller.getMySectionId
@ -952,21 +952,32 @@ method changeMutedOnChat*(self: Module, chatId: string, muted: bool) =
proc changeCanPostValues*(self: Module, chatId: string, canPost, canView, canPostReactions, viewersCanPostReactions: bool) = proc changeCanPostValues*(self: Module, chatId: string, canPost, canView, canPostReactions, viewersCanPostReactions: bool) =
self.view.chatsModel().changeCanPostValues(chatId, canPost, canView, canPostReactions, viewersCanPostReactions) self.view.chatsModel().changeCanPostValues(chatId, canPost, canView, canPostReactions, viewersCanPostReactions)
method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = proc updateChatsRequiredPermissions(self: Module, chats: seq[ChatDto]) =
self.rebuildCommunityTokenPermissionsModel() for chat in chats:
let community = self.controller.getMyCommunity() self.updatePermissionsRequiredOnChat(chat.id)
proc displayTokenPermissionChangeNotification(self: Module, title: string, message: string, community: CommunityDto, tokenPermission: CommunityTokenPermissionDto) =
if self.showPermissionUpdateNotification(community, tokenPermission): if self.showPermissionUpdateNotification(community, tokenPermission):
singletonInstance.globalEvents.showCommunityTokenPermissionDeletedNotification(communityId, "Community permission deleted", "A token permission has been removed") singletonInstance.globalEvents.showCommunityTokenPermissionCreatedNotification(community.id, title, message)
method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =
self.view.tokenPermissionsModel.removeItemWithId(tokenPermission.id)
self.reevaluateRequiresTokenPermissionToJoin()
let community = self.controller.getMyCommunity()
let chats = community.getCommunityChats(tokenPermission.chatIds)
self.updateChatsRequiredPermissions(chats)
self.displayTokenPermissionChangeNotification("Community permission deleted", "A token permission has been removed", community, tokenPermission)
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()
let chats = community.getCommunityChats(tokenPermission.chatIds) let chats = community.getCommunityChats(tokenPermission.chatIds)
let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats) let tokenPermissionItem = buildTokenPermissionItem(tokenPermission, chats)
self.updateChatsRequiredPermissions(chats)
self.view.tokenPermissionsModel.addItem(tokenPermissionItem) self.view.tokenPermissionsModel.addItem(tokenPermissionItem)
self.reevaluateRequiresTokenPermissionToJoin() self.reevaluateRequiresTokenPermissionToJoin()
if self.showPermissionUpdateNotification(community, tokenPermission): self.displayTokenPermissionChangeNotification("Community permission created", "A token permission has been added", community, tokenPermission)
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
proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckPermissionsResultDto], community: CommunityDto): bool = proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckPermissionsResultDto], community: CommunityDto): bool =
@ -1062,7 +1073,7 @@ proc updateChannelPermissionViewData*(
let viewOnlyUpdated = self.updateTokenPermissionModel(viewOnlyPermissions.permissions, community) let viewOnlyUpdated = self.updateTokenPermissionModel(viewOnlyPermissions.permissions, community)
let viewAndPostUpdated = self.updateTokenPermissionModel(viewAndPostPermissions.permissions, community) let viewAndPostUpdated = self.updateTokenPermissionModel(viewAndPostPermissions.permissions, community)
if viewOnlyUpdated or viewAndPostUpdated: if viewOnlyUpdated or viewAndPostUpdated:
self.updateChatRequiresPermissions(chatId) self.updatePermissionsRequiredOnChat(chatId)
self.updateChatLocked(chatId) self.updateChatLocked(chatId)
if self.chatContentModules.hasKey(chatId): if self.chatContentModules.hasKey(chatId):
@ -1459,7 +1470,7 @@ method addOrUpdateChat(self: Module,
self.changeMutedOnChat(chat.id, chat.muted) self.changeMutedOnChat(chat.id, chat.muted)
self.changeCanPostValues(chat.id, result.canPost, result.canView, result.canPostReactions, result.viewersCanPostReactions) self.changeCanPostValues(chat.id, result.canPost, result.canView, result.canPostReactions, result.viewersCanPostReactions)
self.updateChatRequiresPermissions(chat.id) self.updatePermissionsRequiredOnChat(chat.id)
self.updateChatLocked(chat.id) self.updateChatLocked(chat.id)
if (chat.chatType == ChatType.PrivateGroupChat): if (chat.chatType == ChatType.PrivateGroupChat):
self.onGroupChatDetailsUpdated(chat.id, chat.name, chat.color, chat.icon) self.onGroupChatDetailsUpdated(chat.id, chat.name, chat.color, chat.icon)