diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 5c96ff18..4f10f352 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -95,6 +95,8 @@ Rectangle { source: replyButtonImg color: replyButton.hovered ? colors.highlight : colors.buttonText } + + onClicked: chat.model.replyAction(model.id) } Button { Layout.alignment: Qt.AlignRight | Qt.AlignTop diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index f544c83c..46a33add 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -5,6 +5,7 @@ #include +#include "ChatPage.h" #include "Logging.h" #include "Olm.h" #include "Utils.h" @@ -37,6 +38,33 @@ eventTimestamp(const T &event) return QDateTime::fromMSecsSinceEpoch(event.origin_server_ts); } +template +std::string +eventMsgType(const mtx::events::Event &) +{ + return ""; +} +template +auto +eventMsgType(const mtx::events::RoomEvent &e) -> decltype(e.content.msgtype) +{ + return e.content.msgtype; +} + +template +QString +eventBody(const mtx::events::Event &) +{ + return QString(""); +} +template +auto +eventBody(const mtx::events::RoomEvent &e) + -> std::enable_if_t::value, QString> +{ + return QString::fromStdString(e.content.body); +} + template QString eventFormattedBody(const mtx::events::Event &) @@ -293,6 +321,9 @@ TimelineModel::data(const QModelIndex &index, int role) const return QVariant(boost::apply_visitor( [](const auto &e) -> qml_mtx_events::EventType { return toRoomEventType(e); }, event)); + case Body: + return QVariant(utils::replaceEmoji(boost::apply_visitor( + [](const auto &e) -> QString { return eventBody(e); }, event))); case FormattedBody: return QVariant(utils::replaceEmoji(boost::apply_visitor( [](const auto &e) -> QString { return eventFormattedBody(e); }, event))); @@ -571,3 +602,26 @@ TimelineModel::decryptEvent(const mtx::events::EncryptedEvent RelatedInfo { + RelatedInfo related_ = {}; + related_.quoted_user = QString::fromStdString(ev.sender); + related_.related_event = ev.event_id; + return related_; + }, + event); + related.type = mtx::events::getMessageType(boost::apply_visitor( + [](const auto &e) -> std::string { return eventMsgType(e); }, event)); + related.quoted_body = + boost::apply_visitor([](const auto &e) -> QString { return eventBody(e); }, event); + + if (related.quoted_body.isEmpty()) + return; + + emit ChatPage::instance()->messageReply(related); +} diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index 59321119..b2481668 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -111,6 +111,7 @@ public: Q_INVOKABLE QString formatDateSeparator(QDate date) const; Q_INVOKABLE QString escapeEmoji(QString str) const; Q_INVOKABLE void viewRawMessage(QString id) const; + Q_INVOKABLE void replyAction(QString id); void addEvents(const mtx::responses::Timeline &events); template