summary refs log tree commit diff
path: root/src/timeline2/TimelineModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-11-05 17:16:04 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:15 +0100
commit1268e9f11c22e8cd22302342e80daef94b15001d (patch)
tree3b987792c989836f422ecbbe4ad05ea05c47cb42 /src/timeline2/TimelineModel.cpp
parentEnable link handling (diff)
downloadnheko-1268e9f11c22e8cd22302342e80daef94b15001d.tar.xz
Make replies format nicer
Also lays a bit of groundwork for better reply rendering
Diffstat (limited to 'src/timeline2/TimelineModel.cpp')
-rw-r--r--src/timeline2/TimelineModel.cpp44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp

index bdb3ea6f..b2b6f803 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp
@@ -13,6 +13,8 @@ #include "Utils.h" #include "dialogs/RawMessage.h" +Q_DECLARE_METATYPE(QModelIndex) + namespace { template<class T> QString @@ -80,12 +82,6 @@ eventFormattedBody(const mtx::events::RoomEvent<T> &e) { auto temp = e.content.formatted_body; if (!temp.empty()) { - auto pos = temp.find("<mx-reply>"); - if (pos != std::string::npos) - temp.erase(pos, std::string("<mx-reply>").size()); - pos = temp.find("</mx-reply>"); - if (pos != std::string::npos) - temp.erase(pos, std::string("</mx-reply>").size()); return QString::fromStdString(temp); } else { return QString::fromStdString(e.content.body).toHtmlEscaped().replace("\n", "<br>"); @@ -183,6 +179,21 @@ eventMimeType(const mtx::events::RoomEvent<T> &e) } template<class T> +QString +eventRelatesTo(const mtx::events::Event<T> &) +{ + return QString(); +} +template<class T> +auto +eventRelatesTo(const mtx::events::RoomEvent<T> &e) -> std::enable_if_t< + std::is_same<decltype(e.content.relates_to.in_reply_to.event_id), std::string>::value, + QString> +{ + return QString::fromStdString(e.content.relates_to.in_reply_to.event_id); +} + +template<class T> qml_mtx_events::EventType toRoomEventType(const mtx::events::Event<T> &e) { @@ -383,6 +394,7 @@ TimelineModel::roleNames() const {Id, "id"}, {State, "state"}, {IsEncrypted, "isEncrypted"}, + {ReplyTo, "replyTo"}, }; } int @@ -450,8 +462,12 @@ TimelineModel::data(const QModelIndex &index, int role) const 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))); + return QVariant( + utils::replaceEmoji( + boost::apply_visitor( + [](const auto &e) -> QString { return eventFormattedBody(e); }, event)) + .remove("<mx-reply>") + .remove("</mx-reply>")); case Url: return QVariant(boost::apply_visitor( [](const auto &e) -> QString { return eventUrl(e); }, event)); @@ -501,6 +517,11 @@ TimelineModel::data(const QModelIndex &index, int role) const return boost::get<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( &tempEvent) != nullptr; } + case ReplyTo: { + QString evId = boost::apply_visitor( + [](const auto &e) -> QString { return eventRelatesTo(e); }, event); + return QVariant(evId); + } default: return QVariant(); } @@ -825,8 +846,11 @@ TimelineModel::replyAction(QString id) 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); + related.quoted_body = boost::apply_visitor( + [](const auto &e) -> QString { return eventFormattedBody(e); }, event); + related.quoted_body.remove(QRegularExpression( + "<mx-reply>.*</mx-reply>", QRegularExpression::DotMatchesEverythingOption)); + nhlog::ui()->debug("after replacement: {}", related.quoted_body.toStdString()); related.room = room_id_; if (related.quoted_body.isEmpty())