1ee8d134bc
* Adapt setTdlibParameters for TdLib > 1.8.5 For some reason tdlibParameters were inlined between 1.8.5 and 1.8.6 See https://github.com/tdlib/td/commit/f6a2ecd * sponsoredMessage => sponsoredMessages in TdLib 1.8.8 See https://github.com/tdlib/td/commit/ec1310a * Support another variant of messageReaction The reaction field has changed from string to ReactionType somewhere between 1.8.5 and 1.8.6 See https://github.com/tdlib/td/commit/b14708f * Add support for new message reactions API It has changed between 1.8.5 and 1.8.6 https://github.com/tdlib/td/commit/b14708f (ReactionType) https://github.com/tdlib/td/commit/0b8e143 (ChatAvailableReactions) https://github.com/tdlib/td/commit/6b2f6b4 (addMessageReaction) https://github.com/tdlib/td/commit/d29d367 (updateActiveEmojiReactions) etc. * Highlight chosen reaction * Support username in the new format username attribute has been replaced with usernames in 1.8.8 and now looks like this: "usernames": { "@type": "usernames", "active_usernames": [ "whatever" ], "disabled_usernames": [ ], "editable_username": "whatever" } See https://github.com/tdlib/td/commit/897032e * Support new reply_to message attribute Since 1.8.15 it replaces reply_to_message_id and reply_in_chat_id. Looks like this: "reply_to": { "@type": "messageReplyToMessage", "chat_id": -1001234567890, "is_quote_manual": false, "message_id": 234567890, "origin_send_date": 0 }, See https://github.com/tdlib/td/commit/6116573 * Added support for MessageOrigin values All of a sudden MessageForwardOrigin has been renamed into MessageOrigin in TdLib 1.8.20 just because why not: https://github.com/tdlib/td/commit/10c9e40
232 lines
9 KiB
QML
232 lines
9 KiB
QML
/*
|
|
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 "./messageContent"
|
|
import "../js/functions.js" as Functions
|
|
import "../js/twemoji.js" as Emoji
|
|
import "../js/debug.js" as Debug
|
|
|
|
Flickable {
|
|
id: messageOverlayFlickable
|
|
anchors.fill: parent
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
contentHeight: messageContentColumn.height
|
|
clip: true
|
|
|
|
property var overlayMessage;
|
|
property bool showHeader: true
|
|
readonly property var userInformation: tdLibWrapper.getUserInformation(overlayMessage.sender_id.user_id);
|
|
readonly property bool isOwnMessage: tdLibWrapper.getUserInformation().id === overlayMessage.sender_id.user_id;
|
|
readonly property bool isAnonymous: overlayMessage.sender_id["@type"] === "messageSenderChat"
|
|
property bool hasContentComponent: overlayMessage.content && chatView.delegateMessagesContent.indexOf(overlayMessage.content['@type']) > -1
|
|
signal requestClose;
|
|
|
|
function getOriginalAuthor(forwardInformation, fontSize) {
|
|
switch (forwardInformation.origin["@type"]) {
|
|
case "messageOriginChannel":
|
|
case "messageForwardOriginChannel":
|
|
var otherChatInformation = tdLibWrapper.getChat(forwardInformation.origin.chat_id);
|
|
return Emoji.emojify(otherChatInformation.title, fontSize);
|
|
case "messageOriginUser":
|
|
case "messageForwardOriginUser":
|
|
var otherUserInformation = tdLibWrapper.getUserInformation(forwardInformation.origin.sender_id.user_id);
|
|
return Emoji.emojify(Functions.getUserName(otherUserInformation), fontSize);
|
|
default:
|
|
return Emoji.emojify(forwardInformation.origin.sender_name, fontSize);
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
delegateComponentLoadingTimer.start();
|
|
}
|
|
|
|
Timer {
|
|
id: delegateComponentLoadingTimer
|
|
interval: 500
|
|
repeat: false
|
|
running: false
|
|
onTriggered: {
|
|
if (messageOverlayFlickable.hasContentComponent) {
|
|
var type = overlayMessage.content["@type"];
|
|
overlayExtraContentLoader.setSource(
|
|
"../components/messageContent/" + type.charAt(0).toUpperCase() + type.substring(1) + ".qml",
|
|
{
|
|
overlayFlickable: messageOverlayFlickable
|
|
})
|
|
} else if(overlayMessage.content && overlayMessage.content.web_page) {
|
|
overlayWebPagePreviewLoader.active = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
id: messageContentBackground
|
|
color: Theme.overlayBackgroundColor
|
|
opacity: 0.7
|
|
width: parent.width
|
|
height: messageContentColumn.height >= messageOverlayFlickable.height ? messageContentColumn.height : messageOverlayFlickable.height
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
messageOverlayFlickable.requestClose();
|
|
}
|
|
}
|
|
}
|
|
|
|
Column {
|
|
id: messageContentColumn
|
|
spacing: Theme.paddingMedium
|
|
anchors.top: parent.top
|
|
anchors.topMargin: Theme.paddingMedium
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
width: parent.width - ( 2 * Theme.horizontalPageMargin )
|
|
|
|
Row {
|
|
visible: messageOverlayFlickable.showHeader
|
|
width: parent.width
|
|
spacing: Theme.paddingMedium
|
|
ProfileThumbnail {
|
|
id: overlayMessagePictureThumbnail
|
|
photoData: messageOverlayFlickable.isAnonymous ? ((typeof chatPage.chatInformation.photo !== "undefined") ? chatPage.chatInformation.photo.small : {}) : ((typeof messageOverlayFlickable.userInformation.profile_photo !== "undefined") ? messageOverlayFlickable.userInformation.profile_photo.small : ({}))
|
|
replacementStringHint: overlayMessageUserText.text
|
|
width: Theme.itemSizeLarge
|
|
height: Theme.itemSizeLarge
|
|
}
|
|
Label {
|
|
id: overlayMessageUserText
|
|
|
|
width: parent.width - overlayMessagePictureThumbnail.width
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: messageOverlayFlickable.isOwnMessage ? qsTr("You") : Emoji.emojify(messageOverlayFlickable.isAnonymous ? chatPage.chatInformation.title : Functions.getUserName(messageOverlayFlickable.userInformation), font.pixelSize)
|
|
font.pixelSize: Theme.fontSizeExtraLarge
|
|
font.weight: Font.ExtraBold
|
|
maximumLineCount: 1
|
|
truncationMode: TruncationMode.Fade
|
|
textFormat: Text.StyledText
|
|
}
|
|
}
|
|
|
|
MessageViaLabel {
|
|
message: overlayMessage
|
|
}
|
|
|
|
Text {
|
|
id: overlayForwardedInfoText
|
|
width: parent.width
|
|
visible: typeof overlayMessage.forward_info !== "undefined"
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
font.italic: true
|
|
textFormat: Text.StyledText
|
|
color: Theme.secondaryColor
|
|
wrapMode: Text.Wrap
|
|
text: visible ? qsTr("This message was forwarded. Original author: %1").arg(getOriginalAuthor(overlayMessage.forward_info, font.pixelSize)) : ""
|
|
}
|
|
|
|
Text {
|
|
id: overlayMessageText
|
|
width: parent.width
|
|
text: Emoji.emojify(Functions.getMessageText(overlayMessage, false, tdLibWrapper.getUserInformation().id, false), font.pixelSize)
|
|
font.pixelSize: Theme.fontSizeMedium
|
|
color: Theme.primaryColor
|
|
wrapMode: Text.Wrap
|
|
textFormat: Text.StyledText
|
|
onLinkActivated: {
|
|
Functions.handleLink(link);
|
|
}
|
|
linkColor: Theme.highlightColor
|
|
visible: (text !== "")
|
|
}
|
|
|
|
Loader {
|
|
id: overlayWebPagePreviewLoader
|
|
active: false
|
|
asynchronous: true
|
|
width: parent.width
|
|
|
|
sourceComponent: Component {
|
|
id: webPagePreviewComponent
|
|
WebPagePreview {
|
|
id: webPagePreview
|
|
|
|
onImplicitHeightChanged: {
|
|
overlayWebPagePreviewLoader.height = webPagePreview.implicitHeight;
|
|
}
|
|
|
|
webPageData: overlayMessage.content.web_page
|
|
largerFontSize: true
|
|
width: parent.width
|
|
}
|
|
}
|
|
}
|
|
|
|
Loader {
|
|
id: overlayExtraContentLoader
|
|
width: parent.width
|
|
asynchronous: true
|
|
}
|
|
|
|
Loader {
|
|
id: replyMarkupLoader
|
|
property var myMessage: overlayMessage
|
|
width: parent.width
|
|
height: active ? (overlayMessage.reply_markup.rows.length * (Theme.itemSizeSmall + Theme.paddingSmall) - Theme.paddingSmall) : 0
|
|
asynchronous: true
|
|
active: !!overlayMessage.reply_markup && myMessage.reply_markup.rows
|
|
source: Qt.resolvedUrl("ReplyMarkupButtons.qml")
|
|
}
|
|
|
|
Timer {
|
|
id: messageDateUpdater
|
|
interval: 60000
|
|
running: true
|
|
repeat: true
|
|
onTriggered: {
|
|
overlayMessageDateText.text = ( overlayMessageDateText.useElapsed ? Functions.getDateTimeElapsed(overlayMessage.date) : Functions.getDateTimeTranslated(overlayMessage.date) );
|
|
}
|
|
}
|
|
|
|
Text {
|
|
width: parent.width
|
|
|
|
property bool useElapsed: true
|
|
|
|
id: overlayMessageDateText
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
text: ( useElapsed ? Functions.getDateTimeElapsed(overlayMessage.date) : Functions.getDateTimeTranslated(overlayMessage.date) )
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: {
|
|
overlayMessageDateText.useElapsed = !overlayMessageDateText.useElapsed;
|
|
overlayMessageDateText.text = ( useElapsed ? Functions.getDateTimeElapsed(overlayMessage.date) : Functions.getDateTimeTranslated(overlayMessage.date) );
|
|
}
|
|
}
|
|
}
|
|
|
|
Label {
|
|
id: separatorLabel
|
|
width: parent.width
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
}
|
|
|
|
}
|
|
|
|
VerticalScrollDecorator {}
|
|
}
|