Merge pull request #169 from jgibbon/bugfix/message-permissions
Bugfix/message permissions
This commit is contained in:
commit
f6b42eb3cb
4 changed files with 116 additions and 16 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 && neededPermissions.length < 3; 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
|
||||||
|
}
|
||||||
|
|
|
@ -108,6 +108,9 @@ Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateGroupStatusText() {
|
function updateGroupStatusText() {
|
||||||
|
if(chatPage.state === "selectMessages") {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (chatOnlineMemberCount > 0) {
|
if (chatOnlineMemberCount > 0) {
|
||||||
chatStatusText.text = qsTr("%1 members, %2 online").arg(Functions.getShortenedCount(chatGroupInformation.member_count)).arg(Functions.getShortenedCount(chatOnlineMemberCount));
|
chatStatusText.text = qsTr("%1 members, %2 online").arg(Functions.getShortenedCount(chatGroupInformation.member_count)).arg(Functions.getShortenedCount(chatOnlineMemberCount));
|
||||||
} else {
|
} else {
|
||||||
|
@ -266,6 +269,16 @@ Page {
|
||||||
forwardMessagesTimer.messageIds = messageIds;
|
forwardMessagesTimer.messageIds = messageIds;
|
||||||
forwardMessagesTimer.start();
|
forwardMessagesTimer.start();
|
||||||
}
|
}
|
||||||
|
function hasSendPrivilege(privilege) {
|
||||||
|
var groupStatus = chatGroupInformation ? chatGroupInformation.status : null
|
||||||
|
var groupStatusType = groupStatus ? groupStatus["@type"] : null
|
||||||
|
return chatPage.isPrivateChat
|
||||||
|
|| (groupStatusType === "chatMemberStatusMember" && chatInformation.permissions[privilege])
|
||||||
|
|| groupStatusType === "chatMemberStatusAdministrator"
|
||||||
|
|| groupStatusType === "chatMemberStatusCreator"
|
||||||
|
|| (groupStatusType === "chatMemberStatusRestricted" && groupStatus.permissions[privilege])
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: forwardMessagesTimer
|
id: forwardMessagesTimer
|
||||||
interval: 200
|
interval: 200
|
||||||
|
@ -824,7 +837,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 {} }
|
||||||
|
|
||||||
|
@ -861,7 +874,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");
|
||||||
|
@ -876,7 +889,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");
|
||||||
|
@ -891,7 +904,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");
|
||||||
|
@ -907,6 +920,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
|
||||||
|
@ -919,10 +934,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});
|
||||||
|
@ -1200,21 +1212,21 @@ Page {
|
||||||
leftMargin: visible ? Theme.paddingSmall : 0
|
leftMargin: visible ? Theme.paddingSmall : 0
|
||||||
verticalCenter: parent.verticalCenter
|
verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
visible: chatPage.chatInformation.can_be_forwarded && selectedMessages.every(function(message){
|
visible: selectedMessages.every(function(message){
|
||||||
return message.can_be_forwarded
|
return message.can_be_forwarded
|
||||||
})
|
})
|
||||||
width: visible ? Theme.itemSizeMedium : 0
|
width: visible ? Theme.itemSizeMedium : 0
|
||||||
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"), {
|
||||||
|
myUserId: chatPage.myUserId,
|
||||||
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"
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,13 @@ Dialog {
|
||||||
canAccept: false
|
canAccept: false
|
||||||
acceptDestinationAction: PageStackAction.Replace
|
acceptDestinationAction: PageStackAction.Replace
|
||||||
acceptDestinationReplaceTarget: pageStack.find( function(page){ return(page._depth === 0)} )
|
acceptDestinationReplaceTarget: pageStack.find( function(page){ return(page._depth === 0)} )
|
||||||
|
property int myUserId: tdLibWrapper.getUserInformation().id
|
||||||
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 +43,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +67,61 @@ Dialog {
|
||||||
|
|
||||||
model: chatListModel
|
model: chatListModel
|
||||||
delegate: ChatListViewItem {
|
delegate: ChatListViewItem {
|
||||||
ownUserId: overviewPage.ownUserId
|
ownUserId: chatSelectionPage.myUserId
|
||||||
|
Loader { // checking permissions takes a while, so we defer those calculations
|
||||||
|
id: visibleLoader
|
||||||
|
asynchronous: true
|
||||||
|
sourceComponent: Component {
|
||||||
|
QtObject {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
else if (chatType === "chatTypeBasicGroup" ) {
|
||||||
|
chatGroupInformation = tdLibWrapper.getBasicGroup(display.type.basic_group_id)
|
||||||
|
}
|
||||||
|
else if (chatType === "chatTypeSupergroup" ) {
|
||||||
|
chatGroupInformation = tdLibWrapper.getSuperGroup(display.type.supergroup_id)
|
||||||
|
}
|
||||||
|
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 groupPermissions[neededPermission]
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|| (groupStatusType === "chatMemberStatusRestricted"
|
||||||
|
&& chatSelectionPage.payload.neededPermissions.every(function(neededPermission){
|
||||||
|
return groupStatusPermissions[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
|
||||||
|
|
||||||
|
Behavior on opacity { FadeAnimation {}}
|
||||||
|
Behavior on height { NumberAnimation {}}
|
||||||
|
|
||||||
|
// normal height while calculating, otherwise all elements get displayed at once
|
||||||
|
height: !visibleLoader.item || valid ? contentHeight : 0
|
||||||
|
enabled: valid
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var chat = tdLibWrapper.getChat(display.id);
|
var chat = tdLibWrapper.getChat(display.id);
|
||||||
switch(chatSelectionPage.state) {
|
switch(chatSelectionPage.state) {
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "processlauncher.h"
|
#include "processlauncher.h"
|
||||||
#include "stickermanager.h"
|
#include "stickermanager.h"
|
||||||
#include "tgsplugin.h"
|
#include "tgsplugin.h"
|
||||||
|
#include "fernschreiberutils.h"
|
||||||
|
|
||||||
Q_IMPORT_PLUGIN(TgsIOPlugin)
|
Q_IMPORT_PLUGIN(TgsIOPlugin)
|
||||||
|
|
||||||
|
@ -60,6 +61,9 @@ int main(int argc, char *argv[])
|
||||||
context->setContextProperty("tdLibWrapper", tdLibWrapper);
|
context->setContextProperty("tdLibWrapper", tdLibWrapper);
|
||||||
qmlRegisterUncreatableType<TDLibWrapper>(uri, 1, 0, "TelegramAPI", QString());
|
qmlRegisterUncreatableType<TDLibWrapper>(uri, 1, 0, "TelegramAPI", QString());
|
||||||
|
|
||||||
|
FernschreiberUtils *fernschreiberUtils = new FernschreiberUtils(view.data());
|
||||||
|
context->setContextProperty("fernschreiberUtils", fernschreiberUtils);
|
||||||
|
|
||||||
DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor();
|
DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor();
|
||||||
context->setContextProperty("dBusAdaptor", dBusAdaptor);
|
context->setContextProperty("dBusAdaptor", dBusAdaptor);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue