diff options
author | Erik Johnston <erikj@jki.re> | 2017-03-15 16:01:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-15 16:01:29 +0000 |
commit | 9d527191bcd14f51ae43cfccf18a34ecb19df801 (patch) | |
tree | 272a697640aaf3c919db0b63967908e89b8f16f5 /synapse/rest/client/v2_alpha/sync.py | |
parent | Merge pull request #1997 from matrix-org/dbkr/cas_partialdownload (diff) | |
parent | Comment (diff) | |
download | synapse-9d527191bcd14f51ae43cfccf18a34ecb19df801.tar.xz |
Merge pull request #2013 from matrix-org/erikj/presence_FASTER
Format presence events on the edges instead of reformatting them multiple times
Diffstat (limited to 'synapse/rest/client/v2_alpha/sync.py')
-rw-r--r-- | synapse/rest/client/v2_alpha/sync.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/synapse/rest/client/v2_alpha/sync.py b/synapse/rest/client/v2_alpha/sync.py index b3d8001638..a7a9e0a794 100644 --- a/synapse/rest/client/v2_alpha/sync.py +++ b/synapse/rest/client/v2_alpha/sync.py @@ -18,6 +18,7 @@ from twisted.internet import defer from synapse.http.servlet import ( RestServlet, parse_string, parse_integer, parse_boolean ) +from synapse.handlers.presence import format_user_presence_state from synapse.handlers.sync import SyncConfig from synapse.types import StreamToken from synapse.events.utils import ( @@ -28,7 +29,6 @@ from synapse.api.errors import SynapseError from synapse.api.constants import PresenceState from ._base import client_v2_patterns -import copy import itertools import logging @@ -194,12 +194,18 @@ class SyncRestServlet(RestServlet): defer.returnValue((200, response_content)) def encode_presence(self, events, time_now): - formatted = [] - for event in events: - event = copy.deepcopy(event) - event['sender'] = event['content'].pop('user_id') - formatted.append(event) - return {"events": formatted} + return { + "events": [ + { + "type": "m.presence", + "sender": event.user_id, + "content": format_user_presence_state( + event, time_now, include_user_id=False + ), + } + for event in events + ] + } def encode_joined(self, rooms, time_now, token_id, event_fields): """ |