summary refs log tree commit diff
path: root/synapse/events
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-01-08 14:27:04 +0000
committerKegan Dougal <kegan@matrix.org>2015-01-08 14:28:08 +0000
commitedb557b2ad98d3260caaba41ef2278b3eafc7e85 (patch)
treed3c5bceb3f5c9fb142c4ff6f8ab23b095f4eae37 /synapse/events
parentAdd missing continuation indent. (diff)
downloadsynapse-edb557b2ad98d3260caaba41ef2278b3eafc7e85.tar.xz
Return the raw federation event rather than adding extra keys for federation data.
Diffstat (limited to 'synapse/events')
-rw-r--r--synapse/events/utils.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py
index 258dedb27c..4687d96f26 100644
--- a/synapse/events/utils.py
+++ b/synapse/events/utils.py
@@ -89,13 +89,21 @@ def prune_event(event):
     return type(event)(allowed_fields)
 
 
-def serialize_event(hs, e, remove_data=True):
+def serialize_event(hs, e, client_event=True):
     # FIXME(erikj): To handle the case of presence events and the like
     if not isinstance(e, EventBase):
         return e
 
     # Should this strip out None's?
     d = {k: v for k, v in e.get_dict().items()}
+
+    if not client_event:
+        # set the age and keep all other keys
+        if "age_ts" in d["unsigned"]:
+            now = int(hs.get_clock().time_msec())
+            d["unsigned"]["age"] = now - d["unsigned"]["age_ts"]
+        return d
+
     if "age_ts" in d["unsigned"]:
         now = int(hs.get_clock().time_msec())
         d["unsigned"]["age"] = now - d["unsigned"]["age_ts"]
@@ -122,13 +130,12 @@ def serialize_event(hs, e, remove_data=True):
         d["prev_content"] = e.unsigned["prev_content"]
         del d["unsigned"]["prev_content"]
 
-    if remove_data:
-        del d["auth_events"]
-        del d["prev_events"]
-        del d["hashes"]
-        del d["signatures"]
-        d.pop("depth", None)
-        d.pop("unsigned", None)
-        d.pop("origin", None)
+    del d["auth_events"]
+    del d["prev_events"]
+    del d["hashes"]
+    del d["signatures"]
+    d.pop("depth", None)
+    d.pop("unsigned", None)
+    d.pop("origin", None)
 
     return d