From 6893e3a8d5cd30fc3e29dbf9160f258cb86b0cf0 Mon Sep 17 00:00:00 2001 From: targetakhil Date: Thu, 15 Apr 2021 21:14:58 +0530 Subject: [PATCH] show forward menu item only for relevant events, changes to ui --- resources/qml/ForwardCompleter.qml | 24 ++++++++++++++++++------ resources/qml/TimelineView.qml | 3 ++- src/timeline/TimelineModel.cpp | 11 +++++++++++ src/timeline/TimelineModel.h | 1 + 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/resources/qml/ForwardCompleter.qml b/resources/qml/ForwardCompleter.qml index 2b5e6dfe..22d6e5b0 100644 --- a/resources/qml/ForwardCompleter.qml +++ b/resources/qml/ForwardCompleter.qml @@ -2,16 +2,19 @@ // // SPDX-License-Identifier: GPL-3.0-or-later +import "./delegates/" import QtQuick 2.9 import QtQuick.Controls 2.3 import im.nheko 1.0 -Popup { +Dialog { id: forwardMessagePopup + title: qsTr("Forward Message") x: 400 y: 400 width: 200 + height: replyPreview.height + roomTextInput.height + completerPopup.height + implicitFooterHeight + implicitHeaderHeight property var mid @@ -24,19 +27,27 @@ Popup { completerPopup.close(); } - background: Rectangle { - border.color: "#444" - } - function setMessageEventId(mid_in) { mid = mid_in; } + Reply { + id: replyPreview + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + modelData: TimelineManager.timeline ? TimelineManager.timeline.getDump(mid, "") : { + } + userColor: TimelineManager.userColor(modelData.userId, colors.window) + } + MatrixTextField { id: roomTextInput width: forwardMessagePopup.width - forwardMessagePopup.leftPadding * 2 + anchors.top: replyPreview.bottom + color: colors.text onTextEdited: { completerPopup.completer.searchString = text; @@ -58,7 +69,8 @@ Popup { Completer { id: completerPopup - y: roomTextInput.height + roomTextInput.bottomPadding + y: replyPreview.height + roomTextInput.height + roomTextInput.bottomPadding + width: forwardMessagePopup.width - forwardMessagePopup.leftPadding * 2 completerName: "room" avatarHeight: 24 diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 6c75eb74..e08c8a1e 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -141,11 +141,12 @@ Page { } Platform.MenuItem { + visible: messageContextMenu.eventType == MtxEvent.ImageMessage || messageContextMenu.eventType == MtxEvent.VideoMessage || messageContextMenu.eventType == MtxEvent.AudioMessage || messageContextMenu.eventType == MtxEvent.FileMessage || messageContextMenu.eventType == MtxEvent.Sticker || messageContextMenu.eventType == MtxEvent.TextMessage|| messageContextMenu.eventType == MtxEvent.LocationMessage || messageContextMenu.eventType == MtxEvent.EmoteMessage || messageContextMenu.eventType == MtxEvent.NoticeMessage text: qsTr("Forward") onTriggered: { var forwardMess = forwardCompleterComponent.createObject(timelineRoot); + forwardMess.setMessageEventId(messageContextMenu.eventId); forwardMess.open(); - forwardMess.setMessageEventId(messageContextMenu.eventId) } } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index e3efe5ad..0edee4aa 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -832,6 +832,17 @@ TimelineModel::forwardMessage(QString eventId, QString roomId) emit forwardToRoom(e, roomId, cache::isRoomEncrypted(room_id_.toStdString())); } +QString +TimelineModel::messageContent(QString eventId) +{ + auto e = events.get(eventId.toStdString(), ""); + if (!e) + return ""; + + auto content = mtx::accessors::body(*e); + return QString::fromStdString(content); +} + void TimelineModel::viewDecryptedRawMessage(QString id) const { diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 3e6f6f15..c17280da 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -220,6 +220,7 @@ public: Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void forwardMessage(QString eventId, QString roomId); + Q_INVOKABLE QString messageContent(QString eventId); Q_INVOKABLE void viewDecryptedRawMessage(QString id) const; Q_INVOKABLE void openUserProfile(QString userid, bool global = false); Q_INVOKABLE void openRoomSettings();