optimize permission lookups

This commit is contained in:
John Gibbon 2020-11-17 11:14:36 +01:00
parent c76d079e03
commit 3cce631aa7
2 changed files with 23 additions and 14 deletions

View file

@ -267,14 +267,15 @@ Page {
forwardMessagesTimer.start();
}
function hasSendPrivilege(privilege) {
return chatPage.isPrivateChat ||
chatGroupInformation &&
(
(chatGroupInformation.status["@type"] === "chatMemberStatusMember" && chatGroupInformation.status.permissions[privilege])
|| chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator"
|| chatGroupInformation.status["@type"] === "chatMemberStatusCreator"
|| (chatGroupInformation.status["@type"] === "chatMemberStatusRestricted" && chatGroupInformation.status.permissions[privilege])
)
var groupStatus = chatGroupInformation ? chatGroupInformation.status : null;
var groupStatusType = grouptStatus ? groupStatus["@type"] : null;
return chatPage.isPrivateChat
|| (groupStatusType === "chatMemberStatusMember" && chatInformation.permissions[privilege])
|| groupStatusType === "chatMemberStatusAdministrator"
|| groupStatusType === "chatMemberStatusCreator"
|| (groupStatusType === "chatMemberStatusRestricted" && groupStatus.permissions[privilege])
}
Timer {

View file

@ -73,11 +73,11 @@ Dialog {
asynchronous: true
sourceComponent: Component {
QtObject {
property var chatGroupInformation: ({})
property bool visible: false
Component.onCompleted: {
if(chatSelectionPage.state === "forwardMessages") {
var chatType = display.type['@type'];
var chatGroupInformation;
if(chatType === "chatTypePrivate" || chatType === "chatTypeSecret") {
visible = true
return;
@ -88,12 +88,20 @@ Dialog {
else if (chatType === "chatTypeSupergroup" ) {
chatGroupInformation = tdLibWrapper.getSuperGroup(display.type.supergroup_id);
}
visible = (chatGroupInformation.status["@type"] === "chatMemberStatusCreator"
|| chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator"
|| (chatGroupInformation.status["@type"] === "chatMemberStatusMember"
var groupStatus = chatGroupInformation.status;
var groupStatusType = groupStatus["@type"];
var groupStatusPermissions = groupStatus.permissions;
var groupPermissions = display.permissions;
visible = (groupStatusType === "chatMemberStatusCreator"
|| groupStatusType === "chatMemberStatusAdministrator"
|| (groupStatusType === "chatMemberStatusMember"
&& chatSelectionPage.payload.neededPermissions.every(function(neededPermission){
return display.permissions[neededPermission];
return groupPermissions[neededPermission];
})
)
|| (groupStatusType === "chatMemberStatusRestricted"
&& chatSelectionPage.payload.neededPermissions.every(function(neededPermission){
return groupStatusPermissions[neededPermission];
})
)
);