From faeaf9dc6bfae5bf56f6edee4e21bb54db08b2e1 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 27 Jan 2021 16:14:03 +0100 Subject: [PATCH] Fix edited replies --- src/EventAccessors.cpp | 21 +++++++++++++++++++++ src/EventAccessors.h | 2 ++ src/timeline/EventStore.cpp | 19 +++++++++++++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/EventAccessors.cpp b/src/EventAccessors.cpp index 4218f491..212c2970 100644 --- a/src/EventAccessors.cpp +++ b/src/EventAccessors.cpp @@ -264,6 +264,20 @@ struct EventRelations } }; +struct SetEventRelations +{ + mtx::common::Relations new_relations; + template + using related_ev_id_t = decltype(Content::relations); + template + void operator()(mtx::events::Event &e) + { + if constexpr (is_detected::value) { + e.content.relations = std::move(new_relations); + } + } +}; + struct EventTransactionId { template @@ -426,6 +440,13 @@ mtx::accessors::relations(const mtx::events::collections::TimelineEvents &event) return std::visit(EventRelations{}, event); } +void +mtx::accessors::set_relations(mtx::events::collections::TimelineEvents &event, + mtx::common::Relations relations) +{ + std::visit(SetEventRelations{std::move(relations)}, event); +} + std::string mtx::accessors::transaction_id(const mtx::events::collections::TimelineEvents &event) { diff --git a/src/EventAccessors.h b/src/EventAccessors.h index 60912497..95e5df24 100644 --- a/src/EventAccessors.h +++ b/src/EventAccessors.h @@ -55,6 +55,8 @@ std::string mimetype(const mtx::events::collections::TimelineEvents &event); mtx::common::Relations relations(const mtx::events::collections::TimelineEvents &event); +void +set_relations(mtx::events::collections::TimelineEvents &event, mtx::common::Relations relations); std::string transaction_id(const mtx::events::collections::TimelineEvents &event); diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index ebf2f024..e5a66e19 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -414,7 +414,8 @@ EventStore::edits(const std::string &event_id) if (!original_event) return {}; - auto original_sender = mtx::accessors::sender(*original_event); + auto original_sender = mtx::accessors::sender(*original_event); + auto original_relations = mtx::accessors::relations(*original_event); std::vector edits; for (const auto &id : event_ids) { @@ -422,10 +423,20 @@ EventStore::edits(const std::string &event_id) if (!related_event) continue; - auto edit_rel = mtx::accessors::relations(*related_event); + auto related_ev = *related_event; + + auto edit_rel = mtx::accessors::relations(related_ev); if (edit_rel.replaces() == event_id && - original_sender == mtx::accessors::sender(*related_event)) - edits.push_back(*related_event); + original_sender == mtx::accessors::sender(related_ev)) { + if (edit_rel.synthesized && original_relations.reply_to() && + !edit_rel.reply_to()) { + edit_rel.relations.push_back( + {mtx::common::RelationType::InReplyTo, + original_relations.reply_to().value()}); + mtx::accessors::set_relations(related_ev, std::move(edit_rel)); + } + edits.push_back(std::move(related_ev)); + } } auto c = cache::client();