From ce42797d5bded1170979c8f2904defafc7d113be Mon Sep 17 00:00:00 2001
From: Nicolas Werner <nicolas.werner@hotmail.de>
Date: Wed, 9 Jun 2021 12:48:17 +0200
Subject: [PATCH] Fix edits that have different keys in new_content and content

See https://github.com/matrix-org/matrix-doc/pull/2676#discussion_r648179045
---
 include/mtx/events_impl.hpp | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/mtx/events_impl.hpp b/include/mtx/events_impl.hpp
index 6ff565d95..efad2ab97 100644
--- a/include/mtx/events_impl.hpp
+++ b/include/mtx/events_impl.hpp
@@ -34,12 +34,14 @@ template<class Content>
 from_json(const json &obj, Event<Content> &event)
 {
         if (obj.at("content").contains("m.new_content")) {
-                auto new_content = obj.at("content");
-                for (const auto &e : obj["content"]["m.new_content"].items()) {
-                        if (e.key() != "m.relates_to" &&
-                            e.key() != "im.nheko.relations.v1.relations")
-                                new_content[e.key()] = e.value();
-                }
+                auto new_content = obj.at("content").at("m.new_content");
+
+                if (obj.at("content").contains("m.relates_to"))
+                        new_content["m.relates_to"] = obj.at("content").at("m.relates_to");
+                if (obj.at("content").contains("im.nheko.relations.v1.relations"))
+                        new_content["im.nheko.relations.v1.relations"] =
+                          obj.at("content").at("im.nheko.relations.v1.relations");
+
                 event.content = new_content.get<Content>();
         } else {
                 event.content = obj.at("content").get<Content>();
-- 
GitLab