summary refs log tree commit diff
path: root/src/timeline/TimelineModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-05-16 22:48:43 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-05-16 22:48:43 +0200
commitf0757a6426c95424072806180d424c5019dbc666 (patch)
tree7f25d3ac14df798d55e04dcab8275a9e6ca9dd48 /src/timeline/TimelineModel.cpp
parentFix reactions binding loop (diff)
downloadnheko-f0757a6426c95424072806180d424c5019dbc666.tar.xz
Fix local echo for reactions
Diffstat (limited to 'src/timeline/TimelineModel.cpp')
-rw-r--r--src/timeline/TimelineModel.cpp22
1 files changed, 21 insertions, 1 deletions
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<mtx::events::RoomEvent<mtx::events::msg::Reaction>>(&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)