fix: set correct permision UI

This commit is contained in:
Mykhailo Prakhov 2024-03-25 23:46:58 +01:00 committed by Jonathan Rainville
parent b5f2a11bc8
commit 7804d4ca39
5 changed files with 14 additions and 7 deletions

View File

@ -392,6 +392,7 @@ proc reevaluateRequiresTokenPermissionToJoin(self: Module) =
for id, tokenPermission in community.tokenPermissions:
if tokenPermission.`type` == TokenPermissionType.BecomeMember or tokenPermission.`type` == TokenPermissionType.BecomeAdmin:
hasBecomeMemberOrBecomeAdminPermissions = true
self.view.setRequiresTokenPermissionToJoin(hasBecomeMemberOrBecomeAdminPermissions)
proc initCommunityTokenPermissionsModel(self: Module, channelGroup: ChannelGroupDto) =
@ -955,6 +956,7 @@ proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckP
)
self.view.tokenPermissionsModel().updateItem(id, updatedTokenPermissionItem)
proc updateCommunityPermissionsView*(self: Module) =
let tokenPermissionsItems = self.view.tokenPermissionsModel().getItems()
let memberPermissions = filter(tokenPermissionsItems, tokenPermissionsItem =>
@ -976,17 +978,17 @@ proc updateTokenPermissionModel*(self: Module, permissions: Table[string, CheckP
let tmRequirementMet = tokenMasterPermissions.len() > 0 and any(tokenMasterPermissions, proc (item: TokenPermissionItem): bool = item.tokenCriteriaMet)
let requiresPermissionToJoin = not (tokenMasterPermissions.len() > 0 and tmRequirementMet) and
((adminPermissions.len() > 0 and adminRequirementMet) or memberPermissions.len() > 0)
let requiresPermissionToJoin = memberPermissions.len() > 0
let tokenRequirementsMet = if requiresPermissionToJoin:
tmRequirementMet or adminRequirementMet or memberRequirementMet
else:
false
true
self.view.setAllTokenRequirementsMet(tokenRequirementsMet)
self.view.setRequiresTokenPermissionToJoin(requiresPermissionToJoin)
proc updateChannelPermissionViewData*(self: Module, chatId: string, viewOnlyPermissions: ViewOnlyOrViewAndPostPermissionsResponseDto, viewAndPostPermissions: ViewOnlyOrViewAndPostPermissionsResponseDto, community: CommunityDto) =
self.updateTokenPermissionModel(viewOnlyPermissions.permissions, community)
self.updateTokenPermissionModel(viewAndPostPermissions.permissions, community)
@ -1004,6 +1006,7 @@ method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissions
let community = self.controller.getMyCommunity()
self.view.setAllTokenRequirementsMet(checkPermissionsToJoinResponse.satisfied)
self.updateTokenPermissionModel(checkPermissionsToJoinResponse.permissions, community)
self.updateCommunityPermissionsView()
self.setPermissionsToJoinCheckOngoing(false)
method onCommunityTokenPermissionUpdated*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =

View File

@ -61,7 +61,8 @@ QtObject {
root.communitiesModuleInst.prepareTokenModelForCommunity(publicKey)
}
readonly property bool allChannelsAreHiddenBecauseNotPermitted: root.chatCommunitySectionModule.allChannelsAreHiddenBecauseNotPermitted
readonly property bool allChannelsAreHiddenBecauseNotPermitted: root.chatCommunitySectionModule.allChannelsAreHiddenBecauseNotPermitted &&
!root.chatCommunitySectionModule.requiresTokenPermissionToJoin
readonly property bool requirementsCheckPending: root.communitiesModuleInst.requirementsCheckPending

View File

@ -13,6 +13,7 @@ import shared.stores.send 1.0
import SortFilterProxyModel 0.2
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Layout 0.1
import StatusQ.Popups 0.1
import StatusQ.Controls 0.1

View File

@ -142,7 +142,7 @@ Control {
text: root.isInvitationPending ? (root.joinCommunity ? d.communityMembershipRequestPendingText : d.channelMembershipRequestPendingText)
: d.communityRequestToJoinText
font.pixelSize: 13
enabled: root.requirementsMet || d.communityPermissionsModel.count === 0
enabled: root.requirementsMet || (joinCommunity && d.communityPermissionsModel.count === 0)
onClicked: root.isInvitationPending ? root.invitationPendingClicked() : root.requestToJoinClicked()
}

View File

@ -97,7 +97,9 @@ QtObject {
id: becomeMemberPermissionsModel
sourceModel: root.permissionsModel
function filterPredicate(modelData) {
return (modelData.permissionType == Constants.permissionType.member) &&
return (modelData.permissionType === Constants.permissionType.member ||
modelData.permissionType === Constants.permissionType.admin ||
modelData.permissionType === Constants.permissionType.becomeTokenMaster) &&
(modelData.tokenCriteriaMet || !modelData.isPrivate)
}
filters: [