2020-12-27 02:01:59 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2020 Sebastian J. Wolf and other contributors
|
|
|
|
|
|
|
|
This file is part of Fernschreiber.
|
|
|
|
|
|
|
|
Fernschreiber is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Fernschreiber is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
import QtQuick 2.6
|
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import "../js/twemoji.js" as Emoji
|
|
|
|
import "../js/functions.js" as Functions
|
|
|
|
import "../js/debug.js" as Debug
|
|
|
|
|
|
|
|
Column {
|
2021-01-10 04:06:41 +03:00
|
|
|
id: replyMarkupButtons
|
2020-12-27 02:01:59 +03:00
|
|
|
width: parent.width
|
|
|
|
height: childrenRect.height
|
|
|
|
spacing: Theme.paddingSmall
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
model: myMessage.reply_markup.rows
|
|
|
|
delegate: Row {
|
|
|
|
width: parent.width
|
|
|
|
height: Theme.itemSizeSmall
|
|
|
|
spacing: Theme.paddingSmall
|
|
|
|
Repeater {
|
|
|
|
id: buttonsRepeater
|
|
|
|
model: modelData
|
2021-01-10 04:06:41 +03:00
|
|
|
property int itemWidth: replyMarkupButtons.width / count
|
2020-12-27 02:01:59 +03:00
|
|
|
delegate: MouseArea {
|
|
|
|
/*
|
|
|
|
Unimplemented callback types:
|
|
|
|
inlineKeyboardButtonTypeBuy
|
|
|
|
inlineKeyboardButtonTypeCallbackGame
|
|
|
|
inlineKeyboardButtonTypeCallbackWithPassword
|
|
|
|
inlineKeyboardButtonTypeLoginUrl
|
|
|
|
inlineKeyboardButtonTypeSwitchInline
|
|
|
|
*/
|
|
|
|
property var callbacks: ({
|
|
|
|
inlineKeyboardButtonTypeCallback: function(){
|
2021-01-10 04:06:41 +03:00
|
|
|
tdLibWrapper.getCallbackQueryAnswer(myMessage.chat_id, myMessage.id, {data: modelData.type.data, "@type": "callbackQueryPayloadData"})
|
2020-12-27 02:01:59 +03:00
|
|
|
},
|
2021-01-10 04:06:41 +03:00
|
|
|
|
|
|
|
inlineKeyboardButtonTypeCallbackGame: function(){
|
|
|
|
tdLibWrapper.getCallbackQueryAnswer(myMessage.chat_id, myMessage.id, {game_short_name: myMessage.content.game.short_name, "@type": "callbackQueryPayloadGame"})
|
|
|
|
},
|
2020-12-27 02:01:59 +03:00
|
|
|
inlineKeyboardButtonTypeUrl: function() {
|
|
|
|
Functions.handleLink(modelData.type.url);
|
2021-01-10 04:06:41 +03:00
|
|
|
},
|
|
|
|
inlineKeyboardButtonTypeSwitchInline: function() {
|
|
|
|
if(modelData.type.in_current_chat) {
|
2023-11-19 23:49:00 +03:00
|
|
|
chatPage.setMessageText("@" + userInformation.usernames.editable_username + " "+(modelData.type.query || ""))
|
2021-01-10 04:06:41 +03:00
|
|
|
} else {
|
|
|
|
|
|
|
|
pageStack.push(Qt.resolvedUrl("../pages/ChatSelectionPage.qml"), {
|
|
|
|
myUserId: chatPage.myUserId,
|
2023-11-19 23:49:00 +03:00
|
|
|
payload: { neededPermissions: ["can_send_other_messages"], text:"@" + userInformation.usernames.editable_username + " "+(modelData.type.query || "")},
|
2021-01-10 04:06:41 +03:00
|
|
|
state: "fillTextArea"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
keyboardButtonTypeText: function() {
|
|
|
|
chatPage.setMessageText(modelData.text, true);
|
2020-12-27 02:01:59 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
enabled: !!callbacks[modelData.type["@type"]]
|
|
|
|
height: Theme.itemSizeSmall
|
2021-01-10 04:06:41 +03:00
|
|
|
width: (replyMarkupButtons.width + Theme.paddingSmall) / buttonsRepeater.count - (Theme.paddingSmall)
|
2020-12-27 02:01:59 +03:00
|
|
|
onClicked: {
|
|
|
|
callbacks[modelData.type["@type"]]();
|
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
|
|
|
radius: Theme.paddingSmall
|
|
|
|
color: parent.pressed ? Theme.rgba(Theme.highlightBackgroundColor, Theme.highlightBackgroundOpacity)
|
|
|
|
: Theme.rgba(Theme.primaryColor, Theme.opacityFaint)
|
|
|
|
opacity: parent.enabled ? 1.0 : Theme.opacityLow
|
|
|
|
|
|
|
|
Label {
|
|
|
|
width: Math.min(parent.width - Theme.paddingSmall*2, contentWidth)
|
|
|
|
truncationMode: TruncationMode.Fade
|
|
|
|
text: Emoji.emojify(modelData.text, Theme.fontSizeSmall)
|
2021-01-10 04:06:41 +03:00
|
|
|
color: parent.parent.pressed ? Theme.highlightColor : Theme.primaryColor
|
2020-12-27 02:01:59 +03:00
|
|
|
anchors.centerIn: parent
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
}
|
|
|
|
Icon {
|
|
|
|
property var sources: ({
|
|
|
|
inlineKeyboardButtonTypeUrl: "../../images/icon-s-link.svg",
|
2021-01-10 04:06:41 +03:00
|
|
|
inlineKeyboardButtonTypeSwitchInline: !modelData.type.in_current_chat ? "image://theme/icon-s-repost" : "image://theme/icon-s-edit",
|
2020-12-27 02:01:59 +03:00
|
|
|
inlineKeyboardButtonTypeCallbackWithPassword: "image://theme/icon-s-asterisk"
|
|
|
|
})
|
|
|
|
visible: !!sources[modelData.type["@type"]]
|
2021-01-10 04:06:41 +03:00
|
|
|
opacity: 0.6
|
2020-12-27 02:01:59 +03:00
|
|
|
source: sources[modelData.type["@type"]] || ""
|
|
|
|
sourceSize: Qt.size(Theme.iconSizeSmall, Theme.iconSizeSmall)
|
|
|
|
highlighted: parent.pressed
|
|
|
|
anchors {
|
|
|
|
right: parent.right
|
|
|
|
top: parent.top
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|