chore(permissions): Improve performance by using the `Fast` expressions and add necessary models and APIs in the PermissionsStore
Changes: 1. Adding the `Fast` expressions where needed 2. Break the channel permissions into categories in PermissionsStore 3. Remove unused/unneeded code
This commit is contained in:
parent
35c1475403
commit
055d8e8322
|
@ -40,15 +40,6 @@ SortFilterProxyModel {
|
|||
expression: model.icon
|
||||
expectedRoles: ["icon"]
|
||||
},
|
||||
FastExpressionRole {
|
||||
function getColor(color, colorId) {
|
||||
return !!color ? color
|
||||
: Theme.palette.userCustomizationColors[colorId]
|
||||
}
|
||||
name: "color"
|
||||
expression: getColor(model.color, model.colorId)
|
||||
expectedRoles: ["color", "colorId"]
|
||||
},
|
||||
FastExpressionRole {
|
||||
name: "operator"
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import AppLayouts.Communities.panels 1.0
|
|||
import AppLayouts.Communities.controls 1.0
|
||||
|
||||
import StatusQ.Core.Utils 0.1
|
||||
import StatusQ 0.1
|
||||
|
||||
import utils 1.0
|
||||
|
||||
|
@ -21,7 +22,7 @@ SortFilterProxyModel {
|
|||
}
|
||||
|
||||
proxyRoles: [
|
||||
ExpressionRole {
|
||||
FastExpressionRole {
|
||||
name: "text"
|
||||
|
||||
function getName(type, key) {
|
||||
|
@ -50,8 +51,9 @@ SortFilterProxyModel {
|
|||
_collectiblesChanges.revision
|
||||
return getText(model.type, model.key, model.amount)
|
||||
}
|
||||
expectedRoles: ["type", "key", "amount"]
|
||||
},
|
||||
ExpressionRole {
|
||||
FastExpressionRole {
|
||||
name: "imageSource"
|
||||
|
||||
function getIcon(type, key) {
|
||||
|
@ -69,14 +71,16 @@ SortFilterProxyModel {
|
|||
_collectiblesChanges.revision
|
||||
return getIcon(model.type, model.key)
|
||||
}
|
||||
expectedRoles: ["type", "key"]
|
||||
},
|
||||
ExpressionRole {
|
||||
FastExpressionRole {
|
||||
name: "operator"
|
||||
|
||||
// Direct call for singleton enum is not handled properly by SortFilterProxyModel.
|
||||
readonly property int none: OperatorsUtils.Operators.None
|
||||
|
||||
expression: none
|
||||
expectedRoles: []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import QtQml 2.15
|
||||
|
||||
import SortFilterProxyModel 0.2
|
||||
|
||||
import StatusQ 0.1
|
||||
|
||||
import utils 1.0
|
||||
|
||||
QtObject {
|
||||
|
@ -14,16 +17,43 @@ QtObject {
|
|||
readonly property var permissionsModel:
|
||||
chatCommunitySectionModuleInst.permissionsModel
|
||||
|
||||
readonly property var becomeMemberPermissionsModel: SortFilterProxyModel {
|
||||
id: becomeMemberPermissionsModel
|
||||
function setViewOnlyCanAddReaction(chatId, checked) {
|
||||
//TODO: backend implementation
|
||||
}
|
||||
|
||||
function setHideIfPermissionsNotMet(chatId, checked) {
|
||||
//TODO: backend implementation
|
||||
}
|
||||
|
||||
// TODO: Replace with proper backend implementation
|
||||
// This is per chat, not per community
|
||||
readonly property bool viewAndPostCriteriaMet: {
|
||||
if (selectedChannelPermissionsModel.count == 0)
|
||||
return true
|
||||
|
||||
for (var i = 0; i < selectedChannelPermissionsModel.count; i++) {
|
||||
var permissionItem = selectedChannelPermissionsModel.get(i);
|
||||
if (permissionItem && permissionItem.tokenCriteriaMet)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
readonly property var selectedChannelPermissionsModel: SortFilterProxyModel {
|
||||
id: selectedChannelPermissionsModel
|
||||
sourceModel: root.permissionsModel
|
||||
|
||||
function filterPredicate(modelData) {
|
||||
return (modelData.permissionType == Constants.permissionType.member) &&
|
||||
return root.permissionsModel.belongsToChat(modelData.id, root.activeChannelId) &&
|
||||
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
||||
}
|
||||
filters: [
|
||||
ExpressionFilter {
|
||||
expression: becomeMemberPermissionsModel.filterPredicate(model)
|
||||
FastExpressionFilter {
|
||||
expression: {
|
||||
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
||||
selectedChannelPermissionsModel.filterPredicate(model)
|
||||
}
|
||||
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -38,11 +68,12 @@ QtObject {
|
|||
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
||||
}
|
||||
filters: [
|
||||
ExpressionFilter {
|
||||
FastExpressionFilter {
|
||||
expression: {
|
||||
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
||||
viewOnlyPermissionsModel.filterPredicate(model)
|
||||
}
|
||||
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate", "permissionType"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -56,11 +87,27 @@ QtObject {
|
|||
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
||||
}
|
||||
filters: [
|
||||
ExpressionFilter {
|
||||
FastExpressionFilter {
|
||||
expression: {
|
||||
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
||||
viewAndPostPermissionsModel.filterPredicate(model)
|
||||
}
|
||||
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate", "permissionType"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
readonly property var becomeMemberPermissionsModel: SortFilterProxyModel {
|
||||
id: becomeMemberPermissionsModel
|
||||
sourceModel: root.permissionsModel
|
||||
function filterPredicate(modelData) {
|
||||
return (modelData.permissionType == Constants.permissionType.member) &&
|
||||
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
||||
}
|
||||
filters: [
|
||||
FastExpressionFilter {
|
||||
expression: becomeMemberPermissionsModel.filterPredicate(model)
|
||||
expectedRoles: ["permissionType", "tokenCriteriaMet", "isPrivate"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -71,20 +118,9 @@ QtObject {
|
|||
|
||||
readonly property QtObject _d: QtObject {
|
||||
id: d
|
||||
|
||||
function createPermissionEntry(holdings, permissionType, isPrivate,
|
||||
channels) {
|
||||
return {
|
||||
holdingsListModel: holdings,
|
||||
channelsListModel: channels,
|
||||
permissionType,
|
||||
isPrivate
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createOrEdit(key, holdings, permissionType, isPrivate,
|
||||
channels) {
|
||||
|
||||
root.chatCommunitySectionModuleInst.createOrEditCommunityTokenPermission(
|
||||
root.activeSectionId, key,
|
||||
permissionType,
|
||||
|
|
Loading…
Reference in New Issue