summary refs log tree commit diff
path: root/synapse/events/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/events/utils.py')
-rw-r--r--synapse/events/utils.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py
index 4ad37188ba..e391aca4cc 100644
--- a/synapse/events/utils.py
+++ b/synapse/events/utils.py
@@ -89,23 +89,31 @@ def prune_event(event):
     return type(event)(allowed_fields)
 
 
-def serialize_event(hs, e):
+def serialize_event(e, time_now_ms, client_event=True):
     # FIXME(erikj): To handle the case of presence events and the like
     if not isinstance(e, EventBase):
         return e
 
+    time_now_ms = int(time_now_ms)
+
     # 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"]:
+            d["unsigned"]["age"] = time_now_ms - d["unsigned"]["age_ts"]
+        return d
+
     if "age_ts" in d["unsigned"]:
-        now = int(hs.get_clock().time_msec())
-        d["age"] = now - d["unsigned"]["age_ts"]
+        d["age"] = time_now_ms - d["unsigned"]["age_ts"]
         del d["unsigned"]["age_ts"]
 
     d["user_id"] = d.pop("sender", None)
 
     if "redacted_because" in e.unsigned:
         d["redacted_because"] = serialize_event(
-            hs, e.unsigned["redacted_because"]
+            e.unsigned["redacted_because"], time_now_ms
         )
 
         del d["unsigned"]["redacted_because"]