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 return chatDto.icon
method amIChatAdmin*(self: Module): bool = method amIChatAdmin*(self: Module): bool =
if(not self.controller.belongsToCommunity()): if not self.controller.belongsToCommunity():
let chatDto = self.controller.getChatDetails() let chatDto = self.controller.getChatDetails()
for member in chatDto.members: for member in chatDto.members:
if (member.id == singletonInstance.userProfile.getPubKey()): 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 member.role == MemberRole.Owner or member.role == MemberRole.Admin or member.role == MemberRole.TokenMaster
return false return false
else: else:
let communityDto = self.controller.getCommunityDetails() let communityDto = self.controller.getCommunityDetails()
return communityDto.memberRole == MemberRole.Owner or return communityDto.isPrivilegedUser
communityDto.memberRole == MemberRole.Admin or communityDto.memberRole == MemberRole.TokenMaster
method pinMessageAllowedForMembers*(self: Module): bool = method pinMessageAllowedForMembers*(self: Module): bool =
if(self.controller.belongsToCommunity()): if(self.controller.belongsToCommunity()):
@ -734,8 +734,7 @@ method markMessagesAsRead*(self: Module, messages: seq[string]) =
self.view.model().markAsSeen(messages) self.view.model().markAsSeen(messages)
method updateCommunityDetails*(self: Module, community: CommunityDto) = method updateCommunityDetails*(self: Module, community: CommunityDto) =
self.view.setAmIChatAdmin(community.memberRole == MemberRole.Owner or self.view.setAmIChatAdmin(community.isPrivilegedUser)
community.memberRole == MemberRole.Admin or community.memberRole == MemberRole.TokenMaster)
self.view.setIsPinMessageAllowedForMembers(community.adminSettings.pinMessageAllMembersEnabled) self.view.setIsPinMessageAllowedForMembers(community.adminSettings.pinMessageAllMembersEnabled)
proc setChatDetails(self: Module, chatDetails: ChatDto) = proc setChatDetails(self: Module, chatDetails: ChatDto) =

View File

@ -350,10 +350,6 @@ method onChatsLoaded*(
if chatId == activeChatId: if chatId == activeChatId:
cModule.onMadeActive() cModule.onMadeActive()
if(self.controller.isCommunity()):
let community = self.controller.getMyCommunity()
self.controller.asyncCheckChannelPermissions(community.id, activeChatId)
self.view.chatsLoaded() self.view.chatsLoaded()
proc checkIfModuleDidLoad(self: Module) = proc checkIfModuleDidLoad(self: Module) =
@ -432,8 +428,9 @@ method activeItemSet*(self: Module, itemId: string) =
self.delegate.onDeactivateChatLoader(deactivateSectionId, deactivateChatId) self.delegate.onDeactivateChatLoader(deactivateSectionId, deactivateChatId)
if self.controller.isCommunity(): 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 = method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant
@ -505,8 +502,10 @@ method onActiveSectionChange*(self: Module, sectionId: string) =
self.setActiveItem(activeChatId) self.setActiveItem(activeChatId)
if self.isCommunity(): if self.isCommunity():
self.controller.asyncCheckPermissionsToJoin() let community = self.controller.getMyCommunity()
self.controller.asyncCheckAllChannelsPermissions() if not community.isPrivilegedUser:
self.controller.asyncCheckPermissionsToJoin()
self.controller.asyncCheckAllChannelsPermissions()
self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId()) 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: if chatId == communityChat.id:
chats.add(communityChat) chats.add(communityChat)
break 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 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 bool communitySettingsDisabled
property var emojiPopup property var emojiPopup
@ -153,7 +159,7 @@ StackLayout {
Loader { Loader {
id: communitySettingsLoader id: communitySettingsLoader
active: root.rootStore.chatCommunitySectionModule.isCommunity() active: root.rootStore.chatCommunitySectionModule.isCommunity() && root.isPrivilegedUser
sourceComponent: CommunitySettingsView { sourceComponent: CommunitySettingsView {
id: communitySettingsView id: communitySettingsView