From 603ff33ea68b7c9e06578adf96fb6d824aa465df Mon Sep 17 00:00:00 2001 From: targetakhil Date: Sun, 11 Apr 2021 20:01:49 +0530 Subject: added basic forwarding --- src/timeline/TimelineModel.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 8e96cb3e..e3efe5ad 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -822,6 +822,16 @@ TimelineModel::viewRawMessage(QString id) const Q_UNUSED(dialog); } +void +TimelineModel::forwardMessage(QString eventId, QString roomId) +{ + auto e = events.get(eventId.toStdString(), ""); + if (!e) + return; + + emit forwardToRoom(e, roomId, cache::isRoomEncrypted(room_id_.toStdString())); +} + void TimelineModel::viewDecryptedRawMessage(QString id) const { -- cgit 1.5.1 From 6893e3a8d5cd30fc3e29dbf9160f258cb86b0cf0 Mon Sep 17 00:00:00 2001 From: targetakhil Date: Thu, 15 Apr 2021 21:14:58 +0530 Subject: 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(-) (limited to 'src/timeline/TimelineModel.cpp') 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(); -- cgit 1.5.1 From 99340047026b6980c14f83471dfa63369f8eae96 Mon Sep 17 00:00:00 2001 From: targetakhil Date: Thu, 15 Apr 2021 22:32:37 +0530 Subject: remove unused function and set position to center of timeline view --- resources/qml/ForwardCompleter.qml | 10 +++++++--- src/timeline/TimelineModel.cpp | 11 ----------- src/timeline/TimelineModel.h | 1 - 3 files changed, 7 insertions(+), 15 deletions(-) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/resources/qml/ForwardCompleter.qml b/resources/qml/ForwardCompleter.qml index 4cc2e09d..f85362c1 100644 --- a/resources/qml/ForwardCompleter.qml +++ b/resources/qml/ForwardCompleter.qml @@ -9,11 +9,12 @@ import im.nheko 1.0 Popup { id: forwardMessagePopup + + x: Math.round(parent.width / 2 - width / 2) + y: Math.round(parent.height / 2 - height / 2) + modal: true palette: colors parent: Overlay.overlay - modal: true - x: 400 - y: 200 width: implicitWidth >= 300 ? implicitWidth : 300 height: implicitHeight + completerPopup.height + padding * 2 @@ -37,10 +38,12 @@ Popup { Column { id: forwardColumn + spacing: 5 Label { id: titleLabel + text: qsTr("Forward Message") font.bold: true bottomPadding: 10 @@ -48,6 +51,7 @@ Popup { Reply { id: replyPreview + modelData: TimelineManager.timeline ? TimelineManager.timeline.getDump(mid, "") : { } userColor: TimelineManager.userColor(modelData.userId, colors.window) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 0edee4aa..e3efe5ad 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -832,17 +832,6 @@ 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 c17280da..3e6f6f15 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -220,7 +220,6 @@ 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(); -- cgit 1.5.1 From 06e12a0a16c8ded7deada5586a4772779f01dbe8 Mon Sep 17 00:00:00 2001 From: targetakhil Date: Sat, 17 Apr 2021 22:58:04 +0530 Subject: move detection code to nheko namespace and fix a few other bugs --- src/EventAccessors.cpp | 26 +--------- src/EventAccessors.h | 26 ++++++++++ src/timeline/TimelineModel.cpp | 2 +- src/timeline/TimelineModel.h | 4 +- src/timeline/TimelineViewManager.cpp | 99 +++++++++++++++++------------------- src/timeline/TimelineViewManager.h | 43 +++------------- 6 files changed, 83 insertions(+), 117 deletions(-) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/EventAccessors.cpp b/src/EventAccessors.cpp index cfc41a98..362bf4e9 100644 --- a/src/EventAccessors.cpp +++ b/src/EventAccessors.cpp @@ -11,32 +11,8 @@ #include namespace { -struct nonesuch -{ - ~nonesuch() = delete; - nonesuch(nonesuch const &) = delete; - void operator=(nonesuch const &) = delete; -}; - -namespace detail { -template class Op, class... Args> -struct detector -{ - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector>, Op, Args...> -{ - using value_t = std::true_type; - using type = Op; -}; - -} // namespace detail - template class Op, class... Args> -using is_detected = typename detail::detector::value_t; +using is_detected = typename nheko::detail::detector::value_t; struct IsStateEvent { diff --git a/src/EventAccessors.h b/src/EventAccessors.h index ced159c1..a58c7de0 100644 --- a/src/EventAccessors.h +++ b/src/EventAccessors.h @@ -11,6 +11,32 @@ #include +namespace nheko { +struct nonesuch +{ + ~nonesuch() = delete; + nonesuch(nonesuch const &) = delete; + void operator=(nonesuch const &) = delete; +}; + +namespace detail { +template class Op, class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +} // namespace detail +} + namespace mtx::accessors { std::string event_id(const mtx::events::collections::TimelineEvents &event); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index e3efe5ad..2e83b831 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -829,7 +829,7 @@ TimelineModel::forwardMessage(QString eventId, QString roomId) if (!e) return; - emit forwardToRoom(e, roomId, cache::isRoomEncrypted(room_id_.toStdString())); + emit forwardToRoom(e, roomId); } void diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 3e6f6f15..fbe963d2 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -323,9 +323,7 @@ signals: void roomNameChanged(); void roomTopicChanged(); void roomAvatarUrlChanged(); - void forwardToRoom(mtx::events::collections::TimelineEvents *e, - QString roomId, - bool sentFromEncrypted); + void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId); private: template diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index f71fd42b..a3d19950 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -621,68 +621,63 @@ TimelineViewManager::focusTimeline() void TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, - QString roomId, - bool sentFromEncrypted) + QString roomId) { - auto elem = *e; - auto room = models.find(roomId); - auto messageType = mtx::accessors::msg_type(elem); - auto content = mtx::accessors::url(elem); - - if (sentFromEncrypted) { - std::optional encryptionInfo = - mtx::accessors::file(elem); + auto elem = *e; + auto room = models.find(roomId); + auto content = mtx::accessors::url(elem); + std::optional encryptionInfo = mtx::accessors::file(elem); + if (encryptionInfo) { http::client()->download( content, [this, roomId, e, encryptionInfo](const std::string &res, - const std::string &content_type, - const std::string &originalFilename, - mtx::http::RequestErr err) { + const std::string &content_type, + const std::string &originalFilename, + mtx::http::RequestErr err) { if (err) { return; } - assert(encryptionInfo); - - auto data = mtx::crypto::to_string( - mtx::crypto::decrypt_file(res, encryptionInfo.value())); - - http::client()->upload( - data, - content_type, - originalFilename, - [this, roomId, e](const mtx::responses::ContentURI &res, - mtx::http::RequestErr err) mutable { - if (err) { - nhlog::net()->warn("failed to upload media: {} {} ({})", - err->matrix_error.error, - to_string(err->matrix_error.errcode), - static_cast(err->status_code)); - return; - } - - std::visit( - [this, roomId, e, url = res.content_uri](auto ev) { - if constexpr (mtx::events::message_content_to_type< - decltype(ev.content)> == - mtx::events::EventType::RoomMessage) { - if constexpr (messageWithFileAndUrl(ev)) { - ev.content.relations.relations.clear(); - ev.content.file.reset(); - ev.content.url = url; - - auto room = models.find(roomId); - room.value()->sendMessageEvent( - ev.content, - mtx::events::EventType::RoomMessage); - } - } - }, - *e); - }); + auto data = mtx::crypto::to_string( + mtx::crypto::decrypt_file(res, encryptionInfo.value())); + + http::client()->upload( + data, + content_type, + originalFilename, + [this, roomId, e](const mtx::responses::ContentURI &res, + mtx::http::RequestErr err) mutable { + if (err) { + nhlog::net()->warn("failed to upload media: {} {} ({})", + err->matrix_error.error, + to_string(err->matrix_error.errcode), + static_cast(err->status_code)); + return; + } + + std::visit( + [this, roomId, e, url = res.content_uri](auto ev) { + if constexpr (mtx::events::message_content_to_type< + decltype(ev.content)> == + mtx::events::EventType::RoomMessage) { + if constexpr (messageWithFileAndUrl(ev)) { + ev.content.relations.relations + .clear(); + ev.content.file.reset(); + ev.content.url = url; + } + + auto room = models.find(roomId); + room.value()->sendMessageEvent( + ev.content, + mtx::events::EventType::RoomMessage); + } + }, + *e); + }); - return; + return; }); return; diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 9d1b4b1d..e5dea7ce 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -32,33 +32,6 @@ class UserSettings; class ChatPage; class DeviceVerificationFlow; -struct nonesuch -{ - ~nonesuch() = delete; - nonesuch(nonesuch const &) = delete; - void operator=(nonesuch const &) = delete; -}; - -namespace detail { -template class Op, class... Args> -struct detector -{ - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector>, Op, Args...> -{ - using value_t = std::true_type; - using type = Op; -}; - -} // namespace detail - -template class Op, class... Args> -using is_detected = typename detail::detector::value_t; - class TimelineViewManager : public QObject { Q_OBJECT @@ -175,15 +148,17 @@ public slots: void backToRooms() { emit showRoomList(); } QObject *completerFor(QString completerName, QString roomId = ""); - void forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, - QString roomId, - bool sentFromEncrypted); + void forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, QString roomId); private slots: void openImageOverlayInternal(QString eventId, QImage img); private: - template + template class Op, class... Args> + using is_detected = + typename nheko::detail::detector::value_t; + + template using f_t = decltype(Content::file); template @@ -192,11 +167,7 @@ private: template static constexpr bool messageWithFileAndUrl(const mtx::events::Event &e) { - if constexpr (is_detected::value && is_detected::value) { - return true; - } - - return false; + return is_detected::value && is_detected::value; } private: -- cgit 1.5.1