diff options
author | Mark Haines <mjark@negativecurvature.net> | 2015-12-09 12:56:53 +0000 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2015-12-09 12:56:53 +0000 |
commit | 019597555f36c5c1069d98a37dbc2eee91538bd9 (patch) | |
tree | e82f3a1e41cf305eb3eedcd7baf4915de7004452 /synapse | |
parent | Merge pull request #430 from matrix-org/daniel/unstable (diff) | |
parent | Allow filter JSON object in the filter query parameter in /sync (diff) | |
download | synapse-019597555f36c5c1069d98a37dbc2eee91538bd9.tar.xz |
Merge pull request #431 from matrix-org/markjh/filter_inline
Allow filter JSON object in the filter query parameter in /sync Documented by matrix-org/matrix-doc#224
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/rest/client/v2_alpha/sync.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/synapse/rest/client/v2_alpha/sync.py b/synapse/rest/client/v2_alpha/sync.py index 4efe802487..f0a637a6da 100644 --- a/synapse/rest/client/v2_alpha/sync.py +++ b/synapse/rest/client/v2_alpha/sync.py @@ -25,11 +25,14 @@ from synapse.events.utils import ( serialize_event, format_event_for_client_v2_without_room_id, ) from synapse.api.filtering import FilterCollection +from synapse.api.errors import SynapseError from ._base import client_v2_patterns import copy import logging +import ujson as json + logger = logging.getLogger(__name__) @@ -48,7 +51,7 @@ class SyncRestServlet(RestServlet): "next_batch": // batch token for the next /sync "presence": // presence data for the user. "rooms": { - "joined": { // Joined rooms being updated. + "join": { // Joined rooms being updated. "${room_id}": { // Id of the room being updated "event_map": // Map of EventID -> event JSON. "timeline": { // The recent events in the room if gap is "true" @@ -63,8 +66,8 @@ class SyncRestServlet(RestServlet): "ephemeral": {"events": []} // list of event objects } }, - "invited": {}, // Invited rooms being updated. - "archived": {} // Archived rooms being updated. + "invite": {}, // Invited rooms being updated. + "leave": {} // Archived rooms being updated. } } """ @@ -100,12 +103,21 @@ class SyncRestServlet(RestServlet): ) ) - try: - filter = yield self.filtering.get_user_filter( - user.localpart, filter_id - ) - except: - filter = FilterCollection({}) + if filter_id and filter_id.startswith('{'): + logging.error("MJH %r", filter_id) + try: + filter_object = json.loads(filter_id) + except: + raise SynapseError(400, "Invalid filter JSON") + self.filtering._check_valid_filter(filter_object) + filter = FilterCollection(filter_object) + else: + try: + filter = yield self.filtering.get_user_filter( + user.localpart, filter_id + ) + except: + filter = FilterCollection({}) sync_config = SyncConfig( user=user, |