diff options
author | Erik Johnston <erik@matrix.org> | 2014-12-05 16:20:48 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-12-05 16:20:48 +0000 |
commit | 6630e1b5795667fd947cc5b0d5d2b00da97325e3 (patch) | |
tree | ce141a61defe211cac454a5953106f6e351fe260 /synapse/events/utils.py | |
parent | Merge branch 'develop' of github.com:matrix-org/synapse into events_refactor (diff) | |
download | synapse-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.py | 16 |
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 |