summary refs log tree commit diff
path: root/synapse/events/utils.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-12-05 16:20:48 +0000
committerErik Johnston <erik@matrix.org>2014-12-05 16:20:48 +0000
commit6630e1b5795667fd947cc5b0d5d2b00da97325e3 (patch)
treece141a61defe211cac454a5953106f6e351fe260 /synapse/events/utils.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into events_refactor (diff)
downloadsynapse-6630e1b5795667fd947cc5b0d5d2b00da97325e3.tar.xz
Start making more things use EventContext rather than event.*
Diffstat (limited to 'synapse/events/utils.py')
-rw-r--r--synapse/events/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/synapse/events/utils.py b/synapse/events/utils.py
index 412f690f08..1b05ee0a95 100644
--- a/synapse/events/utils.py
+++ b/synapse/events/utils.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 from synapse.api.constants import EventTypes
+from . import EventBase
 
 
 def prune_event(event):
@@ -80,3 +81,18 @@ def prune_event(event):
     allowed_fields["content"] = new_content
 
     return type(event)(allowed_fields)
+
+
+def serialize_event(hs, e):
+    # 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 "age_ts" in d["unsigned"]:
+        now = int(hs.get_clock().time_msec())
+        d["unsigned"]["age"] = now - d["unsigned"]["age_ts"]
+        del d["unsigned"]["age_ts"]
+
+    return d
\ No newline at end of file