diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp
index be4bc09e..4a90222f 100644
--- a/src/timeline/EventStore.cpp
+++ b/src/timeline/EventStore.cpp
@@ -293,16 +293,16 @@ EventStore::handleSync(const mtx::responses::Timeline &events)
}
for (const auto &event : events.events) {
- std::string relates_to;
+ std::set<std::string> relates_to;
if (auto redaction =
std::get_if<mtx::events::RedactionEvent<mtx::events::msg::Redaction>>(
&event)) {
// fixup reactions
auto redacted = events_by_id_.object({room_id_, redaction->redacts});
if (redacted) {
- auto id = mtx::accessors::relates_to_event_id(*redacted);
- if (!id.empty()) {
- auto idx = idToIndex(id);
+ auto id = mtx::accessors::relations(*redacted);
+ if (id.annotates()) {
+ auto idx = idToIndex(id.annotates()->event_id);
if (idx) {
events_by_id_.remove(
{room_id_, redaction->redacts});
@@ -312,20 +312,17 @@ EventStore::handleSync(const mtx::responses::Timeline &events)
}
}
- relates_to = redaction->redacts;
- } else if (auto reaction =
- std::get_if<mtx::events::RoomEvent<mtx::events::msg::Reaction>>(
- &event)) {
- relates_to = reaction->content.relates_to.event_id;
+ relates_to.insert(redaction->redacts);
} else {
- relates_to = mtx::accessors::in_reply_to_event(event);
+ for (const auto &r : mtx::accessors::relations(event).relations)
+ relates_to.insert(r.event_id);
}
- if (!relates_to.empty()) {
- auto idx = cache::client()->getTimelineIndex(room_id_, relates_to);
+ for (const auto &relates_to_id : relates_to) {
+ auto idx = cache::client()->getTimelineIndex(room_id_, relates_to_id);
if (idx) {
- events_by_id_.remove({room_id_, relates_to});
- decryptedEvents_.remove({room_id_, relates_to});
+ events_by_id_.remove({room_id_, relates_to_id});
+ decryptedEvents_.remove({room_id_, relates_to_id});
events_.remove({room_id_, *idx});
emit dataChanged(toExternalIdx(*idx), toExternalIdx(*idx));
}
@@ -430,13 +427,14 @@ EventStore::reactions(const std::string &event_id)
if (auto reaction = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Reaction>>(
related_event);
- reaction && reaction->content.relates_to.key) {
- auto &agg = aggregation[reaction->content.relates_to.key.value()];
+ reaction && reaction->content.relations.annotates() &&
+ reaction->content.relations.annotates()->key) {
+ auto key = reaction->content.relations.annotates()->key.value();
+ auto &agg = aggregation[key];
if (agg.count == 0) {
Reaction temp{};
- temp.key_ =
- QString::fromStdString(reaction->content.relates_to.key.value());
+ temp.key_ = QString::fromStdString(key);
reactions.push_back(temp);
}
@@ -691,8 +689,7 @@ EventStore::decryptEvent(const IdIndex &idx,
body["unsigned"] = e.unsigned_data;
// relations are unencrypted in content...
- if (json old_ev = e; old_ev["content"].count("m.relates_to") != 0)
- body["content"]["m.relates_to"] = old_ev["content"]["m.relates_to"];
+ mtx::common::add_relations(body["content"], e.content.relations);
json event_array = json::array();
event_array.push_back(body);
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index b31c1f76..738fb37c 100644
--- a/src/timeline/InputBar.cpp
+++ b/src/timeline/InputBar.cpp
@@ -294,7 +294,8 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown)
text.formatted_body =
utils::getFormattedQuoteBody(related, msg.toHtmlEscaped()).toStdString();
- text.relates_to.in_reply_to.event_id = related.related_event;
+ text.relations.relations.push_back(
+ {mtx::common::RelationType::InReplyTo, related.related_event});
room->resetReply();
}
@@ -316,7 +317,8 @@ InputBar::emote(QString msg)
}
if (!room->reply().isEmpty()) {
- emote.relates_to.in_reply_to.event_id = room->reply().toStdString();
+ emote.relations.relations.push_back(
+ {mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
@@ -346,7 +348,8 @@ InputBar::image(const QString &filename,
image.url = url.toStdString();
if (!room->reply().isEmpty()) {
- image.relates_to.in_reply_to.event_id = room->reply().toStdString();
+ image.relations.relations.push_back(
+ {mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
@@ -371,7 +374,8 @@ InputBar::file(const QString &filename,
file.url = url.toStdString();
if (!room->reply().isEmpty()) {
- file.relates_to.in_reply_to.event_id = room->reply().toStdString();
+ file.relations.relations.push_back(
+ {mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
@@ -397,7 +401,8 @@ InputBar::audio(const QString &filename,
audio.url = url.toStdString();
if (!room->reply().isEmpty()) {
- audio.relates_to.in_reply_to.event_id = room->reply().toStdString();
+ audio.relations.relations.push_back(
+ {mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
@@ -422,7 +427,8 @@ InputBar::video(const QString &filename,
video.url = url.toStdString();
if (!room->reply().isEmpty()) {
- video.relates_to.in_reply_to.event_id = room->reply().toStdString();
+ video.relations.relations.push_back(
+ {mtx::common::RelationType::InReplyTo, room->reply().toStdString()});
room->resetReply();
}
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 968ec3c7..c47194f5 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -360,7 +360,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
const static QRegularExpression replyFallback(
"<mx-reply>.*</mx-reply>", QRegularExpression::DotMatchesEverythingOption);
- bool isReply = !in_reply_to_event(event).empty();
+ bool isReply = relations(event).reply_to().has_value();
auto formattedBody_ = QString::fromStdString(formatted_body(event));
if (formattedBody_.isEmpty()) {
@@ -442,7 +442,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
return cache::isRoomEncrypted(room_id_.toStdString());
}
case ReplyTo:
- return QVariant(QString::fromStdString(in_reply_to_event(event)));
+ return QVariant(QString::fromStdString(relations(event).reply_to().value_or("")));
case Reactions: {
auto id = event_id(event);
return QVariant::fromValue(events.reactions(id));
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 9e045e83..e1e2b681 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -503,9 +503,11 @@ TimelineViewManager::queueReactionMessage(const QString &reactedEvent, const QSt
// If selfReactedEvent is empty, that means we haven't previously reacted
if (selfReactedEvent.isEmpty()) {
mtx::events::msg::Reaction reaction;
- reaction.relates_to.rel_type = mtx::common::RelationType::Annotation;
- reaction.relates_to.event_id = reactedEvent.toStdString();
- reaction.relates_to.key = reactionKey.toStdString();
+ mtx::common::Relation rel;
+ rel.rel_type = mtx::common::RelationType::Annotation;
+ rel.event_id = reactedEvent.toStdString();
+ rel.key = reactionKey.toStdString();
+ reaction.relations.relations.push_back(rel);
timeline_->sendMessageEvent(reaction, mtx::events::EventType::Reaction);
// Otherwise, we have previously reacted and the reaction should be redacted
|