From 54013e4a00b49721b79f141bca101523a1e82282 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 4 May 2020 13:14:54 +0200 Subject: Basic, broken reaction display --- src/timeline/TimelineModel.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 340bae39..0555d2ba 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -223,6 +223,7 @@ TimelineModel::roleNames() const {State, "state"}, {IsEncrypted, "isEncrypted"}, {ReplyTo, "replyTo"}, + {Reactions, "reactions"}, {RoomId, "roomId"}, {RoomName, "roomName"}, {RoomTopic, "roomTopic"}, @@ -337,6 +338,11 @@ TimelineModel::data(const QString &id, int role) const } case ReplyTo: return QVariant(QString::fromStdString(in_reply_to_event(event))); + case Reactions: + if (reactions.count(id)) + return QVariant::fromValue((QObject *)&reactions.at(id)); + else + return {}; case RoomId: return QVariant(QString::fromStdString(room_id(event))); case RoomName: @@ -574,6 +580,18 @@ TimelineModel::internalAddEvents( QString redacts = QString::fromStdString(redaction->redacts); auto redacted = std::find(eventOrder.begin(), eventOrder.end(), redacts); + auto event = events.value(redacts); + if (auto reaction = + std::get_if>( + &event)) { + QString reactedTo = + QString::fromStdString(reaction->content.relates_to.event_id); + reactions[reactedTo].removeReaction(*reaction); + int idx = idToIndex(reactedTo); + if (idx >= 0) + emit dataChanged(index(idx, 0), index(idx, 0)); + } + if (redacted != eventOrder.end()) { auto redactedEvent = std::visit( [](const auto &ev) @@ -597,6 +615,17 @@ TimelineModel::internalAddEvents( continue; // don't insert redaction into timeline } + if (auto reaction = + std::get_if>(&e)) { + QString reactedTo = + QString::fromStdString(reaction->content.relates_to.event_id); + reactions[reactedTo].addReaction(*reaction); + int idx = idToIndex(reactedTo); + if (idx >= 0) + emit dataChanged(index(idx, 0), index(idx, 0)); + continue; // don't insert reaction into timeline + } + if (auto event = std::get_if>(&e)) { auto e_ = decryptEvent(*event).event; -- cgit 1.5.1 From e045e3eb1cbb3785153ca7634f76ba80b9d16bb1 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 6 May 2020 11:28:24 +0200 Subject: Show displayname on reactions --- src/timeline/ReactionsModel.cpp | 11 +++++++---- src/timeline/ReactionsModel.h | 4 +++- src/timeline/TimelineModel.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/ReactionsModel.cpp b/src/timeline/ReactionsModel.cpp index f21b1c53..b686c750 100644 --- a/src/timeline/ReactionsModel.cpp +++ b/src/timeline/ReactionsModel.cpp @@ -1,9 +1,8 @@ #include "ReactionsModel.h" +#include #include -#include "Logging.h" - QHash ReactionsModel::roleNames() const { @@ -41,7 +40,8 @@ ReactionsModel::data(const QModelIndex &index, int role) const users += ", "; else first = false; - users += QString::fromStdString(reaction.sender); + users += + QString::fromStdString(cache::displayName(room_id_, reaction.sender)); } return users; } @@ -56,8 +56,11 @@ ReactionsModel::data(const QModelIndex &index, int role) const } void -ReactionsModel::addReaction(const mtx::events::RoomEvent &reaction) +ReactionsModel::addReaction(const std::string &room_id, + const mtx::events::RoomEvent &reaction) { + room_id_ = room_id; + int idx = 0; for (auto &storedReactions : reactions) { if (storedReactions.key == reaction.content.relates_to.key) { diff --git a/src/timeline/ReactionsModel.h b/src/timeline/ReactionsModel.h index a0a8580d..5f61cd42 100644 --- a/src/timeline/ReactionsModel.h +++ b/src/timeline/ReactionsModel.h @@ -26,7 +26,8 @@ public: QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; public slots: - void addReaction(const mtx::events::RoomEvent &reaction); + void addReaction(const std::string &room_id, + const mtx::events::RoomEvent &reaction); void removeReaction(const mtx::events::RoomEvent &reaction); private: @@ -35,5 +36,6 @@ private: std::string key; std::map> reactions; }; + std::string room_id_; std::vector reactions; }; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 0555d2ba..5e57952a 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -619,7 +619,7 @@ TimelineModel::internalAddEvents( std::get_if>(&e)) { QString reactedTo = QString::fromStdString(reaction->content.relates_to.event_id); - reactions[reactedTo].addReaction(*reaction); + reactions[reactedTo].addReaction(room_id_.toStdString(), *reaction); int idx = idToIndex(reactedTo); if (idx >= 0) emit dataChanged(index(idx, 0), index(idx, 0)); -- cgit 1.5.1 From ff54ce9334b03f3e5b9fbee9c7198a99a408bbce Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 6 May 2020 11:37:40 +0200 Subject: Fix rooms with a lot of reactions not paginating correctly --- src/timeline/TimelineModel.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 5e57952a..75f41d1e 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -469,7 +469,6 @@ TimelineModel::fetchMore(const QModelIndex &) mtx::errors::to_string(err->matrix_error.errcode), err->matrix_error.error, err->parse_error); - emit oldMessagesRetrieved(std::move(res)); setPaginationInProgress(false); return; } @@ -701,6 +700,11 @@ TimelineModel::addBackwardsEvents(const mtx::responses::Messages &msgs) } prev_batch_token_ = QString::fromStdString(msgs.end); + + if (ids.empty() && !msgs.chunk.empty()) { + // no visible events fetched, prevent loading from stopping + fetchMore(QModelIndex()); + } } QString -- cgit 1.5.1 From e5a5a66716ba8190b3d6ae1689e7e1f721563777 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 6 May 2020 12:52:13 +0200 Subject: Fix reaction redaction for real this time --- src/timeline/TimelineModel.cpp | 3 +++ src/timeline/TimelineModel.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 75f41d1e..836fd59f 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -42,6 +42,8 @@ struct RoomEventType switch (e.type) { case EventType::RoomKeyRequest: return qml_mtx_events::EventType::KeyRequest; + case EventType::Reaction: + return qml_mtx_events::EventType::Reaction; case EventType::RoomAliases: return qml_mtx_events::EventType::Aliases; case EventType::RoomAvatar: @@ -618,6 +620,7 @@ TimelineModel::internalAddEvents( std::get_if>(&e)) { QString reactedTo = QString::fromStdString(reaction->content.relates_to.event_id); + events.insert(id, e); reactions[reactedTo].addReaction(room_id_.toStdString(), *reaction); int idx = idToIndex(reactedTo); if (idx >= 0) diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index ecb64693..a737aac7 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -30,6 +30,8 @@ enum EventType Unsupported, /// m.room_key_request KeyRequest, + /// m.reaction, + Reaction, /// m.room.aliases Aliases, /// m.room.avatar -- cgit 1.5.1