Display pinned message in chat

This commit is contained in:
Sebastian Wolf 2020-11-16 21:39:11 +01:00
parent f6b42eb3cb
commit 15be3862f6
14 changed files with 215 additions and 3 deletions

View file

@ -46,6 +46,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \
qml/components/LocationPreview.qml \
qml/components/MessageListViewItem.qml \
qml/components/MessageListViewItemSimple.qml \
qml/components/PinnedMessageItem.qml \
qml/components/PollPreview.qml \
qml/components/StickerPicker.qml \
qml/components/PhotoTextsListItem.qml \

View file

@ -0,0 +1,120 @@
/*
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
Item {
id: pinnedMessageItem
property var pinnedMessage;
onPinnedMessageChanged: {
if (pinnedMessage) {
console.log("[ChatPage] Activating pinned message");
pinnedMessageUserText.text = (pinnedMessage.sender_user_id !== chatPage.myUserId) ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(pinnedMessage.sender_user_id)), pinnedMessageUserText.font.pixelSize) : qsTr("You");
pinnedMessageText.text = Emoji.emojify(Functions.getMessageText(pinnedMessage, true, pinnedMessage.sender_user_id === chatPage.myUserId), pinnedMessageText.font.pixelSize);
pinnedMessageItem.visible = true;
} else {
pinnedMessageItem.visible = false;
}
}
visible: false
anchors.left: parent.left
anchors.right: parent.right
height: pinnedMessageRow.height
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: {
console.log("Opening pinned message");
}
}
Column {
id: pinnedMessageColumn
spacing: Theme.paddingSmall
width: parent.width - pinnedMessageButton.width - removePinnedMessageIconButton.width
anchors.verticalCenter: parent.verticalCenter
Text {
id: pinnedMessageUserText
width: parent.width
font.pixelSize: Theme.fontSizeExtraSmall
font.weight: Font.ExtraBold
color: Theme.primaryColor
maximumLineCount: 1
elide: Text.ElideRight
textFormat: Text.StyledText
horizontalAlignment: Text.AlignLeft
MouseArea {
anchors.fill: parent
onClicked: {
console.log("Opening pinned message");
}
}
}
Text {
id: pinnedMessageText
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.primaryColor
width: parent.width
elide: Text.ElideRight
maximumLineCount: 1
textFormat: Text.StyledText
MouseArea {
anchors.fill: parent
onClicked: {
console.log("Opening pinned message");
}
}
}
}
IconButton {
id: removePinnedMessageIconButton
icon.source: "image://theme/icon-m-clear"
anchors.verticalCenter: parent.verticalCenter
onClicked: {
pinnedMessage = undefined;
}
}
}
}

View file

@ -145,11 +145,15 @@ Page {
updateGroupStatusText();
}
if (stickerManager.needsReload()) {
console.log("Stickers will be reloaded!");
console.log("[ChatPage] Stickers will be reloaded!");
tdLibWrapper.getRecentStickers();
tdLibWrapper.getInstalledStickerSets();
stickerManager.setNeedsReload(false);
}
if (chatInformation.pinned_message_id.toString() !== "0") {
console.log("[ChatPage] Loading pinned message " + chatInformation.pinned_message_id);
tdLibWrapper.getMessage(chatInformation.id, chatInformation.pinned_message_id);
}
}
function getMessageStatusText(message, listItemIndex, lastReadSentIndex, useElapsed) {
@ -359,6 +363,12 @@ Page {
onErrorReceived: {
Functions.handleErrorMessage(code, message);
}
onReceivedMessage: {
if (messageId === chatInformation.pinned_message_id.toString()) {
console.log("[ChatPage] Received pinned message");
pinnedMessageItem.pinnedMessage = message;
}
}
}
Connections {
@ -535,6 +545,7 @@ Page {
}
}
}
Column {
id: chatColumn
width: parent.width
@ -589,10 +600,14 @@ Page {
}
}
PinnedMessageItem {
id: pinnedMessageItem
}
Item {
id: chatViewItem
width: parent.width
height: parent.height - headerRow.height - newMessageColumn.height - selectedMessagesActions.height
height: parent.height - headerRow.height - ( pinnedMessageItem.visible ? pinnedMessageItem.height : 0 ) - newMessageColumn.height - selectedMessagesActions.height
property int previousHeight;
@ -1256,7 +1271,6 @@ Page {
}
}
}
}
}

View file

@ -897,6 +897,13 @@
<translation>Sie haben noch keine Chats.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Sie</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -897,6 +897,13 @@
<translation>You don&apos;t have any chats yet.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">You</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -893,6 +893,13 @@
<translation>No hay todavía ninguna charla.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Usted</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -898,6 +898,13 @@
<translation>Sinulla ei ole vielä keskusteluja.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Sinä</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -893,6 +893,13 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Te</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -897,6 +897,13 @@
<translation>Carica lista chat...</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Tu</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -901,6 +901,13 @@
<translation>Nie masz jeszcze żadnych czatów.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Ty</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -901,6 +901,13 @@
<translation>Тут пока ничего нет</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Вы</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -897,6 +897,13 @@
<translation>Du har inga chattar än.</translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished">Du</translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -893,6 +893,13 @@
<translation></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>

View file

@ -893,6 +893,13 @@
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinnedMessageItem</name>
<message>
<source>You</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PollCreationPage</name>
<message>