Skip to content

Commit

Permalink
Fix edited replies
Browse files Browse the repository at this point in the history
  • Loading branch information
deepbluev7 committed Jan 27, 2021
1 parent c208620 commit 58b340a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/EventAccessors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ struct EventRelations
}
};

struct SetEventRelations
{
mtx::common::Relations new_relations;
template<class Content>
using related_ev_id_t = decltype(Content::relations);
template<class T>
void operator()(mtx::events::Event<T> &e)
{
if constexpr (is_detected<related_ev_id_t, T>::value) {
e.content.relations = std::move(new_relations);
}
}
};

struct EventTransactionId
{
template<class T>
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/EventAccessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 15 additions & 4 deletions src/timeline/EventStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,29 @@ 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<mtx::events::collections::TimelineEvents> edits;
for (const auto &id : event_ids) {
auto related_event = get(id, event_id, false, false);
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();
Expand Down

0 comments on commit 58b340a

Please sign in to comment.