2020-11-17 14:18:46 +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
|
2021-01-15 12:55:34 +03:00
|
|
|
import "./messageContent"
|
2020-11-17 14:18:46 +03:00
|
|
|
import "../js/functions.js" as Functions
|
|
|
|
import "../js/twemoji.js" as Emoji
|
2021-01-10 04:06:41 +03:00
|
|
|
import "../js/debug.js" as Debug
|
2020-11-17 14:18:46 +03:00
|
|
|
|
|
|
|
Flickable {
|
|
|
|
id: messageOverlayFlickable
|
|
|
|
anchors.fill: parent
|
|
|
|
boundsBehavior: Flickable.StopAtBounds
|
|
|
|
contentHeight: messageContentColumn.height
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
property var overlayMessage;
|
|
|
|
property bool showHeader: true
|
2022-01-07 21:18:04 +03:00
|
|
|
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"
|
2021-01-15 12:55:34 +03:00
|
|
|
property bool hasContentComponent: overlayMessage.content && chatView.delegateMessagesContent.indexOf(overlayMessage.content['@type']) > -1
|
2020-11-17 14:18:46 +03:00
|
|
|
signal requestClose;
|
|
|
|
|
|
|
|
function getOriginalAuthor(forwardInformation, fontSize) {
|
2020-11-18 16:22:08 +03:00
|
|
|
switch (forwardInformation.origin["@type"]) {
|
2023-11-18 16:45:22 +03:00
|
|
|
case "messageOriginChannel":
|
2020-11-18 16:22:08 +03:00
|
|
|
case "messageForwardOriginChannel":
|
|
|
|
var otherChatInformation = tdLibWrapper.getChat(forwardInformation.origin.chat_id);
|
|
|
|
return Emoji.emojify(otherChatInformation.title, fontSize);
|
2023-11-18 16:45:22 +03:00
|
|
|
case "messageOriginUser":
|
2020-11-18 16:22:08 +03:00
|
|
|
case "messageForwardOriginUser":
|
2022-01-07 21:18:04 +03:00
|
|
|
var otherUserInformation = tdLibWrapper.getUserInformation(forwardInformation.origin.sender_id.user_id);
|
2020-11-18 16:22:08 +03:00
|
|
|
return Emoji.emojify(Functions.getUserName(otherUserInformation), fontSize);
|
|
|
|
default:
|
|
|
|
return Emoji.emojify(forwardInformation.origin.sender_name, fontSize);
|
2020-11-17 14:18:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
delegateComponentLoadingTimer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: delegateComponentLoadingTimer
|
|
|
|
interval: 500
|
|
|
|
repeat: false
|
|
|
|
running: false
|
|
|
|
onTriggered: {
|
2021-01-15 12:55:34 +03:00
|
|
|
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;
|
2020-11-17 14:18:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: messageContentBackground
|
2020-11-18 16:22:08 +03:00
|
|
|
color: Theme.overlayBackgroundColor
|
|
|
|
opacity: 0.7
|
2020-11-17 14:18:46 +03:00
|
|
|
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
|
2020-12-25 15:50:13 +03:00
|
|
|
photoData: messageOverlayFlickable.isAnonymous ? ((typeof chatPage.chatInformation.photo !== "undefined") ? chatPage.chatInformation.photo.small : {}) : ((typeof messageOverlayFlickable.userInformation.profile_photo !== "undefined") ? messageOverlayFlickable.userInformation.profile_photo.small : ({}))
|
2020-11-17 14:18:46 +03:00
|
|
|
replacementStringHint: overlayMessageUserText.text
|
|
|
|
width: Theme.itemSizeLarge
|
|
|
|
height: Theme.itemSizeLarge
|
|
|
|
}
|
2020-11-22 02:39:49 +03:00
|
|
|
Label {
|
2020-11-17 14:18:46 +03:00
|
|
|
id: overlayMessageUserText
|
|
|
|
|
|
|
|
width: parent.width - overlayMessagePictureThumbnail.width
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-12-25 15:50:13 +03:00
|
|
|
text: messageOverlayFlickable.isOwnMessage ? qsTr("You") : Emoji.emojify(messageOverlayFlickable.isAnonymous ? chatPage.chatInformation.title : Functions.getUserName(messageOverlayFlickable.userInformation), font.pixelSize)
|
2020-11-17 14:18:46 +03:00
|
|
|
font.pixelSize: Theme.fontSizeExtraLarge
|
|
|
|
font.weight: Font.ExtraBold
|
|
|
|
maximumLineCount: 1
|
2020-11-22 02:39:49 +03:00
|
|
|
truncationMode: TruncationMode.Fade
|
2020-11-17 14:18:46 +03:00
|
|
|
textFormat: Text.StyledText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-10 04:06:41 +03:00
|
|
|
MessageViaLabel {
|
|
|
|
message: overlayMessage
|
|
|
|
}
|
|
|
|
|
2020-11-17 14:18:46 +03:00
|
|
|
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
|
2020-12-29 18:32:39 +03:00
|
|
|
text: Emoji.emojify(Functions.getMessageText(overlayMessage, false, tdLibWrapper.getUserInformation().id, false), font.pixelSize)
|
2020-11-17 14:18:46 +03:00
|
|
|
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: {
|
2020-11-23 10:27:56 +03:00
|
|
|
overlayWebPagePreviewLoader.height = webPagePreview.implicitHeight;
|
2020-11-17 14:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
webPageData: overlayMessage.content.web_page
|
|
|
|
largerFontSize: true
|
|
|
|
width: parent.width
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:18:22 +03:00
|
|
|
Loader {
|
|
|
|
id: overlayExtraContentLoader
|
|
|
|
width: parent.width
|
|
|
|
asynchronous: true
|
|
|
|
}
|
|
|
|
|
2021-01-10 04:06:41 +03:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:18:22 +03:00
|
|
|
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) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 14:18:46 +03:00
|
|
|
Label {
|
|
|
|
id: separatorLabel
|
|
|
|
width: parent.width
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
VerticalScrollDecorator {}
|
|
|
|
}
|