status-desktop/ui/imports/shared/stores/PermissionsStore.qml

129 lines
4.7 KiB
QML
Raw Normal View History

import QtQml 2.15
import SortFilterProxyModel 0.2
import StatusQ 0.1
import utils 1.0
QtObject {
id: root
required property string activeSectionId
required property string activeChannelId
required property var chatCommunitySectionModuleInst
// all permissions model
readonly property var permissionsModel:
chatCommunitySectionModuleInst.permissionsModel
function setHideIfPermissionsNotMet(chatId, checked) {
//TODO: backend implementation
}
readonly property var selectedChannelPermissionsModel: SortFilterProxyModel {
id: selectedChannelPermissionsModel
sourceModel: root.permissionsModel
function filterPredicate(modelData) {
return root.permissionsModel.belongsToChat(modelData.id, root.activeChannelId) &&
(modelData.tokenCriteriaMet || !modelData.isPrivate)
}
filters: [
FastExpressionFilter {
expression: {
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
selectedChannelPermissionsModel.filterPredicate(model)
}
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate"]
}
]
}
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: [
FastExpressionFilter {
expression: {
root.activeChannelId // ensure predicate is re-triggered when activeChannelId changes
viewOnlyPermissionsModel.filterPredicate(model)
}
expectedRoles: ["id", "tokenCriteriaMet", "isPrivate", "permissionType"]
}
]
}
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: [
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(permissionType) {
return (permissionType === Constants.permissionType.member ||
permissionType === Constants.permissionType.admin ||
permissionType === Constants.permissionType.becomeTokenMaster)
}
filters: [
FastExpressionFilter {
expression: { return becomeMemberPermissionsModel.filterPredicate(model.permissionType) }
expectedRoles: ["permissionType"]
}
]
}
readonly property bool isOwner: false
feat: introduce first JoinCommunityView for token-gated communities This does a few things: - It integrates with the latest `CommunityTokensMetadata` to access community specific ERC721 token - It changes `ChatLayout` such that it conditionally loads either `ChatView` or `JoinCommunityView`. `JoinCommunityView` has been specifically designed for token-gated communities Here's what works (in terms of token permissions): 1. If a community has token permissions and the the current users is not a member of that community, we show `JoinCommunityView` instead of `ChatView` 2. Any community token permissions of type "Become member" are listed in the `JoinCommunityView` 3. There are different types of token critera a permission can have: ERC20 token, ERC721 token, or ENS (which is also ERC721 but we have a type for that nonetheless) Only ERC20 token balances are checked for the known wallet accounts. This happens every time the known token list has been updated (every 10 min atm). We still need to add balance checks for any ERC721 tokens and ENS. 4. If token permissions are created, updated or deleted by the community owner, the `JoinCommunityView` will update in real-time. You'll also notice that the `Reveal my address and request access` button will be enabled if any of the token permissions are fulfilled (only ERC20 at the time being). Clicking that button will not yet send a request. This will be done in the next step as part of https://github.com/status-im/status-desktop/issues/9761
2023-03-07 16:51:06 +00:00
readonly property bool allTokenRequirementsMet: chatCommunitySectionModuleInst.allTokenRequirementsMet
readonly property QtObject _d: QtObject {
id: d
function createOrEdit(key, holdings, permissionType, isPrivate,
channels) {
root.chatCommunitySectionModuleInst.createOrEditCommunityTokenPermission(
root.activeSectionId, key,
permissionType,
JSON.stringify(holdings),
channels.map(c => c.key).join(","),
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)
}
}