summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp

index df2051e6..388a5842 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: @@ -223,6 +225,7 @@ TimelineModel::roleNames() const {State, "state"}, {IsEncrypted, "isEncrypted"}, {ReplyTo, "replyTo"}, + {Reactions, "reactions"}, {RoomId, "roomId"}, {RoomName, "roomName"}, {RoomTopic, "roomTopic"}, @@ -345,6 +348,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: @@ -471,7 +479,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; } @@ -609,6 +616,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<mtx::events::RoomEvent<mtx::events::msg::Reaction>>( + &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) @@ -632,6 +651,18 @@ TimelineModel::internalAddEvents( continue; // don't insert redaction into timeline } + if (auto reaction = + std::get_if<mtx::events::RoomEvent<mtx::events::msg::Reaction>>(&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) + emit dataChanged(index(idx, 0), index(idx, 0)); + continue; // don't insert reaction into timeline + } + if (auto event = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(&e)) { auto e_ = decryptEvent(*event).event; @@ -707,6 +738,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