summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorKegsay <kegsay@gmail.com>2016-11-22 14:02:38 +0000
committerGitHub <noreply@github.com>2016-11-22 14:02:38 +0000
commitd4a459f7cb4e7ed6160194bc58757f5adbc2b2b4 (patch)
treef8353515d2179d22127e1981b7a9118c09c84b6b /synapse/api
parentMerge branch 'master' of github.com:matrix-org/synapse into develop (diff)
parentReview comments (diff)
downloadsynapse-d4a459f7cb4e7ed6160194bc58757f5adbc2b2b4.tar.xz
Merge pull request #1638 from matrix-org/kegan/sync-event-fields
Implement "event_fields" in filters
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/filtering.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py
index 3b3ef70750..6f16e4d406 100644
--- a/synapse/api/filtering.py
+++ b/synapse/api/filtering.py
@@ -71,6 +71,21 @@ class Filtering(object):
                 if key in user_filter_json["room"]:
                     self._check_definition(user_filter_json["room"][key])
 
+        if "event_fields" in user_filter_json:
+            if type(user_filter_json["event_fields"]) != list:
+                raise SynapseError(400, "event_fields must be a list of strings")
+            for field in user_filter_json["event_fields"]:
+                if not isinstance(field, basestring):
+                    raise SynapseError(400, "Event field must be a string")
+                # Don't allow '\\' in event field filters. This makes matching
+                # events a lot easier as we can then use a negative lookbehind
+                # assertion to split '\.' If we allowed \\ then it would
+                # incorrectly split '\\.' See synapse.events.utils.serialize_event
+                if r'\\' in field:
+                    raise SynapseError(
+                        400, r'The escape character \ cannot itself be escaped'
+                    )
+
     def _check_definition_room_lists(self, definition):
         """Check that "rooms" and "not_rooms" are lists of room ids if they
         are present
@@ -152,6 +167,7 @@ class FilterCollection(object):
         self.include_leave = filter_json.get("room", {}).get(
             "include_leave", False
         )
+        self.event_fields = filter_json.get("event_fields", [])
 
     def __repr__(self):
         return "<FilterCollection %s>" % (json.dumps(self._filter_json),)