summary refs log tree commit diff
path: root/src/timeline/TimelineItem.cpp
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-12 16:27:25 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-12 16:27:25 +0300
commite9ee29978d60f9fb5e661c5a02f33d8e3ad3655f (patch)
treed7c81724211a2f1dd414efd07bf635082ee9f288 /src/timeline/TimelineItem.cpp
parentMove some info logs to debug (diff)
downloadnheko-e9ee29978d60f9fb5e661c5a02f33d8e3ad3655f.tar.xz
Add context menu option to show the raw message
fixes #437
Diffstat (limited to 'src/timeline/TimelineItem.cpp')
-rw-r--r--src/timeline/TimelineItem.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp

index 8f44b7e8..5bec4458 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp
@@ -34,6 +34,8 @@ #include "timeline/widgets/ImageItem.h" #include "timeline/widgets/VideoItem.h" +#include "dialogs/RawMessage.h" + constexpr int MSG_RIGHT_MARGIN = 7; constexpr int MSG_PADDING = 20; @@ -185,8 +187,10 @@ TimelineItem::init() contextMenu_ = new QMenu(this); showReadReceipts_ = new QAction("Read receipts", this); markAsRead_ = new QAction("Mark as read", this); + viewRawMessage_ = new QAction("View raw message", this); redactMsg_ = new QAction("Redact message", this); contextMenu_->addAction(showReadReceipts_); + contextMenu_->addAction(viewRawMessage_); contextMenu_->addAction(markAsRead_); contextMenu_->addAction(redactMsg_); @@ -218,7 +222,8 @@ TimelineItem::init() }); }); - connect(markAsRead_, &QAction::triggered, this, [this]() { sendReadReceipt(); }); + connect(markAsRead_, &QAction::triggered, this, &TimelineItem::sendReadReceipt); + connect(viewRawMessage_, &QAction::triggered, this, &TimelineItem::openRawMessageViewer); topLayout_ = new QHBoxLayout(this); mainLayout_ = new QVBoxLayout; @@ -816,3 +821,37 @@ TimelineItem::sendReadReceipt() const } }); } + +void +TimelineItem::openRawMessageViewer() const +{ + const auto event_id = event_id_.toStdString(); + const auto room_id = room_id_.toStdString(); + + auto proxy = std::make_shared<EventProxy>(); + connect(proxy.get(), &EventProxy::eventRetrieved, this, [](const nlohmann::json &obj) { + auto dialog = new dialogs::RawMessage{QString::fromStdString(obj.dump(4))}; + Q_UNUSED(dialog); + }); + + http::client()->get_event( + room_id, + event_id, + [event_id, room_id, proxy = std::move(proxy)]( + const mtx::events::collections::TimelineEvents &res, mtx::http::RequestErr err) { + using namespace mtx::events; + + if (err) { + nhlog::net()->warn( + "failed to retrieve event {} from {}", event_id, room_id); + return; + } + + try { + emit proxy->eventRetrieved(utils::serialize_event(res)); + } catch (const nlohmann::json::exception &e) { + nhlog::net()->warn( + "failed to serialize event ({}, {})", room_id, event_id); + } + }); +}