2020-11-16 23:39:11 +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 "../components"
|
|
|
|
import "../js/functions.js" as Functions
|
|
|
|
import "../js/twemoji.js" as Emoji
|
2020-11-20 23:58:26 +03:00
|
|
|
import "../js/debug.js" as Debug
|
2020-11-16 23:39:11 +03:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: pinnedMessageItem
|
|
|
|
|
|
|
|
property var pinnedMessage;
|
2020-11-17 14:18:46 +03:00
|
|
|
signal requestShowMessage;
|
2020-11-18 16:22:08 +03:00
|
|
|
signal requestCloseMessage;
|
2020-11-16 23:39:11 +03:00
|
|
|
|
|
|
|
onPinnedMessageChanged: {
|
|
|
|
if (pinnedMessage) {
|
2020-11-20 23:58:26 +03:00
|
|
|
Debug.log("[ChatPage] Activating pinned message");
|
2022-01-07 21:18:04 +03:00
|
|
|
var messageUserText = (pinnedMessage.sender_id.user_id !== chatPage.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(pinnedMessage.sender_id.user_id)), pinnedMessageUserText.font.pixelSize) : qsTr("You");
|
2020-11-17 14:18:46 +03:00
|
|
|
pinnedMessageUserText.text = (messageUserText === "" ? qsTr("Pinned Message") : messageUserText );
|
2020-12-29 18:32:39 +03:00
|
|
|
pinnedMessageText.text = Emoji.emojify(Functions.getMessageText(pinnedMessage, true, chatPage.myUserId, false), pinnedMessageText.font.pixelSize);
|
2020-11-16 23:39:11 +03:00
|
|
|
pinnedMessageItem.visible = true;
|
|
|
|
} else {
|
|
|
|
pinnedMessageItem.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
visible: false
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2020-11-18 16:22:08 +03:00
|
|
|
height: visible ? pinnedMessageRow.height : 0
|
2020-11-16 23:39:11 +03:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: pinnedMessageBackground
|
|
|
|
anchors.fill: parent
|
|
|
|
opacity: 0.1
|
|
|
|
color: Theme.secondaryColor
|
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
id: pinnedMessageRow
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
IconButton {
|
|
|
|
id: pinnedMessageButton
|
|
|
|
width: Theme.itemSizeLarge
|
|
|
|
height: Theme.itemSizeLarge
|
|
|
|
icon.source: "image://theme/icon-m-mark-unread"
|
|
|
|
onClicked: {
|
2020-11-17 14:18:46 +03:00
|
|
|
pinnedMessageItem.requestShowMessage();
|
2020-11-16 23:39:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 22:25:57 +03:00
|
|
|
Item {
|
2020-11-18 16:22:08 +03:00
|
|
|
width: parent.width - pinnedMessageButton.width - unpinMessageIconLoader.width - removePinnedMessageIconButton.width
|
2020-11-17 22:25:57 +03:00
|
|
|
height: pinnedMessageColumn.height
|
2020-11-16 23:39:11 +03:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-11-17 22:25:57 +03:00
|
|
|
Column {
|
|
|
|
id: pinnedMessageColumn
|
|
|
|
spacing: Theme.paddingSmall
|
2020-11-16 23:39:11 +03:00
|
|
|
width: parent.width
|
2020-11-17 22:25:57 +03:00
|
|
|
|
2020-11-22 02:39:49 +03:00
|
|
|
Label {
|
2020-11-17 22:25:57 +03:00
|
|
|
id: pinnedMessageUserText
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
|
|
font.weight: Font.ExtraBold
|
|
|
|
color: Theme.primaryColor
|
|
|
|
maximumLineCount: 1
|
2020-11-22 02:39:49 +03:00
|
|
|
truncationMode: TruncationMode.Fade
|
2020-11-17 22:25:57 +03:00
|
|
|
textFormat: Text.StyledText
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
2020-11-16 23:39:11 +03:00
|
|
|
}
|
|
|
|
|
2020-11-22 02:39:49 +03:00
|
|
|
Label {
|
2020-11-17 22:25:57 +03:00
|
|
|
id: pinnedMessageText
|
2020-11-16 23:39:11 +03:00
|
|
|
|
2020-11-17 22:25:57 +03:00
|
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
|
|
color: Theme.primaryColor
|
|
|
|
width: parent.width
|
2020-11-22 02:39:49 +03:00
|
|
|
truncationMode: TruncationMode.Fade
|
2020-11-17 22:25:57 +03:00
|
|
|
maximumLineCount: 1
|
|
|
|
textFormat: Text.StyledText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
pinnedMessageItem.requestShowMessage();
|
2020-11-16 23:39:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-18 16:22:08 +03:00
|
|
|
Loader {
|
|
|
|
id: unpinMessageIconLoader
|
|
|
|
asynchronous: true
|
|
|
|
active: canPinMessages()
|
|
|
|
Behavior on opacity { FadeAnimation {} }
|
|
|
|
width: active ? item.width : 0
|
|
|
|
height: active ? item.height : 0
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
sourceComponent: Component {
|
|
|
|
IconButton {
|
|
|
|
id: unpinMessageIconButton
|
|
|
|
icon.source: "image://theme/icon-m-remove"
|
|
|
|
onClicked: {
|
2020-12-26 00:38:13 +03:00
|
|
|
Remorse.itemAction(pinnedMessageRow, qsTr("Message unpinned"), function() { tdLibWrapper.unpinMessage(chatPage.chatInformation.id, pinnedMessage.id);
|
2020-11-18 16:22:08 +03:00
|
|
|
pinnedMessageItem.requestCloseMessage(); });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 23:39:11 +03:00
|
|
|
IconButton {
|
|
|
|
id: removePinnedMessageIconButton
|
|
|
|
icon.source: "image://theme/icon-m-clear"
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
onClicked: {
|
2020-11-18 16:22:08 +03:00
|
|
|
pinnedMessageItem.requestCloseMessage();
|
2020-11-16 23:39:11 +03:00
|
|
|
pinnedMessage = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|