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
|
expression: model.icon
|
||||||
expectedRoles: ["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 {
|
FastExpressionRole {
|
||||||
name: "operator"
|
name: "operator"
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import AppLayouts.Communities.panels 1.0
|
||||||
import AppLayouts.Communities.controls 1.0
|
import AppLayouts.Communities.controls 1.0
|
||||||
|
|
||||||
import StatusQ.Core.Utils 0.1
|
import StatusQ.Core.Utils 0.1
|
||||||
|
import StatusQ 0.1
|
||||||
|
|
||||||
import utils 1.0
|
import utils 1.0
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ SortFilterProxyModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyRoles: [
|
proxyRoles: [
|
||||||
ExpressionRole {
|
FastExpressionRole {
|
||||||
name: "text"
|
name: "text"
|
||||||
|
|
||||||
function getName(type, key) {
|
function getName(type, key) {
|
||||||
|
@ -50,8 +51,9 @@ SortFilterProxyModel {
|
||||||
_collectiblesChanges.revision
|
_collectiblesChanges.revision
|
||||||
return getText(model.type, model.key, model.amount)
|
return getText(model.type, model.key, model.amount)
|
||||||
}
|
}
|
||||||
|
expectedRoles: ["type", "key", "amount"]
|
||||||
},
|
},
|
||||||
ExpressionRole {
|
FastExpressionRole {
|
||||||
name: "imageSource"
|
name: "imageSource"
|
||||||
|
|
||||||
function getIcon(type, key) {
|
function getIcon(type, key) {
|
||||||
|
@ -69,14 +71,16 @@ SortFilterProxyModel {
|
||||||
_collectiblesChanges.revision
|
_collectiblesChanges.revision
|
||||||
return getIcon(model.type, model.key)
|
return getIcon(model.type, model.key)
|
||||||
}
|
}
|
||||||
|
expectedRoles: ["type", "key"]
|
||||||
},
|
},
|
||||||
ExpressionRole {
|
FastExpressionRole {
|
||||||
name: "operator"
|
name: "operator"
|
||||||
|
|
||||||
// Direct call for singleton enum is not handled properly by SortFilterProxyModel.
|
// Direct call for singleton enum is not handled properly by SortFilterProxyModel.
|
||||||
readonly property int none: OperatorsUtils.Operators.None
|
readonly property int none: OperatorsUtils.Operators.None
|
||||||
|
|
||||||
expression: none
|
expression: none
|
||||||
|
expectedRoles: []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import QtQml 2.15
|
import QtQml 2.15
|
||||||
|
|
||||||
import SortFilterProxyModel 0.2
|
import SortFilterProxyModel 0.2
|
||||||
|
|
||||||
|
import StatusQ 0.1
|
||||||
|
|
||||||
import utils 1.0
|
import utils 1.0
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
|
@ -14,16 +17,43 @@ QtObject {
|
||||||
readonly property var permissionsModel:
|
readonly property var permissionsModel:
|
||||||
chatCommunitySectionModuleInst.permissionsModel
|
chatCommunitySectionModuleInst.permissionsModel
|
||||||
|
|
||||||
readonly property var becomeMemberPermissionsModel: SortFilterProxyModel {
|
function setViewOnlyCanAddReaction(chatId, checked) {
|
||||||
id: becomeMemberPermissionsModel
|
//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
|
sourceModel: root.permissionsModel
|
||||||
|
|
||||||
function filterPredicate(modelData) {
|
function filterPredicate(modelData) {
|
||||||
return (modelData.permissionType == Constants.permissionType.member) &&
|
return root.permissionsModel.belongsToChat(modelData.id, root.activeChannelId) &&
|
||||||
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
||||||
}
|
}
|
||||||
filters: [
|
filters: [
|
||||||
ExpressionFilter {
|
FastExpressionFilter {
|
||||||
expression: becomeMemberPermissionsModel.filterPredicate(model)
|
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)
|
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
||||||
}
|
}
|
||||||
filters: [
|
filters: [
|
||||||
ExpressionFilter {
|
FastExpressionFilter {
|
||||||
expression: {
|
expression: {
|
||||||
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
||||||
viewOnlyPermissionsModel.filterPredicate(model)
|
viewOnlyPermissionsModel.filterPredicate(model)
|
||||||
}
|
}
|
||||||
|
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate", "permissionType"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -56,11 +87,27 @@ QtObject {
|
||||||
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
(modelData.tokenCriteriaMet || !modelData.isPrivate)
|
||||||
}
|
}
|
||||||
filters: [
|
filters: [
|
||||||
ExpressionFilter {
|
FastExpressionFilter {
|
||||||
expression: {
|
expression: {
|
||||||
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
|
||||||
viewAndPostPermissionsModel.filterPredicate(model)
|
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 {
|
readonly property QtObject _d: QtObject {
|
||||||
id: d
|
id: d
|
||||||
|
|
||||||
function createPermissionEntry(holdings, permissionType, isPrivate,
|
|
||||||
channels) {
|
|
||||||
return {
|
|
||||||
holdingsListModel: holdings,
|
|
||||||
channelsListModel: channels,
|
|
||||||
permissionType,
|
|
||||||
isPrivate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createOrEdit(key, holdings, permissionType, isPrivate,
|
function createOrEdit(key, holdings, permissionType, isPrivate,
|
||||||
channels) {
|
channels) {
|
||||||
|
|
||||||
root.chatCommunitySectionModuleInst.createOrEditCommunityTokenPermission(
|
root.chatCommunitySectionModuleInst.createOrEditCommunityTokenPermission(
|
||||||
root.activeSectionId, key,
|
root.activeSectionId, key,
|
||||||
permissionType,
|
permissionType,
|
||||||
|
|
Loading…
Reference in New Issue