refactor: rely on canPost and canView instead of checking permissions (#14993)

* refactor: rely on canPost and canView instead of checking permissions

Fixes #14983

* chore: remove all Light permission checks that are no longer needed
This commit is contained in:
Jonathan Rainville 2024-06-03 15:06:34 -04:00 committed by GitHub
parent 757f1efd98
commit b2fb287beb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 93 additions and 252 deletions

View File

@ -134,12 +134,6 @@ method onMadeActive*(self: AccessInterface) {.base.} =
method onMadeInactive*(self: AccessInterface) {.base.} = method onMadeInactive*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method onUpdateViewOnlyPermissionsSatisfied*(self: AccessInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method onUpdateViewAndPostPermissionsSatisfied*(self: AccessInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available")
method setPermissionsCheckOngoing*(self: AccessInterface, value: bool) {.base.} = method setPermissionsCheckOngoing*(self: AccessInterface, value: bool) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")

View File

@ -444,12 +444,6 @@ method amIChatAdmin*(self: Module): bool =
return communityDto.memberRole == MemberRole.Owner or return communityDto.memberRole == MemberRole.Owner or
communityDto.memberRole == MemberRole.Admin or communityDto.memberRole == MemberRole.TokenMaster communityDto.memberRole == MemberRole.Admin or communityDto.memberRole == MemberRole.TokenMaster
method onUpdateViewOnlyPermissionsSatisfied*(self: Module, value: bool) =
self.view.setViewOnlyPermissionsSatisfied(value)
method onUpdateViewAndPostPermissionsSatisfied*(self: Module, value: bool) =
self.view.setViewAndPostPermissionsSatisfied(value)
method setPermissionsCheckOngoing*(self: Module, value: bool) = method setPermissionsCheckOngoing*(self: Module, value: bool) =
self.view.setPermissionsCheckOngoing(value) self.view.setPermissionsCheckOngoing(value)

View File

@ -13,8 +13,6 @@ QtObject:
pinnedMessagesModelVariant: QVariant pinnedMessagesModelVariant: QVariant
chatDetails: ChatDetails chatDetails: ChatDetails
chatDetailsVariant: QVariant chatDetailsVariant: QVariant
viewOnlyPermissionsSatisfied: bool
viewAndPostPermissionsSatisfied: bool
permissionsCheckOngoing: bool permissionsCheckOngoing: bool
proc chatDetailsChanged*(self:View) {.signal.} proc chatDetailsChanged*(self:View) {.signal.}
@ -34,8 +32,6 @@ QtObject:
result.pinnedMessagesModelVariant = newQVariant(result.pinnedMessagesModel) result.pinnedMessagesModelVariant = newQVariant(result.pinnedMessagesModel)
result.chatDetails = newChatDetails() result.chatDetails = newChatDetails()
result.chatDetailsVariant = newQVariant(result.chatDetails) result.chatDetailsVariant = newQVariant(result.chatDetails)
result.viewOnlyPermissionsSatisfied = false
result.viewAndPostPermissionsSatisfied = false
proc load*(self: View) = proc load*(self: View) =
self.delegate.viewDidLoad() self.delegate.viewDidLoad()
@ -149,30 +145,6 @@ QtObject:
proc updateChatBlocked*(self: View, blocked: bool) = proc updateChatBlocked*(self: View, blocked: bool) =
self.chatDetails.setBlocked(blocked) self.chatDetails.setBlocked(blocked)
proc viewOnlyPermissionsSatisfiedChanged(self: View) {.signal.}
proc setViewOnlyPermissionsSatisfied*(self: View, value: bool) =
self.viewOnlyPermissionsSatisfied = value
self.viewOnlyPermissionsSatisfiedChanged()
proc getViewOnlyPermissionsSatisfied*(self: View): bool {.slot.} =
return self.viewOnlyPermissionsSatisfied or self.amIChatAdmin()
QtProperty[bool] viewOnlyPermissionsSatisfied:
read = getViewOnlyPermissionsSatisfied
notify = viewOnlyPermissionsSatisfiedChanged
proc viewAndPostPermissionsSatisfiedChanged(self: View) {.signal.}
proc setViewAndPostPermissionsSatisfied*(self: View, value: bool) =
self.viewAndPostPermissionsSatisfied = value
self.viewAndPostPermissionsSatisfiedChanged()
proc getViewAndPostPermissionsSatisfied*(self: View): bool {.slot.} =
return self.viewAndPostPermissionsSatisfied or self.amIChatAdmin()
QtProperty[bool] viewAndPostPermissionsSatisfied:
read = getViewAndPostPermissionsSatisfied
notify = viewAndPostPermissionsSatisfiedChanged
proc getPermissionsCheckOngoing*(self: View): bool {.slot.} = proc getPermissionsCheckOngoing*(self: View): bool {.slot.} =
return self.permissionsCheckOngoing return self.permissionsCheckOngoing

View File

@ -16,7 +16,6 @@ import ../../../../app_service/service/community_tokens/service as community_tok
import ../../../../app_service/service/visual_identity/service as procs_from_visual_identity_service import ../../../../app_service/service/visual_identity/service as procs_from_visual_identity_service
import ../../../../app_service/service/shared_urls/service as shared_urls_service import ../../../../app_service/service/shared_urls/service as shared_urls_service
import ../../../../app_service/common/types import ../../../../app_service/common/types
import backend/collectibles as backend_collectibles
import ../../../core/signals/types import ../../../core/signals/types
import ../../../core/eventemitter import ../../../core/eventemitter
@ -92,26 +91,12 @@ proc getMySectionId*(self: Controller): string =
proc asyncCheckPermissionsToJoin*(self: Controller) = proc asyncCheckPermissionsToJoin*(self: Controller) =
if self.delegate.getPermissionsToJoinCheckOngoing(): if self.delegate.getPermissionsToJoinCheckOngoing():
return return
self.communityService.asyncCheckPermissionsToJoin(self.getMySectionId(), addresses = @[], fullCheck = false) self.communityService.asyncCheckPermissionsToJoin(self.getMySectionId(), addresses = @[])
self.delegate.setPermissionsToJoinCheckOngoing(true) self.delegate.setPermissionsToJoinCheckOngoing(true)
proc asyncCheckAllChannelsPermissions*(self: Controller) =
if self.allChannelsPermissionCheckOngoing:
return
self.allChannelsPermissionCheckOngoing = true
self.chatService.asyncCheckAllChannelsPermissions(self.getMySectionId(), addresses = @[], fullCheck = false)
self.delegate.setChannelsPermissionsCheckOngoing(true)
proc asyncCheckChannelPermissions*(self: Controller, communityId: string, chatId: string) = proc asyncCheckChannelPermissions*(self: Controller, communityId: string, chatId: string) =
self.chatService.asyncCheckChannelPermissions(communityId, chatId) self.chatService.asyncCheckChannelPermissions(communityId, chatId)
proc asyncCheckPermissions*(self: Controller) =
let community = self.getMyCommunity()
if community.isPrivilegedUser:
return
self.asyncCheckPermissionsToJoin()
self.asyncCheckAllChannelsPermissions()
proc init*(self: Controller) = proc init*(self: Controller) =
self.events.on(SIGNAL_SENDING_SUCCESS) do(e:Args): self.events.on(SIGNAL_SENDING_SUCCESS) do(e:Args):
let args = MessageSendingSuccess(e) let args = MessageSendingSuccess(e)
@ -268,33 +253,30 @@ proc init*(self: Controller) =
if (args.communityId == self.sectionId): if (args.communityId == self.sectionId):
self.delegate.onCategoryUnmuted(args.categoryId) self.delegate.onCategoryUnmuted(args.categoryId)
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_CREATED) do(e: Args):
let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionCreated(args.communityId, args.tokenPermission)
self.asyncCheckPermissions()
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_CREATION_FAILED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_CREATION_FAILED) do(e: Args):
let args = CommunityTokenPermissionArgs(e) let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId): if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionCreationFailed(args.communityId) self.delegate.onCommunityTokenPermissionCreationFailed(args.communityId)
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_UPDATED) do(e: Args):
let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionUpdated(args.communityId, args.tokenPermission)
self.asyncCheckPermissions()
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_UPDATE_FAILED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_UPDATE_FAILED) do(e: Args):
let args = CommunityTokenPermissionArgs(e) let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId): if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionUpdateFailed(args.communityId) self.delegate.onCommunityTokenPermissionUpdateFailed(args.communityId)
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_CREATED) do(e: Args):
let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionCreated(args.communityId, args.tokenPermission)
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_UPDATED) do(e: Args):
let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionUpdated(args.communityId, args.tokenPermission)
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED) do(e: Args): self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED) do(e: Args):
let args = CommunityTokenPermissionArgs(e) let args = CommunityTokenPermissionArgs(e)
if (args.communityId == self.sectionId): if (args.communityId == self.sectionId):
self.delegate.onCommunityTokenPermissionDeleted(args.communityId, args.tokenPermission) self.delegate.onCommunityTokenPermissionDeleted(args.communityId, args.tokenPermission)
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):
let args = CommunityTokenPermissionArgs(e) let args = CommunityTokenPermissionArgs(e)
@ -316,12 +298,6 @@ proc init*(self: Controller) =
if args.communityId == self.sectionId: if args.communityId == self.sectionId:
self.delegate.onCommunityCheckChannelPermissionsResponse(args.chatId, args.checkChannelPermissionsResponse) self.delegate.onCommunityCheckChannelPermissionsResponse(args.chatId, args.checkChannelPermissionsResponse)
self.events.on(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE) do(e: Args):
let args = CheckAllChannelsPermissionsResponseArgs(e)
if args.communityId == self.sectionId:
self.allChannelsPermissionCheckOngoing = false
self.delegate.onCommunityCheckAllChannelsPermissionsResponse(args.checkAllChannelsPermissionsResponse)
self.events.on(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_FAILED) do(e: Args): self.events.on(SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_FAILED) do(e: Args):
let args = CheckChannelsPermissionsErrorArgs(e) let args = CheckChannelsPermissionsErrorArgs(e)
if args.communityId == self.sectionId: if args.communityId == self.sectionId:
@ -333,15 +309,6 @@ proc init*(self: Controller) =
if args.communityId == self.sectionId: if args.communityId == self.sectionId:
self.delegate.onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin() self.delegate.onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin()
self.events.on(SignalType.Wallet.event, proc(e: Args) =
var data = WalletSignal(e)
if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished:
self.asyncCheckPermissions()
)
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args):
self.asyncCheckPermissions()
self.events.on(SIGNAL_COMMUNITY_KICKED) do (e: Args): self.events.on(SIGNAL_COMMUNITY_KICKED) do (e: Args):
let args = CommunityArgs(e) let args = CommunityArgs(e)
if (args.community.id == self.sectionId): if (args.community.id == self.sectionId):

