forwarding/new message/attachment permissions
enhances #159 PR, hopefully fixes #164 issue
This commit is contained in:
parent
9141b8e68b
commit
d5a2d315db
3 changed files with 95 additions and 11 deletions
|
@ -406,3 +406,28 @@ function handleErrorMessage(code, message) {
|
||||||
appNotification.show(message);
|
appNotification.show(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMessagesNeededForwardPermissions(messages) {
|
||||||
|
var neededPermissions = ["can_send_messages"];
|
||||||
|
|
||||||
|
var mediaMessageTypes = ["messageAudio", "messageDocument", "messagePhoto", "messageVideo", "messageVideoNote", "messageVoiceNote"];
|
||||||
|
var otherMessageTypes = ["messageAnimation", "messageGame", "messageSticker"]
|
||||||
|
for(var i = 0; i < messages.length; i += 1) {
|
||||||
|
var type = messages[i]["content"]["@type"];
|
||||||
|
var permission = "";
|
||||||
|
if(type === "messageText") {
|
||||||
|
continue;
|
||||||
|
} else if(type === "messagePoll") {
|
||||||
|
permission = "can_send_polls";
|
||||||
|
} else if(mediaMessageTypes.indexOf(type) > -1) {
|
||||||
|
permission = "can_send_media_messages";
|
||||||
|
} else if(otherMessageTypes.indexOf(type) > -1) {
|
||||||
|
permission = "can_send_other_messages";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(permission !== "" && neededPermissions.indexOf(permission) === -1) {
|
||||||
|
neededPermissions.push(permission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return neededPermissions;
|
||||||
|
}
|
||||||
|
|
|
@ -266,6 +266,17 @@ Page {
|
||||||
forwardMessagesTimer.messageIds = messageIds;
|
forwardMessagesTimer.messageIds = messageIds;
|
||||||
forwardMessagesTimer.start();
|
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" && chatInformation.permissions[privilege])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: forwardMessagesTimer
|
id: forwardMessagesTimer
|
||||||
interval: 200
|
interval: 200
|
||||||
|
@ -822,7 +833,7 @@ Page {
|
||||||
topPadding: Theme.paddingSmall
|
topPadding: Theme.paddingSmall
|
||||||
width: parent.width - ( 2 * Theme.horizontalPageMargin )
|
width: parent.width - ( 2 * Theme.horizontalPageMargin )
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
visible: !chatPage.isChannel
|
visible: chatPage.hasSendPrivilege("can_send_messages")
|
||||||
height: visible ? implicitHeight : 0
|
height: visible ? implicitHeight : 0
|
||||||
Behavior on opacity { FadeAnimation {} }
|
Behavior on opacity { FadeAnimation {} }
|
||||||
|
|
||||||
|
@ -859,7 +870,7 @@ Page {
|
||||||
layoutDirection: Qt.RightToLeft
|
layoutDirection: Qt.RightToLeft
|
||||||
spacing: Theme.paddingMedium
|
spacing: Theme.paddingMedium
|
||||||
IconButton {
|
IconButton {
|
||||||
id: imageAttachmentButton
|
visible: chatPage.hasSendPrivilege("can_send_media_messages")
|
||||||
icon.source: "image://theme/icon-m-image"
|
icon.source: "image://theme/icon-m-image"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var picker = pageStack.push("Sailfish.Pickers.ImagePickerPage");
|
var picker = pageStack.push("Sailfish.Pickers.ImagePickerPage");
|
||||||
|
@ -874,7 +885,7 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IconButton {
|
IconButton {
|
||||||
id: videoAttachmentButton
|
visible: chatPage.hasSendPrivilege("can_send_media_messages")
|
||||||
icon.source: "image://theme/icon-m-video"
|
icon.source: "image://theme/icon-m-video"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var picker = pageStack.push("Sailfish.Pickers.VideoPickerPage");
|
var picker = pageStack.push("Sailfish.Pickers.VideoPickerPage");
|
||||||
|
@ -889,7 +900,7 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IconButton {
|
IconButton {
|
||||||
id: documentAttachmentButton
|
visible: chatPage.hasSendPrivilege("can_send_media_messages")
|
||||||
icon.source: "image://theme/icon-m-document"
|
icon.source: "image://theme/icon-m-document"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var picker = pageStack.push("Sailfish.Pickers.DocumentPickerPage");
|
var picker = pageStack.push("Sailfish.Pickers.DocumentPickerPage");
|
||||||
|
@ -905,6 +916,8 @@ Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
IconButton {
|
IconButton {
|
||||||
|
|
||||||
|
visible: chatPage.hasSendPrivilege("can_send_other_messages")
|
||||||
icon.source: "../../images/icon-m-sticker.svg"
|
icon.source: "../../images/icon-m-sticker.svg"
|
||||||
icon.sourceSize {
|
icon.sourceSize {
|
||||||
width: Theme.iconSizeMedium
|
width: Theme.iconSizeMedium
|
||||||
|
@ -917,10 +930,7 @@ Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IconButton {
|
IconButton {
|
||||||
visible: !chatPage.isPrivateChat && chatGroupInformation &&
|
visible: !chatPage.isPrivateChat && chatPage.hasSendPrivilege("can_send_polls")
|
||||||
(chatGroupInformation.status["@type"] === "chatMemberStatusCreator"
|
|
||||||
|| chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator"
|
|
||||||
|| (chatGroupInformation.status["@type"] === "chatMemberStatusMember" && chatInformation.permissions.can_send_polls))
|
|
||||||
icon.source: "image://theme/icon-m-question"
|
icon.source: "image://theme/icon-m-question"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
pageStack.push(Qt.resolvedUrl("../pages/PollCreationPage.qml"), { "chatId" : chatInformation.id, groupName: chatInformation.title});
|
pageStack.push(Qt.resolvedUrl("../pages/PollCreationPage.qml"), { "chatId" : chatInformation.id, groupName: chatInformation.title});
|
||||||
|
@ -1205,12 +1215,11 @@ Page {
|
||||||
icon.source: "image://theme/icon-m-forward"
|
icon.source: "image://theme/icon-m-forward"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var ids = Functions.getMessagesArrayIds(chatPage.selectedMessages);
|
var ids = Functions.getMessagesArrayIds(chatPage.selectedMessages);
|
||||||
|
var neededPermissions = Functions.getMessagesNeededForwardPermissions(chatPage.selectedMessages);
|
||||||
var chatId = chatInformation.id;
|
var chatId = chatInformation.id;
|
||||||
|
|
||||||
pageStack.push(Qt.resolvedUrl("../pages/ChatSelectionPage.qml"), {
|
pageStack.push(Qt.resolvedUrl("../pages/ChatSelectionPage.qml"), {
|
||||||
headerDescription: qsTr("Forward %n messages", "dialog header", ids.length).arg(ids.length),
|
headerDescription: qsTr("Forward %n messages", "dialog header", ids.length).arg(ids.length),
|
||||||
payload: {fromChatId: chatId, messageIds:ids},
|
payload: {fromChatId: chatId, messageIds:ids, neededPermissions: neededPermissions},
|
||||||
state: "forwardMessages"
|
state: "forwardMessages"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,10 @@ Dialog {
|
||||||
acceptDestinationReplaceTarget: pageStack.find( function(page){ return(page._depth === 0)} )
|
acceptDestinationReplaceTarget: pageStack.find( function(page){ return(page._depth === 0)} )
|
||||||
property alias headerTitle: pageHeader.title
|
property alias headerTitle: pageHeader.title
|
||||||
property alias headerDescription: pageHeader.description
|
property alias headerDescription: pageHeader.description
|
||||||
|
/*
|
||||||
|
payload dependent on chatSelectionPage.state
|
||||||
|
- forwardMessages: {fromChatId, messageIds, neededPermissions}
|
||||||
|
*/
|
||||||
property var payload: ({})
|
property var payload: ({})
|
||||||
|
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
|
@ -38,6 +42,7 @@ Dialog {
|
||||||
case "forwardMessages":
|
case "forwardMessages":
|
||||||
acceptDestinationInstance.forwardMessages(payload.fromChatId, payload.messageIds)
|
acceptDestinationInstance.forwardMessages(payload.fromChatId, payload.messageIds)
|
||||||
break;
|
break;
|
||||||
|
// future uses of chat selection can be processed here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +67,52 @@ Dialog {
|
||||||
model: chatListModel
|
model: chatListModel
|
||||||
delegate: ChatListViewItem {
|
delegate: ChatListViewItem {
|
||||||
ownUserId: overviewPage.ownUserId
|
ownUserId: overviewPage.ownUserId
|
||||||
|
Loader { // checking permissions takes a while, so we defer those calculations
|
||||||
|
id: visibleLoader
|
||||||
|
asynchronous: true
|
||||||
|
sourceComponent: Component {
|
||||||
|
QtObject {
|
||||||
|
property var chatGroupInformation: ({})
|
||||||
|
property bool visible: false
|
||||||
|
Component.onCompleted: {
|
||||||
|
if(chatSelectionPage.state === "forwardMessages") {
|
||||||
|
var chatType = display.type['@type'];
|
||||||
|
if(chatType === "chatTypePrivate" || chatType === "chatTypeSecret") {
|
||||||
|
visible = true
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (chatType === "chatTypeBasicGroup" ) {
|
||||||
|
chatGroupInformation = tdLibWrapper.getBasicGroup(display.type.basic_group_id);
|
||||||
|
}
|
||||||
|
else if (chatType === "chatTypeSupergroup" ) {
|
||||||
|
chatGroupInformation = tdLibWrapper.getSuperGroup(display.type.supergroup_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
visible = (chatGroupInformation.status["@type"] === "chatMemberStatusCreator"
|
||||||
|
|| chatGroupInformation.status["@type"] === "chatMemberStatusAdministrator"
|
||||||
|
|| (chatGroupInformation.status["@type"] === "chatMemberStatusMember"
|
||||||
|
&& chatSelectionPage.payload.neededPermissions.every(function(neededPermission){
|
||||||
|
return display.permissions[neededPermission];
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else { // future uses of chat selection can be processed here
|
||||||
|
visible = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
property bool valid: visibleLoader && visibleLoader.item && visibleLoader.item.visible
|
||||||
|
opacity: valid ? 1.0 : 0.5
|
||||||
|
|
||||||
|
Behavior on opacity { FadeAnimation {}}
|
||||||
|
Behavior on height { NumberAnimation {}}
|
||||||
|
|
||||||
|
// normal height while calculating, otherwise all elements get displayed at once
|
||||||
|
height: !visibleLoader.item || visible ? contentHeight : 0
|
||||||
|
enabled: valid
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var chat = tdLibWrapper.getChat(display.id);
|
var chat = tdLibWrapper.getChat(display.id);
|
||||||
switch(chatSelectionPage.state) {
|
switch(chatSelectionPage.state) {
|
||||||
|
|
Loading…
Reference in a new issue