summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--synapse/api/filtering.py20
-rw-r--r--synapse/handlers/search.py2
2 files changed, 21 insertions, 1 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)
 
diff --git a/synapse/handlers/search.py b/synapse/handlers/search.py
index 473aab53f0..f53e5d35ac 100644
--- a/synapse/handlers/search.py
+++ b/synapse/handlers/search.py
@@ -64,7 +64,7 @@ class SearchHandler(BaseHandler):
         )
         room_ids = set(r.room_id for r in rooms)
 
-        # TODO: Apply room filter to rooms list
+        room_ids = filtr.filter_rooms(room_ids)
 
         rank_map, event_map = yield self.store.search_msgs(room_ids, search_term, keys)