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
This commit is contained in:
Mark Haines 2015-12-09 12:56:53 +00:00
commit 019597555f

View File

@ -25,11 +25,14 @@ from synapse.events.utils import (
serialize_event, format_event_for_client_v2_without_room_id, serialize_event, format_event_for_client_v2_without_room_id,
) )
from synapse.api.filtering import FilterCollection from synapse.api.filtering import FilterCollection
from synapse.api.errors import SynapseError
from ._base import client_v2_patterns from ._base import client_v2_patterns
import copy import copy
import logging import logging
import ujson as json
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -48,7 +51,7 @@ class SyncRestServlet(RestServlet):
"next_batch": // batch token for the next /sync "next_batch": // batch token for the next /sync
"presence": // presence data for the user. "presence": // presence data for the user.
"rooms": { "rooms": {
"joined": { // Joined rooms being updated. "join": { // Joined rooms being updated.
"${room_id}": { // Id of the room being updated "${room_id}": { // Id of the room being updated
"event_map": // Map of EventID -> event JSON. "event_map": // Map of EventID -> event JSON.
"timeline": { // The recent events in the room if gap is "true" "timeline": { // The recent events in the room if gap is "true"
@ -63,8 +66,8 @@ class SyncRestServlet(RestServlet):
"ephemeral": {"events": []} // list of event objects "ephemeral": {"events": []} // list of event objects
} }
}, },
"invited": {}, // Invited rooms being updated. "invite": {}, // Invited rooms being updated.
"archived": {} // Archived rooms being updated. "leave": {} // Archived rooms being updated.
} }
} }
""" """
@ -100,12 +103,21 @@ class SyncRestServlet(RestServlet):
) )
) )
try: if filter_id and filter_id.startswith('{'):
filter = yield self.filtering.get_user_filter( logging.error("MJH %r", filter_id)
user.localpart, filter_id try:
) filter_object = json.loads(filter_id)
except: except:
filter = FilterCollection({}) 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( sync_config = SyncConfig(
user=user, user=user,