summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-09-16 10:19:32 +0100
committerErik Johnston <erik@matrix.org>2016-09-16 10:19:32 +0100
commite58a9d781c7808b66f6eda221c9ce91ccd3cd8d6 (patch)
tree65acefc3f853ec60df599562e16afe63fd4fdb6c /synapse/handlers
parentDon't cache searched in /publicRooms (diff)
downloadsynapse-e58a9d781c7808b66f6eda221c9ce91ccd3cd8d6.tar.xz
Filter remote rooms lists locally
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/room_list.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py
index 37213f4bd8..9383f2486c 100644
--- a/synapse/handlers/room_list.py
+++ b/synapse/handlers/room_list.py
@@ -212,16 +212,7 @@ class RoomListHandler(BaseHandler):
                 if avatar_url:
                     result["avatar_url"] = avatar_url
 
-            logger.info("search_filter: %r", search_filter)
-            if search_filter and search_filter.get("generic_search_term", None):
-                generic_search_term = search_filter["generic_search_term"]
-                if generic_search_term in result.get("name", ""):
-                    chunk.append(result)
-                elif generic_search_term in result.get("topic", ""):
-                    chunk.append(result)
-                elif generic_search_term in result.get("canonical_alias", ""):
-                    chunk.append(result)
-            else:
+            if _matches_room_entry(result, search_filter):
                 chunk.append(result)
 
         yield concurrently_execute(handle_room, rooms_to_scan, 10)
@@ -291,8 +282,16 @@ class RoomListHandler(BaseHandler):
                                     search_filter=None):
         res = yield self.hs.get_replication_layer().get_public_rooms(
             server_name, limit=limit, since_token=since_token,
+            search_filter=search_filter,
         )
 
+        if search_filter:
+            res["chunk"] = [
+                entry
+                for entry in dict(res.get("chunk", []))
+                if _matches_room_entry(entry, search_filter)
+            ]
+
         defer.returnValue(res)
 
 
@@ -329,3 +328,18 @@ class RoomListNextBatch(namedtuple("RoomListNextBatch", (
         return self._replace(
             **kwds
         )
+
+
+def _matches_room_entry(room_entry, search_filter):
+    if search_filter and search_filter.get("generic_search_term", None):
+        generic_search_term = search_filter["generic_search_term"]
+        if generic_search_term in room_entry.get("name", ""):
+            return True
+        elif generic_search_term in room_entry.get("topic", ""):
+            return True
+        elif generic_search_term in room_entry.get("canonical_alias", ""):
+            return True
+    else:
+        return True
+
+    return False