optimize permission lookups
This commit is contained in:
parent
c76d079e03
commit
3cce631aa7
2 changed files with 23 additions and 14 deletions
|
@ -267,14 +267,15 @@ Page {
|
||||||
forwardMessagesTimer.start();
|
forwardMessagesTimer.start();
|
||||||
}
|
}
|
||||||
function hasSendPrivilege(privilege) {
|
function hasSendPrivilege(privilege) {
|
||||||
return chatPage.isPrivateChat ||
|
var groupStatus = chatGroupInformation ? chatGroupInformation.status : null;
|
||||||
chatGroupInformation &&
|
var groupStatusType = grouptStatus ? groupStatus["@type"] : null;
|
||||||
(
|
return chatPage.isPrivateChat
|
||||||
(chatGroupInformation.status["@type"] === "chatMemberStatusMember" && chatGroupInformation.status.permissions[privilege])
|
|| (groupStatusType === "chatMemberStatusMember" && chatInformation.permissions[privilege])
|
||||||
|| chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator"
|
|| groupStatusType === "chatMemberStatusAdministrator"
|
||||||
|| chatGroupInformation.status["@type"] === "chatMemberStatusCreator"
|
|| groupStatusType === "chatMemberStatusCreator"
|
||||||
|| (chatGroupInformation.status["@type"] === "chatMemberStatusRestricted" && chatGroupInformation.status.permissions[privilege])
|
|| (groupStatusType === "chatMemberStatusRestricted" && groupStatus.permissions[privilege])
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
|
|
|
@ -73,11 +73,11 @@ Dialog {
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
sourceComponent: Component {
|
sourceComponent: Component {
|
||||||
QtObject {
|
QtObject {
|
||||||
property var chatGroupInformation: ({})
|
|
||||||
property bool visible: false
|
property bool visible: false
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if(chatSelectionPage.state === "forwardMessages") {
|
if(chatSelectionPage.state === "forwardMessages") {
|
||||||
var chatType = display.type['@type'];
|
var chatType = display.type['@type'];
|
||||||
|
var chatGroupInformation;
|
||||||
if(chatType === "chatTypePrivate" || chatType === "chatTypeSecret") {
|
if(chatType === "chatTypePrivate" || chatType === "chatTypeSecret") {
|
||||||
visible = true
|
visible = true
|
||||||
return;
|
return;
|
||||||
|
@ -88,14 +88,22 @@ Dialog {
|
||||||
else if (chatType === "chatTypeSupergroup" ) {
|
else if (chatType === "chatTypeSupergroup" ) {
|
||||||
chatGroupInformation = tdLibWrapper.getSuperGroup(display.type.supergroup_id);
|
chatGroupInformation = tdLibWrapper.getSuperGroup(display.type.supergroup_id);
|
||||||
}
|
}
|
||||||
|
var groupStatus = chatGroupInformation.status;
|
||||||
visible = (chatGroupInformation.status["@type"] === "chatMemberStatusCreator"
|
var groupStatusType = groupStatus["@type"];
|
||||||
|| chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator"
|
var groupStatusPermissions = groupStatus.permissions;
|
||||||
|| (chatGroupInformation.status["@type"] === "chatMemberStatusMember"
|
var groupPermissions = display.permissions;
|
||||||
|
visible = (groupStatusType === "chatMemberStatusCreator"
|
||||||
|
|| groupStatusType === "chatMemberStatusAdministrator"
|
||||||
|
|| (groupStatusType === "chatMemberStatusMember"
|
||||||
&& chatSelectionPage.payload.neededPermissions.every(function(neededPermission){
|
&& chatSelectionPage.payload.neededPermissions.every(function(neededPermission){
|
||||||
return display.permissions[neededPermission];
|
return groupPermissions[neededPermission];
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|| (groupStatusType === "chatMemberStatusRestricted"
|
||||||
|
&& chatSelectionPage.payload.neededPermissions.every(function(neededPermission){
|
||||||
|
return groupStatusPermissions[neededPermission];
|
||||||
|
})
|
||||||
|
)
|
||||||
);
|
);
|
||||||
} else { // future uses of chat selection can be processed here
|
} else { // future uses of chat selection can be processed here
|
||||||
visible = true;
|
visible = true;
|
||||||
|
|
Loading…
Reference in a new issue