summary refs log tree commit diff
path: root/src/timeline2/TimelineModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-09-11 00:54:40 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:14 +0100
commit62d0cd74da856028147ce222f3af9ad940b70a1b (patch)
tree5fd6e79fbb6a9f5d335d8bc8cff1b8ce31308be9 /src/timeline2/TimelineModel.cpp
parentImplement sending other message types in qml timeline (diff)
downloadnheko-62d0cd74da856028147ce222f3af9ad940b70a1b.tar.xz
Implement replies in qml timeline
Diffstat (limited to 'src/timeline2/TimelineModel.cpp')
-rw-r--r--src/timeline2/TimelineModel.cpp54
1 files changed, 54 insertions, 0 deletions
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 <QRegularExpression> +#include "ChatPage.h" #include "Logging.h" #include "Olm.h" #include "Utils.h" @@ -38,6 +39,33 @@ eventTimestamp(const T &event) } template<class T> +std::string +eventMsgType(const mtx::events::Event<T> &) +{ + return ""; +} +template<class T> +auto +eventMsgType(const mtx::events::RoomEvent<T> &e) -> decltype(e.content.msgtype) +{ + return e.content.msgtype; +} + +template<class T> +QString +eventBody(const mtx::events::Event<T> &) +{ + return QString(""); +} +template<class T> +auto +eventBody(const mtx::events::RoomEvent<T> &e) + -> std::enable_if_t<std::is_same<decltype(e.content.body), std::string>::value, QString> +{ + return QString::fromStdString(e.content.body); +} + +template<class T> QString eventFormattedBody(const mtx::events::Event<T> &) { @@ -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<mtx::events::msg:: .toStdString(); return {dummy, false}; } + +void +TimelineModel::replyAction(QString id) +{ + auto event = events.value(id); + RelatedInfo related = boost::apply_visitor( + [](const auto &ev) -> 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); +}