View File

@ -40,8 +40,6 @@ type
canView: bool canView: bool
viewersCanPostReactions: bool viewersCanPostReactions: bool
hideIfPermissionsNotMet: bool hideIfPermissionsNotMet: bool
viewOnlyPermissionsSatisfied: bool
viewAndPostPermissionsSatisfied: bool
proc initItem*( proc initItem*(
id, id,
@ -75,8 +73,6 @@ proc initItem*(
canPostReactions = true, canPostReactions = true,
viewersCanPostReactions = true, viewersCanPostReactions = true,
hideIfPermissionsNotMet: bool, hideIfPermissionsNotMet: bool,
viewOnlyPermissionsSatisfied: bool,
viewAndPostPermissionsSatisfied: bool,
): Item = ): Item =
result = Item() result = Item()
result.id = id result.id = id
@ -111,8 +107,6 @@ proc initItem*(
result.canPostReactions = canPostReactions result.canPostReactions = canPostReactions
result.viewersCanPostReactions = viewersCanPostReactions result.viewersCanPostReactions = viewersCanPostReactions
result.hideIfPermissionsNotMet = hideIfPermissionsNotMet result.hideIfPermissionsNotMet = hideIfPermissionsNotMet
result.viewOnlyPermissionsSatisfied = viewOnlyPermissionsSatisfied
result.viewAndPostPermissionsSatisfied = viewAndPostPermissionsSatisfied
proc `$`*(self: Item): string = proc `$`*(self: Item): string =
result = fmt"""chat_section/Item( result = fmt"""chat_section/Item(
@ -146,8 +140,6 @@ proc `$`*(self: Item): string =
canPostReactions: {$self.canPostReactions}, canPostReactions: {$self.canPostReactions},
viewersCanPostReactions: {$self.viewersCanPostReactions}, viewersCanPostReactions: {$self.viewersCanPostReactions},
hideIfPermissionsNotMet: {$self.hideIfPermissionsNotMet}, hideIfPermissionsNotMet: {$self.hideIfPermissionsNotMet},
viewOnlyPermissionsSatisfied: {$self.viewOnlyPermissionsSatisfied},
viewAndPostPermissionsSatisfied: {$self.viewAndPostPermissionsSatisfied},
]""" ]"""
proc toJsonNode*(self: Item): JsonNode = proc toJsonNode*(self: Item): JsonNode =
@ -182,8 +174,6 @@ proc toJsonNode*(self: Item): JsonNode =
"canPostReactions": self.canPostReactions, "canPostReactions": self.canPostReactions,
"viewersCanPostReactions": self.viewersCanPostReactions, "viewersCanPostReactions": self.viewersCanPostReactions,
"hideIfPermissionsNotMet": self.hideIfPermissionsNotMet, "hideIfPermissionsNotMet": self.hideIfPermissionsNotMet,
"viewOnlyPermissionsSatisfied": self.viewOnlyPermissionsSatisfied,
"viewAndPostPermissionsSatisfied": self.viewAndPostPermissionsSatisfied
} }
proc delete*(self: Item) = proc delete*(self: Item) =
@ -288,18 +278,6 @@ proc hideIfPermissionsNotMet*(self: Item): bool =
proc `hideIfPermissionsNotMet=`*(self: var Item, value: bool) = proc `hideIfPermissionsNotMet=`*(self: var Item, value: bool) =
self.hideIfPermissionsNotMet = value self.hideIfPermissionsNotMet = value
proc viewAndPostPermissionsSatisfied*(self: Item): bool =
self.viewAndPostPermissionsSatisfied
proc `viewAndPostPermissionsSatisfied=`*(self: var Item, value: bool) =
self.viewAndPostPermissionsSatisfied = value
proc viewOnlyPermissionsSatisfied*(self: Item): bool =
self.viewOnlyPermissionsSatisfied
proc `viewOnlyPermissionsSatisfied=`*(self: var Item, value: bool) =
self.viewOnlyPermissionsSatisfied = value
proc categoryPosition*(self: Item): int = proc categoryPosition*(self: Item): int =
self.categoryPosition self.categoryPosition
@ -379,4 +357,4 @@ proc `viewersCanPostReactions=`*(self: Item, value: bool) =
self.viewersCanPostReactions = value self.viewersCanPostReactions = value
proc hideBecausePermissionsAreNotMet*(self: Item): bool = proc hideBecausePermissionsAreNotMet*(self: Item): bool =
self.hideIfPermissionsNotMet and not self.viewOnlyPermissionsSatisfied and not self.viewAndPostPermissionsSatisfied self.hideIfPermissionsNotMet and not self.canPost and not self.canView

