From f0757a6426c95424072806180d424c5019dbc666 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 16 May 2020 22:48:43 +0200 Subject: [PATCH] Fix local echo for reactions --- src/timeline/TimelineModel.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index f8334d9b..9eca05ba 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -154,13 +154,25 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj connect(this, &TimelineModel::messageSent, this, [this](QString txn_id, QString event_id) { pending.removeOne(txn_id); + auto ev = events.value(txn_id); + + if (auto reaction = + std::get_if>(&ev)) { + QString reactedTo = + QString::fromStdString(reaction->content.relates_to.event_id); + auto &rModel = reactions[reactedTo]; + rModel.removeReaction(*reaction); + auto rCopy = *reaction; + rCopy.event_id = event_id.toStdString(); + rModel.addReaction(room_id_.toStdString(), rCopy); + } + int idx = idToIndex(txn_id); if (idx < 0) { // transaction already received via sync return; } eventOrder[idx] = event_id; - auto ev = events.value(txn_id); ev = std::visit( [event_id](const auto &e) -> mtx::events::collections::TimelineEvents { auto eventCopy = e; @@ -665,6 +677,14 @@ TimelineModel::internalAddEvents( QString reactedTo = QString::fromStdString(reaction->content.relates_to.event_id); events.insert(id, e); + + // remove local echo + if (!txid.isEmpty()) { + auto rCopy = *reaction; + rCopy.event_id = txid.toStdString(); + reactions[reactedTo].removeReaction(rCopy); + } + reactions[reactedTo].addReaction(room_id_.toStdString(), *reaction); int idx = idToIndex(reactedTo); if (idx >= 0)