Filter remote rooms lists locally

This commit is contained in:
Erik Johnston 2016-09-16 10:19:32 +01:00
parent 74d4cdee25
commit e58a9d781c
2 changed files with 25 additions and 11 deletions

View File

@ -212,16 +212,7 @@ class RoomListHandler(BaseHandler):
if avatar_url: if avatar_url:
result["avatar_url"] = avatar_url result["avatar_url"] = avatar_url
logger.info("search_filter: %r", search_filter) if _matches_room_entry(result, 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:
chunk.append(result) chunk.append(result)
yield concurrently_execute(handle_room, rooms_to_scan, 10) yield concurrently_execute(handle_room, rooms_to_scan, 10)
@ -291,8 +282,16 @@ class RoomListHandler(BaseHandler):
search_filter=None): search_filter=None):
res = yield self.hs.get_replication_layer().get_public_rooms( res = yield self.hs.get_replication_layer().get_public_rooms(
server_name, limit=limit, since_token=since_token, 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) defer.returnValue(res)
@ -329,3 +328,18 @@ class RoomListNextBatch(namedtuple("RoomListNextBatch", (
return self._replace( return self._replace(
**kwds **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

View File

@ -376,7 +376,7 @@ class EventFederationStore(SQLBaseStore):
INNER JOIN ( INNER JOIN (
SELECT room_id, MAX(stream_ordering) AS stream_ordering SELECT room_id, MAX(stream_ordering) AS stream_ordering
FROM stream_ordering_to_exterm FROM stream_ordering_to_exterm
WHERE stream_ordering < ? GROUP BY room_id WHERE stream_ordering <= ? GROUP BY room_id
) AS rms USING (room_id, stream_ordering) ) AS rms USING (room_id, stream_ordering)
WHERE room_id = ? WHERE room_id = ?
""") """)