View File

@ -35,13 +35,13 @@ type
LoaderActive LoaderActive
Locked Locked
RequiresPermissions RequiresPermissions
CanPost
CanView
CanPostReactions CanPostReactions
ViewersCanPostReactions ViewersCanPostReactions
HideIfPermissionsNotMet HideIfPermissionsNotMet
ViewOnlyPermissionsSatisfied
ViewAndPostPermissionsSatisfied
ShouldBeHiddenBecausePermissionsAreNotMet #this is a complex role which depends on other roles ShouldBeHiddenBecausePermissionsAreNotMet #this is a complex role which depends on other roles
#(MemberRole , HideIfPermissionsNotMet, ViewOnlyPermissionsSatisfied, ViewAndPostPermissionsSatisfied) #(MemberRole , HideIfPermissionsNotMet, canPost and canView)
QtObject: QtObject:
type type
@ -130,8 +130,6 @@ QtObject:
ModelRole.Position.int:"position", ModelRole.Position.int:"position",
ModelRole.CategoryId.int:"categoryId", ModelRole.CategoryId.int:"categoryId",
ModelRole.HideIfPermissionsNotMet.int:"hideIfPermissionsNotMet", ModelRole.HideIfPermissionsNotMet.int:"hideIfPermissionsNotMet",
ModelRole.ViewOnlyPermissionsSatisfied.int:"viewOnlyPermissionsSatisfied",
ModelRole.ViewAndPostPermissionsSatisfied.int:"viewAndPostPermissionsSatisfied",
ModelRole.CategoryPosition.int:"categoryPosition", ModelRole.CategoryPosition.int:"categoryPosition",
ModelRole.Highlight.int:"highlight", ModelRole.Highlight.int:"highlight",
ModelRole.CategoryOpened.int:"categoryOpened", ModelRole.CategoryOpened.int:"categoryOpened",
@ -141,6 +139,8 @@ QtObject:
ModelRole.LoaderActive.int:"loaderActive", ModelRole.LoaderActive.int:"loaderActive",
ModelRole.Locked.int:"locked", ModelRole.Locked.int:"locked",
ModelRole.RequiresPermissions.int:"requiresPermissions", ModelRole.RequiresPermissions.int:"requiresPermissions",
ModelRole.CanPost.int:"canPost",
ModelRole.CanView.int:"canView",
ModelRole.CanPostReactions.int:"canPostReactions", ModelRole.CanPostReactions.int:"canPostReactions",
ModelRole.ViewersCanPostReactions.int:"viewersCanPostReactions", ModelRole.ViewersCanPostReactions.int:"viewersCanPostReactions",
ModelRole.ShouldBeHiddenBecausePermissionsAreNotMet.int:"shouldBeHiddenBecausePermissionsAreNotMet" ModelRole.ShouldBeHiddenBecausePermissionsAreNotMet.int:"shouldBeHiddenBecausePermissionsAreNotMet"
@ -211,16 +211,16 @@ QtObject:
result = newQVariant(item.isLocked) result = newQVariant(item.isLocked)
of ModelRole.RequiresPermissions: of ModelRole.RequiresPermissions:
result = newQVariant(item.requiresPermissions) result = newQVariant(item.requiresPermissions)
of ModelRole.CanPost:
result = newQVariant(item.canPost)
of ModelRole.CanView:
result = newQVariant(item.canView)
of ModelRole.CanPostReactions: of ModelRole.CanPostReactions:
result = newQVariant(item.canPostReactions) result = newQVariant(item.canPostReactions)
of ModelRole.ViewersCanPostReactions: of ModelRole.ViewersCanPostReactions:
result = newQVariant(item.viewersCanPostReactions) result = newQVariant(item.viewersCanPostReactions)
of ModelRole.HideIfPermissionsNotMet: of ModelRole.HideIfPermissionsNotMet:
result = newQVariant(item.hideIfPermissionsNotMet) result = newQVariant(item.hideIfPermissionsNotMet)
of ModelRole.ViewAndPostPermissionsSatisfied:
result = newQVariant(item.viewAndPostPermissionsSatisfied)
of ModelRole.ViewOnlyPermissionsSatisfied:
result = newQVariant(item.viewOnlyPermissionsSatisfied)
of ModelRole.ShouldBeHiddenBecausePermissionsAreNotMet: of ModelRole.ShouldBeHiddenBecausePermissionsAreNotMet:
return newQVariant(self.itemShouldBeHiddenBecauseNotPermitted(item)) return newQVariant(self.itemShouldBeHiddenBecauseNotPermitted(item))
@ -370,36 +370,6 @@ QtObject:
defer: modelIndex.delete defer: modelIndex.delete
self.dataChanged(modelIndex, modelIndex, @[ModelRole.Locked.int]) self.dataChanged(modelIndex, modelIndex, @[ModelRole.Locked.int])
proc setViewOnlyPermissionsSatisfied*(self: Model, id: string, satisfied: bool) =
let index = self.getItemIdxById(id)
if index == -1:
return
if (self.items[index].viewOnlyPermissionsSatisfied == satisfied):
return
self.items[index].viewOnlyPermissionsSatisfied = satisfied
let modelIndex = self.createIndex(index, 0, nil)
defer: modelIndex.delete
# refresh also ShouldBeHiddenBecausePermissionsAreNotMet because it depends on ViewOnlyPermissionsSatisfied
self.dataChanged(modelIndex, modelIndex, @[ModelRole.ViewOnlyPermissionsSatisfied.int, ModelRole.ShouldBeHiddenBecausePermissionsAreNotMet.int])
self.updateHiddenFlagForCategory(self.items[index].categoryId)
proc setViewAndPostPermissionsSatisfied*(self: Model, id: string, satisfied: bool) =
let index = self.getItemIdxById(id)
if index == -1:
return
if (self.items[index].viewAndPostPermissionsSatisfied == satisfied):
return
self.items[index].viewAndPostPermissionsSatisfied = satisfied
let modelIndex = self.createIndex(index, 0, nil)
defer: modelIndex.delete
# refresh also ShouldBeHiddenBecausePermissionsAreNotMet because it depends on ViewAndPostPermissionsSatisfied
self.dataChanged(modelIndex, modelIndex, @[ModelRole.ViewAndPostPermissionsSatisfied.int, ModelRole.ShouldBeHiddenBecausePermissionsAreNotMet.int])
self.updateHiddenFlagForCategory(self.items[index].categoryId)
proc setItemPermissionsRequired*(self: Model, id: string, value: bool) = proc setItemPermissionsRequired*(self: Model, id: string, value: bool) =
let index = self.getItemIdxById(id) let index = self.getItemIdxById(id)
if index == -1: if index == -1:
@ -431,22 +401,34 @@ QtObject:
defer: modelIndex.delete defer: modelIndex.delete
self.dataChanged(modelIndex, modelIndex, @[ModelRole.Muted.int]) self.dataChanged(modelIndex, modelIndex, @[ModelRole.Muted.int])
proc changeCanPostValues*(self: Model, id: string, canPostReactions, viewersCanPostReactions: bool) = proc changeCanPostValues*(self: Model, id: string, canPost, canView, canPostReactions, viewersCanPostReactions: bool) =
let index = self.getItemIdxById(id) let index = self.getItemIdxById(id)
if index == -1: if index == -1:
return return
if(self.items[index].canPostReactions == canPostReactions and var changedRoles: seq[int] = @[]
self.items[index].viewersCanPostReactions == viewersCanPostReactions
): if self.items[index].canView != canView:
self.items[index].canView = canView
changedRoles.add(ModelRole.CanView.int)
if self.items[index].canPost != canPost:
self.items[index].canPost = canPost
changedRoles.add(ModelRole.CanPost.int)
if self.items[index].canPostReactions != canPostReactions:
self.items[index].canPostReactions = canPostReactions
changedRoles.add(ModelRole.CanPostReactions.int)
if self.items[index].viewersCanPostReactions != viewersCanPostReactions:
self.items[index].viewersCanPostReactions = viewersCanPostReactions
changedRoles.add(ModelRole.ViewersCanPostReactions.int)
if changedRoles.len == 0:
return return
self.items[index].canPostReactions = canPostReactions
self.items[index].viewersCanPostReactions = viewersCanPostReactions
let modelIndex = self.createIndex(index, 0, nil) let modelIndex = self.createIndex(index, 0, nil)
defer: modelIndex.delete defer: modelIndex.delete
self.dataChanged(modelIndex, modelIndex, @[ self.dataChanged(modelIndex, modelIndex, changedRoles)
ModelRole.CanPostReactions.int,
ModelRole.ViewersCanPostReactions.int
])
proc changeMutedOnItemByCategoryId*(self: Model, categoryId: string, muted: bool) = proc changeMutedOnItemByCategoryId*(self: Model, categoryId: string, muted: bool) =
for i in 0 ..< self.items.len: for i in 0 ..< self.items.len:

