summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <olivier@librepush.net>2019-07-24 11:29:51 +0100
committerOlivier Wilkinson (reivilibre) <olivier@librepush.net>2019-08-30 16:49:21 +0100
commit295b1de9e6315767da781683381e5bb34705a3dd (patch)
treeafb010260d911ac48d88dba39a2e5bb90723ac10
parentUse room_stats and room_state for room directory search (diff)
downloadsynapse-295b1de9e6315767da781683381e5bb34705a3dd.tar.xz
Don't populate empty/null fields in publicRooms.
Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
-rw-r--r--synapse/handlers/room_list.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py
index 3d0e62ebaf..de5f5c63e8 100644
--- a/synapse/handlers/room_list.py
+++ b/synapse/handlers/room_list.py
@@ -152,17 +152,24 @@ class RoomListHandler(BaseHandler):
             network_tuple, search_filter, probing_limit, pagination_token, forwards
         )
 
-        results = [
-            {
-                "room_id": r["room_id"],
-                "name": r["name"],
-                "topic": r["topic"],
-                "canonical_alias": r["canonical_alias"],
-                "num_joined_members": r["joined_members"],
-                "avatar_url": r["avatar"],
-                "world_readable": r["history_visibility"] == "world_readable",
+        def build_room_entry(room):
+            entry = {
+                "room_id": room["room_id"],
+                "name": room["name"],
+                "topic": room["topic"],
+                "canonical_alias": room["canonical_alias"],
+                "num_joined_members": room["joined_members"],
+                "avatar_url": room["avatar"],
+                "world_readable": room["history_visibility"] == "world_readable",
+            }
+
+            # Filter out Nones – rather omit the field altogether
+            return {
+                k: v for k, v in entry.items() if v is not None
             }
-            for r in results
+
+        results = [
+            build_room_entry(r) for r in results
         ]
 
         response = {}
@@ -225,7 +232,10 @@ class RoomListHandler(BaseHandler):
             # populate search result entries with additional fields, namely
             # 'aliases' and 'guest_can_join'
             room_id = room["room_id"]
-            room["aliases"] = yield self.store.get_aliases_for_room(room_id)
+
+            aliases = yield self.store.get_aliases_for_room(room_id)
+            if aliases:
+                room["aliases"] = aliases
 
             state_ids = yield self.store.get_current_state_ids(room_id)
             guests_can_join = False