summary refs log tree commit diff
path: root/synapse/api
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-10-22 17:14:12 +0100
committerErik Johnston <erik@matrix.org>2015-10-22 17:14:12 +0100
commit53c679b59b664a248d4fce138806efe2e284c7e4 (patch)
treeabdddc0b5aadc1bd11b74c89cbf7af761d694885 /synapse/api
parentMerge pull request #319 from matrix-org/erikj/filter_refactor (diff)
parentActually filter results (diff)
downloadsynapse-53c679b59b664a248d4fce138806efe2e284c7e4.tar.xz
Merge pull request #324 from matrix-org/erikj/search
Add filters to search.
Diffstat (limited to 'synapse/api')
-rw-r--r--synapse/api/filtering.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py
index 60b6648e0d..ab14b47281 100644
--- a/synapse/api/filtering.py
+++ b/synapse/api/filtering.py
@@ -202,6 +202,26 @@ class Filter(object):
 
         return True
 
+    def filter_rooms(self, room_ids):
+        """Apply the 'rooms' filter to a given list of rooms.
+
+        Args:
+            room_ids (list): A list of room_ids.
+
+        Returns:
+            list: A list of room_ids that match the filter
+        """
+        room_ids = set(room_ids)
+
+        disallowed_rooms = set(self.filter_json.get("not_rooms", []))
+        room_ids -= disallowed_rooms
+
+        allowed_rooms = self.filter_json.get("rooms", None)
+        if allowed_rooms is not None:
+            room_ids &= set(allowed_rooms)
+
+        return room_ids
+
     def filter(self, events):
         return filter(self.check, events)