View File

@ -69,11 +69,11 @@ proc buildChatSectionUI(
mailserversService: mailservers_service.Service, mailserversService: mailservers_service.Service,
sharedUrlsService: shared_urls_service.Service, sharedUrlsService: shared_urls_service.Service,
) )
proc reevaluateRequiresTokenPermissionToJoin(self: Module) proc reevaluateRequiresTokenPermissionToJoin(self: Module)
proc changeCanPostValues*(self: Module, chatId: string, canPost, canView, canPostReactions, viewersCanPostReactions: bool)
proc changeCanPostValues*(self: Module, chatId: string, canPostReactions, viewersCanPostReactions: bool) method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto)
method onCommunityCheckChannelPermissionsResponse*(self: Module, chatId: string, checkChannelPermissionsResponse: CheckChannelPermissionsResponseDto)
method onCommunityCheckAllChannelsPermissionsResponse*(self: Module, checkAllChannelsPermissionsResponse: CheckAllChannelsPermissionsResponseDto)
method addOrUpdateChat(self: Module, method addOrUpdateChat(self: Module,
chat: ChatDto, chat: ChatDto,
belongsToCommunity: bool, belongsToCommunity: bool,
@ -275,8 +275,6 @@ proc addCategoryItem(self: Module, category: Category, memberRole: MemberRole, c
category.id, category.id,
category.position, category.position,
hideIfPermissionsNotMet = false, hideIfPermissionsNotMet = false,
viewOnlyPermissionsSatisfied = true,
viewAndPostPermissionsSatisfied = true,
) )
if insertIntoModel: if insertIntoModel:
@ -448,8 +446,6 @@ method onChatsLoaded*(
self.view.setRequestToJoinState(requestToJoinState) self.view.setRequestToJoinState(requestToJoinState)
self.initCommunityTokenPermissionsModel() self.initCommunityTokenPermissionsModel()
self.onCommunityCheckAllChannelsPermissionsResponse(community.channelPermissions)
self.controller.asyncCheckPermissionsToJoin()
let activeChatId = self.controller.getActiveChatId() let activeChatId = self.controller.getActiveChatId()
let isCurrentSectionActive = self.controller.getIsCurrentSectionActive() let isCurrentSectionActive = self.controller.getIsCurrentSectionActive()
@ -534,7 +530,18 @@ method activeItemSet*(self: Module, itemId: string) =
if self.controller.isCommunity(): if self.controller.isCommunity():
let community = self.controller.getMyCommunity() let community = self.controller.getMyCommunity()
if not community.isPrivilegedUser: if not community.isPrivilegedUser:
self.controller.asyncCheckChannelPermissions(mySectionId, activeChatId) if not chat_item.canView or not chat_item.canPost:
# User doesn't have full access to this channel. Check permissions to know what is missing
self.controller.asyncCheckChannelPermissions(mySectionId, activeChatId)
self.onCommunityCheckChannelPermissionsResponse(activeChatId, CheckChannelPermissionsResponseDto(
viewOnlyPermissions: ViewOnlyOrViewAndPostPermissionsResponseDto(
satisfied: chat_item.canView
),
viewAndPostPermissions: ViewOnlyOrViewAndPostPermissionsResponseDto(
satisfied: chat_item.canPost
),
))
method getModuleAsVariant*(self: Module): QVariant = method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant return self.viewVariant
@ -569,16 +576,6 @@ 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 updateViewOnlyPermissionsSatisfied(self: Module, chatId: string, satisifed: bool) =
if not self.controller.isCommunity():
return
self.view.chatsModel().setViewOnlyPermissionsSatisfied(chatId, satisifed)
proc updateViewAndPostPermissionsSatisfied(self: Module, chatId: string, satisifed: bool) =
if not self.controller.isCommunity():
return
self.view.chatsModel().setViewAndPostPermissionsSatisfied(chatId, satisifed)
proc updateChatRequiresPermissions(self: Module, chatId: string) = proc updateChatRequiresPermissions(self: Module, chatId: string) =
if not self.controller.isCommunity(): if not self.controller.isCommunity():
return return
@ -628,9 +625,13 @@ method onActiveSectionChange*(self: Module, sectionId: string) =
if self.isCommunity(): if self.isCommunity():
let community = self.controller.getMyCommunity() let community = self.controller.getMyCommunity()
if not community.isPrivilegedUser: if not community.isPrivilegedUser:
self.controller.asyncCheckPermissionsToJoin() if not community.joined:
if firstLoad: self.controller.asyncCheckPermissionsToJoin()
self.controller.asyncCheckAllChannelsPermissions() else:
# We do not care about the combinations when we do satisfy
self.onCommunityCheckPermissionsToJoinResponse(CheckPermissionsToJoinResponseDto(
satisfied: true
))
self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId()) self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId())
@ -753,8 +754,6 @@ proc getChatItemFromChatDto(
canPostReactions = canPostReactions, canPostReactions = canPostReactions,
viewersCanPostReactions = viewersCanPostReactions, viewersCanPostReactions = viewersCanPostReactions,
hideIfPermissionsNotMet = hideIfPermissionsNotMet, hideIfPermissionsNotMet = hideIfPermissionsNotMet,
viewOnlyPermissionsSatisfied = true, # will be updated in async call
viewAndPostPermissionsSatisfied = true, # will be updated in async call
) )
proc addNewChat( proc addNewChat(
@ -898,7 +897,7 @@ proc refreshHiddenBecauseNotPermittedState(self: Module) =
method onCommunityChannelEdited*(self: Module, chat: ChatDto) = method onCommunityChannelEdited*(self: Module, chat: ChatDto) =
if(not self.chatContentModules.contains(chat.id)): if(not self.chatContentModules.contains(chat.id)):
return return
self.changeCanPostValues(chat.id, chat.canPostReactions, chat.viewersCanPostReactions) self.changeCanPostValues(chat.id, chat.canPost, chat.canView, chat.canPostReactions, chat.viewersCanPostReactions)
self.view.chatsModel().updateItemDetailsById(chat.id, chat.name, chat.description, chat.emoji, chat.color, chat.hideIfPermissionsNotMet) self.view.chatsModel().updateItemDetailsById(chat.id, chat.name, chat.description, chat.emoji, chat.color, chat.hideIfPermissionsNotMet)
self.refreshHiddenBecauseNotPermittedState() self.refreshHiddenBecauseNotPermittedState()
@ -950,8 +949,8 @@ method onCategoryUnmuted*(self: Module, categoryId: string) =
method changeMutedOnChat*(self: Module, chatId: string, muted: bool) = method changeMutedOnChat*(self: Module, chatId: string, muted: bool) =
self.view.chatsModel().changeMutedOnItemById(chatId, muted) self.view.chatsModel().changeMutedOnItemById(chatId, muted)
proc changeCanPostValues*(self: Module, chatId: string, canPostReactions, viewersCanPostReactions: bool) = proc changeCanPostValues*(self: Module, chatId: string, canPost, canView, canPostReactions, viewersCanPostReactions: bool) =
self.view.chatsModel().changeCanPostValues(chatId, canPostReactions, viewersCanPostReactions) self.view.chatsModel().changeCanPostValues(chatId, canPost, canView, canPostReactions, viewersCanPostReactions)
method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) = method onCommunityTokenPermissionDeleted*(self: Module, communityId: string, tokenPermission: CommunityTokenPermissionDto) =
self.rebuildCommunityTokenPermissionsModel() self.rebuildCommunityTokenPermissionsModel()
@ -1067,11 +1066,7 @@ proc updateChannelPermissionViewData*(
self.updateChatLocked(chatId) self.updateChatLocked(chatId)
if self.chatContentModules.hasKey(chatId): if self.chatContentModules.hasKey(chatId):
self.chatContentModules[chatId].onUpdateViewOnlyPermissionsSatisfied(viewOnlyPermissions.satisfied)
self.chatContentModules[chatId].onUpdateViewAndPostPermissionsSatisfied(viewAndPostPermissions.satisfied)
self.chatContentModules[chatId].setPermissionsCheckOngoing(false) self.chatContentModules[chatId].setPermissionsCheckOngoing(false)
self.updateViewOnlyPermissionsSatisfied(chatId, viewOnlyPermissions.satisfied)
self.updateViewAndPostPermissionsSatisfied(chatId, viewAndPostPermissions.satisfied)
self.refreshHiddenBecauseNotPermittedState() self.refreshHiddenBecauseNotPermittedState()
method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto) = method onCommunityCheckPermissionsToJoinResponse*(self: Module, checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto) =
@ -1379,8 +1374,6 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) =
c.position, c.position,
categoryId="", categoryId="",
hideIfPermissionsNotMet=false, hideIfPermissionsNotMet=false,
viewOnlyPermissionsSatisfied = true,
viewAndPostPermissionsSatisfied = true,
) )
self.view.editCategoryChannelsModel().appendItem(chatItem) self.view.editCategoryChannelsModel().appendItem(chatItem)
let catChats = self.controller.getChats(communityId, categoryId) let catChats = self.controller.getChats(communityId, categoryId)
@ -1404,8 +1397,6 @@ method prepareEditCategoryModel*(self: Module, categoryId: string) =
c.position, c.position,
categoryId, categoryId,
hideIfPermissionsNotMet=false, hideIfPermissionsNotMet=false,
viewOnlyPermissionsSatisfied = true,
viewAndPostPermissionsSatisfied = true,
) )
self.view.editCategoryChannelsModel().appendItem(chatItem, ignoreCategory = true) self.view.editCategoryChannelsModel().appendItem(chatItem, ignoreCategory = true)
@ -1467,7 +1458,7 @@ method addOrUpdateChat(self: Module,
self.chatContentModules[chat.id].onChatUpdated(result) self.chatContentModules[chat.id].onChatUpdated(result)
self.changeMutedOnChat(chat.id, chat.muted) self.changeMutedOnChat(chat.id, chat.muted)
self.changeCanPostValues(chat.id, chat.canPostReactions, chat.viewersCanPostReactions) self.changeCanPostValues(chat.id, result.canPost, result.canView, result.canPostReactions, result.viewersCanPostReactions)
self.updateChatRequiresPermissions(chat.id) self.updateChatRequiresPermissions(chat.id)
self.updateChatLocked(chat.id) self.updateChatLocked(chat.id)
if (chat.chatType == ChatType.PrivateGroupChat): if (chat.chatType == ChatType.PrivateGroupChat):

View File

@ -404,11 +404,11 @@ proc authenticate*(self: Controller) =
proc getCommunityPublicKeyFromPrivateKey*(self: Controller, communityPrivateKey: string): string = proc getCommunityPublicKeyFromPrivateKey*(self: Controller, communityPrivateKey: string): string =
result = self.communityService.getCommunityPublicKeyFromPrivateKey(communityPrivateKey) result = self.communityService.getCommunityPublicKeyFromPrivateKey(communityPrivateKey)
proc asyncCheckPermissionsToJoin*(self: Controller, communityId: string, addressesToShare: seq[string], fullCheck: bool) = proc asyncCheckPermissionsToJoin*(self: Controller, communityId: string, addressesToShare: seq[string]) =
self.communityService.asyncCheckPermissionsToJoin(communityId, addressesToShare, fullCheck) self.communityService.asyncCheckPermissionsToJoin(communityId, addressesToShare)
proc asyncCheckAllChannelsPermissions*(self: Controller, communityId: string, sharedAddresses: seq[string], fullCheck: bool) = proc asyncCheckAllChannelsPermissions*(self: Controller, communityId: string, sharedAddresses: seq[string]) =
self.chatService.asyncCheckAllChannelsPermissions(communityId, sharedAddresses, fullCheck) self.chatService.asyncCheckAllChannelsPermissions(communityId, sharedAddresses)
proc asyncGetRevealedAccountsForMember*(self: Controller, communityId, memberPubkey: string) = proc asyncGetRevealedAccountsForMember*(self: Controller, communityId, memberPubkey: string) =
self.communityService.asyncGetRevealedAccountsForMember(communityId, memberPubkey) self.communityService.asyncGetRevealedAccountsForMember(communityId, memberPubkey)

View File

@ -858,11 +858,11 @@ method getCommunityPublicKeyFromPrivateKey*(self: Module, communityPrivateKey: s
method checkPermissions*(self: Module, communityId: string, sharedAddresses: seq[string]) = method checkPermissions*(self: Module, communityId: string, sharedAddresses: seq[string]) =
self.joiningCommunityDetails.communityIdForPermissions = communityId self.joiningCommunityDetails.communityIdForPermissions = communityId
self.controller.asyncCheckPermissionsToJoin(communityId, sharedAddresses, fullCheck = true) self.controller.asyncCheckPermissionsToJoin(communityId, sharedAddresses)
self.view.setJoinPermissionsCheckSuccessful(false) self.view.setJoinPermissionsCheckSuccessful(false)
self.setCheckingPermissionToJoinInProgress(true) self.setCheckingPermissionToJoinInProgress(true)
self.controller.asyncCheckAllChannelsPermissions(communityId, sharedAddresses, fullCheck = true) self.controller.asyncCheckAllChannelsPermissions(communityId, sharedAddresses)
self.view.setChannelsPermissionsCheckSuccessful(false) self.view.setChannelsPermissionsCheckSuccessful(false)
self.checkingAllChannelPermissionsInProgress = true self.checkingAllChannelPermissionsInProgress = true

View File

@ -27,10 +27,7 @@ type
const asyncCheckChannelPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const asyncCheckChannelPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckChannelPermissionsTaskArg](argEncoded) let arg = decode[AsyncCheckChannelPermissionsTaskArg](argEncoded)
try: try:
var response = status_communities.checkCommunityChannelPermissionsLight(arg.communityId, arg.chatId).result let response = status_communities.checkCommunityChannelPermissions(arg.communityId, arg.chatId).result
let channelPermissions = response.toCheckChannelPermissionsResponseDto()
if not channelPermissions.viewOnlyPermissions.satisfied and not channelPermissions.viewAndPostPermissions.satisfied:
response = status_communities.checkCommunityChannelPermissions(arg.communityId, arg.chatId).result
arg.finish(%* { arg.finish(%* {
"response": response, "response": response,
@ -49,16 +46,11 @@ type
AsyncCheckAllChannelsPermissionsTaskArg = ref object of QObjectTaskArg AsyncCheckAllChannelsPermissionsTaskArg = ref object of QObjectTaskArg
communityId: string communityId: string
addresses: seq[string] addresses: seq[string]
fullCheck: bool
const asyncCheckAllChannelsPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const asyncCheckAllChannelsPermissionsTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckAllChannelsPermissionsTaskArg](argEncoded) let arg = decode[AsyncCheckAllChannelsPermissionsTaskArg](argEncoded)
try: try:
var result = JsonNode() let result = status_communities.checkAllCommunityChannelsPermissions(arg.communityId, arg.addresses).result
if arg.fullCheck:
result = status_communities.checkAllCommunityChannelsPermissions(arg.communityId, arg.addresses).result
else:
result = status_communities.checkAllCommunityChannelsPermissionsLight(arg.communityId).result
let allChannelsPermissions = result.toCheckAllChannelsPermissionsResponseDto() let allChannelsPermissions = result.toCheckAllChannelsPermissionsResponseDto()
arg.finish(%* { arg.finish(%* {
"response": allChannelsPermissions, "response": allChannelsPermissions,

View File

@ -702,14 +702,13 @@ QtObject:
let errMsg = e.msg let errMsg = e.msg
error "error checking all channel permissions: ", errMsg error "error checking all channel permissions: ", errMsg
proc asyncCheckAllChannelsPermissions*(self: Service, communityId: string, addresses: seq[string], fullCheck: bool) = proc asyncCheckAllChannelsPermissions*(self: Service, communityId: string, addresses: seq[string]) =
let arg = AsyncCheckAllChannelsPermissionsTaskArg( let arg = AsyncCheckAllChannelsPermissionsTaskArg(
tptr: cast[ByteAddress](asyncCheckAllChannelsPermissionsTask), tptr: cast[ByteAddress](asyncCheckAllChannelsPermissionsTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckAllChannelsPermissionsDone", slot: "onAsyncCheckAllChannelsPermissionsDone",
communityId: communityId, communityId: communityId,
addresses: addresses, addresses: addresses,
fullCheck: fullCheck
) )
self.threadpool.start(arg) self.threadpool.start(arg)

View File

@ -209,21 +209,11 @@ type
AsyncCheckPermissionsToJoinTaskArg = ref object of QObjectTaskArg AsyncCheckPermissionsToJoinTaskArg = ref object of QObjectTaskArg
communityId: string communityId: string
addresses: seq[string] addresses: seq[string]
fullCheck: bool
const asyncCheckPermissionsToJoinTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} = const asyncCheckPermissionsToJoinTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncCheckPermissionsToJoinTaskArg](argEncoded) let arg = decode[AsyncCheckPermissionsToJoinTaskArg](argEncoded)
try: try:
var response = JsonNode() let response = status_go.checkPermissionsToJoinCommunity(arg.communityId, arg.addresses).result
if not arg.fullCheck:
let hasPermissionToJoin = status_go.checkPermissionsToJoinCommunityLight(arg.communityId, arg.addresses).result.getBool
if hasPermissionToJoin:
let permissionToJoin = CheckPermissionsToJoinResponseDto(satisfied: true)
response = %permissionToJoin
else:
response = status_go.checkPermissionsToJoinCommunity(arg.communityId, arg.addresses).result
else:
response = status_go.checkPermissionsToJoinCommunity(arg.communityId, arg.addresses).result
arg.finish(%* { arg.finish(%* {
"response": response, "response": response,

View File

@ -1619,14 +1619,13 @@ QtObject:
self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community)) self.events.emit(SIGNAL_COMMUNITY_DATA_IMPORTED, CommunityArgs(community: community))
self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community])) self.events.emit(SIGNAL_COMMUNITIES_UPDATE, CommunitiesArgs(communities: @[community]))
proc asyncCheckPermissionsToJoin*(self: Service, communityId: string, addresses: seq[string], fullCheck: bool) = proc asyncCheckPermissionsToJoin*(self: Service, communityId: string, addresses: seq[string]) =
let arg = AsyncCheckPermissionsToJoinTaskArg( let arg = AsyncCheckPermissionsToJoinTaskArg(
tptr: cast[ByteAddress](asyncCheckPermissionsToJoinTask), tptr: cast[ByteAddress](asyncCheckPermissionsToJoinTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncCheckPermissionsToJoinDone", slot: "onAsyncCheckPermissionsToJoinDone",
communityId: communityId, communityId: communityId,
addresses: addresses, addresses: addresses,
fullCheck: fullCheck
) )
self.threadpool.start(arg) self.threadpool.start(arg)

View File

@ -103,12 +103,6 @@ proc checkPermissionsToJoinCommunity*(communityId: string, addresses: seq[string
"addresses": addresses "addresses": addresses
}]) }])
proc checkPermissionsToJoinCommunityLight*(communityId: string, addresses: seq[string]): RpcResponse[JsonNode] =
result = callPrivateRPC("checkPermissionsToJoinCommunityLight".prefix, %*[{
"communityId": communityId,
"addresses": addresses
}])
proc reevaluateCommunityMembersPermissions*( proc reevaluateCommunityMembersPermissions*(
communityId: string, communityId: string,
): RpcResponse[JsonNode] = ): RpcResponse[JsonNode] =
@ -128,17 +122,6 @@ proc checkAllCommunityChannelsPermissions*(communityId: string, addresses: seq[s
"addresses": addresses, "addresses": addresses,
}]) }])
proc checkCommunityChannelPermissionsLight*(communityId: string, chatId: string): RpcResponse[JsonNode] =
result = callPrivateRPC("checkCommunityChannelPermissionsLight".prefix, %*[{
"communityId": communityId,
"chatId": chatId
}])
proc checkAllCommunityChannelsPermissionsLight*(communityId: string): RpcResponse[JsonNode] =
result = callPrivateRPC("checkAllCommunityChannelsPermissionsLight".prefix, %*[{
"communityId": communityId
}])
proc allNonApprovedCommunitiesRequestsToJoin*(): RpcResponse[JsonNode] = proc allNonApprovedCommunitiesRequestsToJoin*(): RpcResponse[JsonNode] =
result = callPrivateRPC("allNonApprovedCommunitiesRequestsToJoin".prefix) result = callPrivateRPC("allNonApprovedCommunitiesRequestsToJoin".prefix)

