2023-03-07 08:47:04 +00:00
|
|
|
import QtQml 2.15
|
|
|
|
|
2023-06-08 11:01:01 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
2024-02-06 09:22:33 +00:00
|
|
|
|
|
|
|
import StatusQ 0.1
|
|
|
|
|
2023-06-08 11:01:01 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
required property string activeSectionId
|
2023-06-08 11:01:01 +00:00
|
|
|
required property string activeChannelId
|
2023-03-07 08:47:04 +00:00
|
|
|
required property var chatCommunitySectionModuleInst
|
|
|
|
|
2023-06-08 11:01:01 +00:00
|
|
|
// all permissions model
|
2023-03-07 08:47:04 +00:00
|
|
|
readonly property var permissionsModel:
|
|
|
|
chatCommunitySectionModuleInst.permissionsModel
|
|
|
|
|
2024-02-06 09:22:33 +00:00
|
|
|
function setHideIfPermissionsNotMet(chatId, checked) {
|
|
|
|
//TODO: backend implementation
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var selectedChannelPermissionsModel: SortFilterProxyModel {
|
|
|
|
id: selectedChannelPermissionsModel
|
2023-06-08 11:01:01 +00:00
|
|
|
sourceModel: root.permissionsModel
|
2024-02-06 09:22:33 +00:00
|
|
|
|
2023-06-08 11:01:01 +00:00
|
|
|
function filterPredicate(modelData) {
|
2024-02-06 09:22:33 +00:00
|
|
|
return root.permissionsModel.belongsToChat(modelData.id, root.activeChannelId) &&
|
2023-06-08 11:01:01 +00:00
|
|
|
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
|
|
|
}
|
|
|
|
filters: [
|
2024-02-06 09:22:33 +00:00
|
|
|
FastExpressionFilter {
|
|
|
|
expression: {
|
|
|
|
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
|
|
|
selectedChannelPermissionsModel.filterPredicate(model)
|
|
|
|
}
|
|
|
|
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate"]
|
2023-06-08 11:01:01 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var viewOnlyPermissionsModel: SortFilterProxyModel {
|
|
|
|
id: viewOnlyPermissionsModel
|
|
|
|
sourceModel: root.permissionsModel
|
|
|
|
|
|
|
|
function filterPredicate(modelData) {
|
|
|
|
return (modelData.permissionType == Constants.permissionType.read) &&
|
|
|
|
root.permissionsModel.belongsToChat(modelData.id, root.activeChannelId) &&
|
|
|
|
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
|
|
|
}
|
|
|
|
filters: [
|
2024-02-06 09:22:33 +00:00
|
|
|
FastExpressionFilter {
|
2023-06-08 11:01:01 +00:00
|
|
|
expression: {
|
|
|
|
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
|
|
|
viewOnlyPermissionsModel.filterPredicate(model)
|
|
|
|
}
|
2024-02-06 09:22:33 +00:00
|
|
|
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate", "permissionType"]
|
2023-06-08 11:01:01 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var viewAndPostPermissionsModel: SortFilterProxyModel {
|
|
|
|
id: viewAndPostPermissionsModel
|
|
|
|
sourceModel: root.permissionsModel
|
|
|
|
function filterPredicate(modelData) {
|
|
|
|
return (modelData.permissionType == Constants.permissionType.viewAndPost) &&
|
|
|
|
root.permissionsModel.belongsToChat(modelData.id, root.activeChannelId) &&
|
|
|
|
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
|
|
|
}
|
|
|
|
filters: [
|
2024-02-06 09:22:33 +00:00
|
|
|
FastExpressionFilter {
|
2023-06-08 11:01:01 +00:00
|
|
|
expression: {
|
|
|
|
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
|
|
|
viewAndPostPermissionsModel.filterPredicate(model)
|
|
|
|
}
|
2024-02-06 09:22:33 +00:00
|
|
|
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate", "permissionType"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var becomeMemberPermissionsModel: SortFilterProxyModel {
|
|
|
|
id: becomeMemberPermissionsModel
|
|
|
|
sourceModel: root.permissionsModel
|
2024-03-27 12:36:00 +00:00
|
|
|
function filterPredicate(permissionType) {
|
|
|
|
return (permissionType === Constants.permissionType.member ||
|
|
|
|
permissionType === Constants.permissionType.admin ||
|
|
|
|
permissionType === Constants.permissionType.becomeTokenMaster)
|
2024-02-06 09:22:33 +00:00
|
|
|
}
|
|
|
|
filters: [
|
|
|
|
FastExpressionFilter {
|
2024-03-27 12:36:00 +00:00
|
|
|
expression: { return becomeMemberPermissionsModel.filterPredicate(model.permissionType) }
|
|
|
|
expectedRoles: ["permissionType"]
|
2023-06-08 11:01:01 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
readonly property bool isOwner: false
|
|
|
|
|
2023-03-07 16:51:06 +00:00
|
|
|
readonly property bool allTokenRequirementsMet: chatCommunitySectionModuleInst.allTokenRequirementsMet
|
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
readonly property QtObject _d: QtObject {
|
|
|
|
id: d
|
2024-02-06 09:22:33 +00:00
|
|
|
|
2023-03-07 08:47:04 +00:00
|
|
|
function createOrEdit(key, holdings, permissionType, isPrivate,
|
|
|
|
channels) {
|
|
|
|
root.chatCommunitySectionModuleInst.createOrEditCommunityTokenPermission(
|
|
|
|
root.activeSectionId, key,
|
|
|
|
permissionType,
|
|
|
|
JSON.stringify(holdings),
|
2023-06-08 11:01:01 +00:00
|
|
|
channels.map(c => c.key).join(","),
|
2023-03-07 08:47:04 +00:00
|
|
|
isPrivate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function createPermission(holdings, permissionType, isPrivate, channels) {
|
|
|
|
d.createOrEdit("", holdings, permissionType, isPrivate, channels)
|
|
|
|
}
|
|
|
|
|
|
|
|
function editPermission(key, holdings, permissionType, channels, isPrivate) {
|
|
|
|
d.createOrEdit(key, holdings, permissionType, isPrivate, channels)
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePermission(key) {
|
|
|
|
root.chatCommunitySectionModuleInst.deleteCommunityTokenPermission(
|
|
|
|
root.activeSectionId, key)
|
|
|
|
}
|
|
|
|
}
|