summary refs log tree commit diff
path: root/synapse/api/events
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-11-18 19:18:36 +0000
committerMark Haines <mark.haines@matrix.org>2014-11-18 19:20:25 +0000
commit428581dd056e40adaca41c3593d79f76339f3220 (patch)
tree27fd6b9faf275962f446bb6c9128939a6f91717b /synapse/api/events
parentRemember also to UTF-8 decode bytes in room alias names in directory server URLs (diff)
downloadsynapse-428581dd056e40adaca41c3593d79f76339f3220.tar.xz
SYN-144: Remove bad keys from pdu json objects, convert age_ts to age
for all pdus sent.
Diffstat (limited to 'synapse/api/events')
-rw-r--r--synapse/api/events/__init__.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/synapse/api/events/__init__.py b/synapse/api/events/__init__.py
index 63c0bd7ae7..0019789dd1 100644
--- a/synapse/api/events/__init__.py
+++ b/synapse/api/events/__init__.py
@@ -117,10 +117,21 @@ class SynapseEvent(JsonEncodedObject):
         """
         raise NotImplementedError("get_content_template not implemented.")
 
-    def get_pdu_json(self):
+    def get_pdu_json(self, time_now=None):
         pdu_json = self.get_full_dict()
         pdu_json.pop("destination", None)
         pdu_json.pop("outlier", None)
+        pdu_json.pop("replaces_state", None)
+        pdu_json.pop("redacted", None)
+        state_hash = pdu_json.pop("state_hash", None)
+        if state_hash is not None:
+            pdu_json.setdefault("unsigned", {})["state_hash"] = state_hash
+        content = pdu_json.get("content", {})
+        content.pop("prev", None)
+        if time_now is not None and "age_ts" in pdu_json:
+            age = time_now - pdu_json["age_ts"]
+            pdu_json.setdefault("unsigned", {})["age"] = int(age)
+            del pdu_json["age_ts"]
         return pdu_json