View File

@ -674,7 +674,7 @@ QtObject {
} else if (_d.activeChatType === Constants.chatType.privateGroupChat) { } else if (_d.activeChatType === Constants.chatType.privateGroupChat) {
return _d.amIMember return _d.amIMember
} else if (_d.activeChatType === Constants.chatType.communityChat) { } else if (_d.activeChatType === Constants.chatType.communityChat) {
return currentChatContentModule().viewAndPostPermissionsSatisfied return currentChatContentModule().chatDetails.canPost
} }
return true return true

View File

@ -46,7 +46,7 @@ Item {
property int activeChatType: parentModule && parentModule.activeItem.type property int activeChatType: parentModule && parentModule.activeItem.type
property bool stickersLoaded: false property bool stickersLoaded: false
property bool permissionUpdatePending: false property bool permissionUpdatePending: false
property bool viewAndPostPermissionsSatisfied: true property bool canPost: true
property var viewAndPostHoldingsModel property var viewAndPostHoldingsModel
readonly property var contactDetails: rootStore ? rootStore.oneToOneChatContact : null readonly property var contactDetails: rootStore ? rootStore.oneToOneChatContact : null
@ -300,7 +300,7 @@ Item {
if (root.permissionUpdatePending) { if (root.permissionUpdatePending) {
return qsTr("Some permissions are being updated. You will be able to send messages once the control node is back online.") return qsTr("Some permissions are being updated. You will be able to send messages once the control node is back online.")
} }
if (!root.viewAndPostPermissionsSatisfied) { if (!root.canPost) {
return qsTr("Sorry, you don't have permissions to post in this channel.") return qsTr("Sorry, you don't have permissions to post in this channel.")
} }
return root.rootStore.chatInputPlaceHolderText return root.rootStore.chatInputPlaceHolderText
@ -389,7 +389,7 @@ Item {
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: (2*Style.current.bigPadding) anchors.leftMargin: (2*Style.current.bigPadding)
visible: (!!root.viewAndPostHoldingsModel && (root.viewAndPostHoldingsModel.count > 0) visible: (!!root.viewAndPostHoldingsModel && (root.viewAndPostHoldingsModel.count > 0)
&& !root.amISectionAdmin && !root.viewAndPostPermissionsSatisfied) && !root.amISectionAdmin && !root.canPost)
assetsModel: root.rootStore.assetsModel assetsModel: root.rootStore.assetsModel
collectiblesModel: root.rootStore.collectiblesModel collectiblesModel: root.rootStore.collectiblesModel
holdingsModel: root.viewAndPostHoldingsModel holdingsModel: root.viewAndPostHoldingsModel

View File

@ -49,8 +49,8 @@ StatusSectionLayout {
property bool stickersLoaded: false property bool stickersLoaded: false
readonly property var chatContentModule: rootStore.currentChatContentModule() || null readonly property var chatContentModule: rootStore.currentChatContentModule() || null
readonly property bool viewOnlyPermissionsSatisfied: chatContentModule.viewOnlyPermissionsSatisfied readonly property bool canView: chatContentModule.chatDetails.canView
readonly property bool viewAndPostPermissionsSatisfied: chatContentModule.viewAndPostPermissionsSatisfied readonly property bool canPost: chatContentModule.chatDetails.canPost
property bool hasViewOnlyPermissions: false property bool hasViewOnlyPermissions: false
property bool hasUnrestrictedViewOnlyPermission: false property bool hasUnrestrictedViewOnlyPermission: false
@ -104,13 +104,13 @@ StatusSectionLayout {
return false return false
} }
if (!hasViewAndPostPermissions && hasViewOnlyPermissions) { if (!hasViewAndPostPermissions && hasViewOnlyPermissions) {
return !viewOnlyPermissionsSatisfied return !canView
} }
if (hasViewAndPostPermissions && !hasViewOnlyPermissions) { if (hasViewAndPostPermissions && !hasViewOnlyPermissions) {
return !viewAndPostPermissionsSatisfied return !canPost
} }
if (hasViewOnlyPermissions && hasViewAndPostPermissions) { if (hasViewOnlyPermissions && hasViewAndPostPermissions) {
return !viewOnlyPermissionsSatisfied && !viewAndPostPermissionsSatisfied return !canView && !canPost
} }
return false return false
} }
@ -245,7 +245,7 @@ StatusSectionLayout {
stickersPopup: root.stickersPopup stickersPopup: root.stickersPopup
permissionUpdatePending: root.permissionUpdatePending permissionUpdatePending: root.permissionUpdatePending
viewAndPostHoldingsModel: root.viewAndPostPermissionsModel viewAndPostHoldingsModel: root.viewAndPostPermissionsModel
viewAndPostPermissionsSatisfied: !root.rootStore.chatCommunitySectionModule.isCommunity() || root.viewAndPostPermissionsSatisfied canPost: !root.rootStore.chatCommunitySectionModule.isCommunity() || root.canPost
amISectionAdmin: root.amISectionAdmin amISectionAdmin: root.amISectionAdmin
onOpenStickerPackPopup: { onOpenStickerPackPopup: {
Global.openPopup(statusStickerPackClickPopup, {packId: stickerPackId, store: root.stickersPopup.store} ) Global.openPopup(statusStickerPackClickPopup, {packId: stickerPackId, store: root.stickersPopup.store} )
@ -267,8 +267,8 @@ StatusSectionLayout {
collectiblesModel: root.collectiblesModel collectiblesModel: root.collectiblesModel
requestToJoinState: root.requestToJoinState requestToJoinState: root.requestToJoinState
requiresRequest: !root.amIMember requiresRequest: !root.amIMember
requirementsMet: (viewOnlyPermissionsSatisfied && viewOnlyPermissionsModel.count > 0) || requirementsMet: (canView && viewOnlyPermissionsModel.count > 0) ||
(viewAndPostPermissionsSatisfied && viewAndPostPermissionsModel.count > 0) (canPost && viewAndPostPermissionsModel.count > 0)
requirementsCheckPending: root.chatContentModule.permissionsCheckOngoing requirementsCheckPending: root.chatContentModule.permissionsCheckOngoing
onRequestToJoinClicked: root.requestToJoinClicked() onRequestToJoinClicked: root.requestToJoinClicked()
onInvitationPendingClicked: root.invitationPendingClicked() onInvitationPendingClicked: root.invitationPendingClicked()