fix(crash): fix crash about community permissions

Fixes #11996
This commit is contained in:
Jonathan Rainville 2023-08-28 15:56:03 -04:00
parent 4ea3ec8575
commit 8336a6d08e
4 changed files with 31 additions and 15 deletions

View File

@ -555,16 +555,16 @@ method getChatIcon*(self: Module): string =
return chatDto.icon
method amIChatAdmin*(self: Module): bool =
if(not self.controller.belongsToCommunity()):
if not self.controller.belongsToCommunity():
let chatDto = self.controller.getChatDetails()
for member in chatDto.members:
if (member.id == singletonInstance.userProfile.getPubKey()):
# TODO untangle this. There is no special roles for group chats
return member.role == MemberRole.Owner or member.role == MemberRole.Admin or member.role == MemberRole.TokenMaster
return false
else:
let communityDto = self.controller.getCommunityDetails()
return communityDto.memberRole == MemberRole.Owner or
communityDto.memberRole == MemberRole.Admin or communityDto.memberRole == MemberRole.TokenMaster
return communityDto.isPrivilegedUser
method pinMessageAllowedForMembers*(self: Module): bool =
if(self.controller.belongsToCommunity()):
@ -734,8 +734,7 @@ method markMessagesAsRead*(self: Module, messages: seq[string]) =
self.view.model().markAsSeen(messages)
method updateCommunityDetails*(self: Module, community: CommunityDto) =
self.view.setAmIChatAdmin(community.memberRole == MemberRole.Owner or
community.memberRole == MemberRole.Admin or community.memberRole == MemberRole.TokenMaster)
self.view.setAmIChatAdmin(community.isPrivilegedUser)
self.view.setIsPinMessageAllowedForMembers(community.adminSettings.pinMessageAllMembersEnabled)
proc setChatDetails(self: Module, chatDetails: ChatDto) =

View File

@ -350,10 +350,6 @@ method onChatsLoaded*(
if chatId == activeChatId:
cModule.onMadeActive()
if(self.controller.isCommunity()):
let community = self.controller.getMyCommunity()
self.controller.asyncCheckChannelPermissions(community.id, activeChatId)
self.view.chatsLoaded()
proc checkIfModuleDidLoad(self: Module) =
@ -432,8 +428,9 @@ method activeItemSet*(self: Module, itemId: string) =
self.delegate.onDeactivateChatLoader(deactivateSectionId, deactivateChatId)
if self.controller.isCommunity():
self.controller.asyncCheckChannelPermissions(mySectionId, activeChatId)
let community = self.controller.getMyCommunity()
if not community.isPrivilegedUser:
self.controller.asyncCheckChannelPermissions(mySectionId, activeChatId)
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
@ -505,8 +502,10 @@ method onActiveSectionChange*(self: Module, sectionId: string) =
self.setActiveItem(activeChatId)
if self.isCommunity():
self.controller.asyncCheckPermissionsToJoin()
self.controller.asyncCheckAllChannelsPermissions()
let community = self.controller.getMyCommunity()
if not community.isPrivilegedUser:
self.controller.asyncCheckPermissionsToJoin()
self.controller.asyncCheckAllChannelsPermissions()
self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId())

View File

@ -566,4 +566,16 @@ proc getCommunityChats*(self: CommunityDto, chatsIds: seq[string]): seq[ChatDto]
if chatId == communityChat.id:
chats.add(communityChat)
break
return chats
return chats
proc isOwner*(self: CommunityDto): bool =
return self.memberRole == MemberRole.Owner
proc isTokenMaster*(self: CommunityDto): bool =
return self.memberRole == MemberRole.TokenMaster
proc isAdmin*(self: CommunityDto): bool =
return self.memberRole == MemberRole.Admin
proc isPrivilegedUser*(self: CommunityDto): bool =
return self.isControlNode or self.isOwner or self.isTokenMaster or self.isAdmin

View File

@ -23,6 +23,12 @@ StackLayout {
property var sectionItemModel
readonly property bool isOwner: community.memberRole === Constants.memberRole.owner
readonly property bool isAdmin: community.memberRole === Constants.memberRole.admin
readonly property bool isTokenMasterOwner: community.memberRole === Constants.memberRole.tokenMaster
readonly property bool isControlNode: community.isControlNode
readonly property bool isPrivilegedUser: isControlNode || isOwner || isAdmin || isTokenMasterOwner
property bool communitySettingsDisabled
property var emojiPopup
@ -153,7 +159,7 @@ StackLayout {
Loader {
id: communitySettingsLoader
active: root.rootStore.chatCommunitySectionModule.isCommunity()
active: root.rootStore.chatCommunitySectionModule.isCommunity() && root.isPrivilegedUser
sourceComponent: CommunitySettingsView {
id: communitySettingsView