diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-15 14:15:10 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-15 14:15:10 +0100 |
commit | b0406b9ead0e3b726ef2c675181d040ca392e85d (patch) | |
tree | 42fdeee7d4b5eb283f6a406463499ae05b9e5ffe /synapse/api/events | |
parent | Merge remote-tracking branch 'origin/develop' into test-sqlite-memory (diff) | |
parent | Correctly handle the 'age' key in events and pdus (diff) | |
download | synapse-b0406b9ead0e3b726ef2c675181d040ca392e85d.tar.xz |
Merge remote-tracking branch 'origin/develop' into test-sqlite-memory
Diffstat (limited to 'synapse/api/events')
-rw-r--r-- | synapse/api/events/__init__.py | 13 | ||||
-rw-r--r-- | synapse/api/events/factory.py | 8 |
2 files changed, 21 insertions, 0 deletions
diff --git a/synapse/api/events/__init__.py b/synapse/api/events/__init__.py index 5f300de108..72c493db57 100644 --- a/synapse/api/events/__init__.py +++ b/synapse/api/events/__init__.py @@ -17,6 +17,18 @@ from synapse.api.errors import SynapseError, Codes from synapse.util.jsonobject import JsonEncodedObject +def serialize_event(hs, e): + # FIXME(erikj): To handle the case of presence events and the like + if not isinstance(e, SynapseEvent): + return e + + d = e.get_dict() + if "age_ts" in d: + d["age"] = int(hs.get_clock().time_msec()) - d["age_ts"] + + return d + + class SynapseEvent(JsonEncodedObject): """Base class for Synapse events. These are JSON objects which must abide @@ -43,6 +55,7 @@ class SynapseEvent(JsonEncodedObject): "content", # HTTP body, JSON "state_key", "required_power_level", + "age_ts", ] internal_keys = [ diff --git a/synapse/api/events/factory.py b/synapse/api/events/factory.py index 5e38cdbc44..d3d96d73eb 100644 --- a/synapse/api/events/factory.py +++ b/synapse/api/events/factory.py @@ -59,6 +59,14 @@ class EventFactory(object): if "ts" not in kwargs: kwargs["ts"] = int(self.clock.time_msec()) + # The "age" key is a delta timestamp that should be converted into an + # absolute timestamp the minute we see it. + if "age" in kwargs: + kwargs["age_ts"] = int(self.clock.time_msec()) - int(kwargs["age"]) + del kwargs["age"] + elif "age_ts" not in kwargs: + kwargs["age_ts"] = int(self.clock.time_msec()) + if etype in self._event_list: handler = self._event_list[etype] else: |