summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--synapse/events/utils.py8
-rw-r--r--synapse/storage/_base.py6
-rw-r--r--tests/storage/test_stream.py5
3 files changed, 16 insertions, 3 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py
index 6d9c9352e2..4ab770dd5f 100644
--- a/synapse/events/utils.py
+++ b/synapse/events/utils.py
@@ -113,6 +113,14 @@ def serialize_event(hs, e):
         d["redacted_by"] = e.unsigned["redacted_by"]
         del d["unsigned"]["redacted_by"]
 
+    if "replaces_state" in e.unsigned:
+        d["replaces_state"] = e.unsigned["replaces_state"]
+        del d["unsigned"]["replaces_state"]
+
+    if "prev_content" in e.unsigned:
+        d["prev_content"] = e.unsigned["prev_content"]
+        del d["unsigned"]["prev_content"]
+
     del d["auth_events"]
     del d["prev_events"]
     del d["hashes"]
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index ffc26d4a61..e9cf73a8e2 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -487,6 +487,12 @@ class SQLBaseStore(object):
             if because:
                 ev.unsigned["redacted_because"] = because
 
+        if "replaces_state" in ev.unsigned:
+            ev.unsigned["prev_content"] = self._get_event_txn(
+                txn,
+                ev.unsigned["replaces_state"],
+            ).get_dict()["content"]
+
         return ev
 
     def _parse_events(self, rows):
diff --git a/tests/storage/test_stream.py b/tests/storage/test_stream.py
index cba65bb9f0..4865a5c142 100644
--- a/tests/storage/test_stream.py
+++ b/tests/storage/test_stream.py
@@ -58,7 +58,7 @@ class StreamStoreTestCase(unittest.TestCase):
         self.depth = 1
 
     @defer.inlineCallbacks
-    def inject_room_member(self, room, user, membership, replaces_state=None):
+    def inject_room_member(self, room, user, membership):
         self.depth += 1
 
         builder = self.event_builder_factory.new({
@@ -215,7 +215,6 @@ class StreamStoreTestCase(unittest.TestCase):
 
         event2 = yield self.inject_room_member(
             self.room1, self.u_alice, Membership.JOIN,
-            replaces_state=event1.event_id,
         )
 
         end = yield self.store.get_room_events_max_id()
@@ -233,6 +232,6 @@ class StreamStoreTestCase(unittest.TestCase):
         event = results[0]
 
         self.assertTrue(
-            hasattr(event, "prev_content"),
+            "prev_content" in event.unsigned,
             msg="No prev_content key"
         )