From e4b078a6004ea34684c27056825346178c22aa0f Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 22 Feb 2019 12:11:43 +0000 Subject: [PATCH 01/14] Config option to prevent showing non-fed rooms in fed /publicRooms --- synapse/config/room_directory.py | 11 +++++++++++ synapse/handlers/room_list.py | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/synapse/config/room_directory.py b/synapse/config/room_directory.py index 9da13ab11b..08d1d26e58 100644 --- a/synapse/config/room_directory.py +++ b/synapse/config/room_directory.py @@ -27,6 +27,10 @@ class RoomDirectoryConfig(Config): for rule in alias_creation_rules ] + self.allow_non_federated_in_public_rooms = config.get( + "allow_non_federated_in_public_rooms", True, + ) + def default_config(self, config_dir_path, server_name, **kwargs): return """ # The `alias_creation` option controls who's allowed to create aliases @@ -42,6 +46,13 @@ class RoomDirectoryConfig(Config): - user_id: "*" alias: "*" action: allow + + # Specify whether rooms that only allow local users to join should be + # shown in the federation public room directory. + # + # Note that this does not affect the room directory shown to users on + # this homeserver, only those on other homeservers. + #allow_non_federated_in_public_rooms: True """ def is_alias_creation_allowed(self, user_id, alias): diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index dc88620885..47aeeb1d88 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -47,6 +47,7 @@ class RoomListHandler(BaseHandler): self.response_cache = ResponseCache(hs, "room_list") self.remote_response_cache = ResponseCache(hs, "remote_room_list", timeout_ms=30 * 1000) + self.config = hs.get_config() def get_local_public_room_list(self, limit=None, since_token=None, search_filter=None, @@ -286,14 +287,16 @@ class RoomListHandler(BaseHandler): # We've already got enough, so lets just drop it. return - result = yield self.generate_room_entry(room_id, num_joined_users) + result = yield self.generate_room_entry(room_id, num_joined_users, + allow_federated=self.config.allow_non_federated_in_public_rooms) if result and _matches_room_entry(result, search_filter): chunk.append(result) @cachedInlineCallbacks(num_args=1, cache_context=True) def generate_room_entry(self, room_id, num_joined_users, cache_context, - with_alias=True, allow_private=False): + with_alias=True, allow_private=False, + allow_federated=True): """Returns the entry for a room """ result = { @@ -308,6 +311,7 @@ class RoomListHandler(BaseHandler): event_map = yield self.store.get_events([ event_id for key, event_id in iteritems(current_state_ids) if key[0] in ( + EventTypes.Create, EventTypes.JoinRules, EventTypes.Name, EventTypes.Topic, @@ -324,12 +328,21 @@ class RoomListHandler(BaseHandler): } # Double check that this is actually a public room. + join_rules_event = current_state.get((EventTypes.JoinRules, "")) if join_rules_event: join_rule = join_rules_event.content.get("join_rule", None) if not allow_private and join_rule and join_rule != JoinRules.PUBLIC: defer.returnValue(None) + if not allow_federated: + # Disallow non-federated from appearing + create_event = current_state.get((EventTypes.Create, "")) + if create_event: + federate = create_event.content.get("m.federate", True) + if federate == False: + defer.returnValue(None) + if with_alias: aliases = yield self.store.get_aliases_for_room( room_id, on_invalidate=cache_context.invalidate From bd398b874eb375e92939a087a64258a4feb91f49 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 22 Feb 2019 15:43:11 +0000 Subject: [PATCH 02/14] Don't restrict non-fed rooms over client APIs --- synapse/federation/transport/server.py | 3 ++- synapse/groups/groups_server.py | 4 ++-- synapse/handlers/room_list.py | 29 ++++++++++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py index 7288d49074..6d4a26f595 100644 --- a/synapse/federation/transport/server.py +++ b/synapse/federation/transport/server.py @@ -697,7 +697,8 @@ class PublicRoomList(BaseFederationServlet): data = yield self.handler.get_local_public_room_list( limit, since_token, - network_tuple=network_tuple + network_tuple=network_tuple, + from_federation=True, ) defer.returnValue((200, data)) diff --git a/synapse/groups/groups_server.py b/synapse/groups/groups_server.py index 633c865ed8..691752a30c 100644 --- a/synapse/groups/groups_server.py +++ b/synapse/groups/groups_server.py @@ -113,7 +113,7 @@ class GroupsServerHandler(object): room_id = room_entry["room_id"] joined_users = yield self.store.get_users_in_room(room_id) entry = yield self.room_list_handler.generate_room_entry( - room_id, len(joined_users), + room_id, True, len(joined_users), with_alias=False, allow_private=True, ) entry = dict(entry) # so we don't change whats cached @@ -544,7 +544,7 @@ class GroupsServerHandler(object): joined_users = yield self.store.get_users_in_room(room_id) entry = yield self.room_list_handler.generate_room_entry( - room_id, len(joined_users), + room_id, True, len(joined_users), with_alias=False, allow_private=True, ) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 47aeeb1d88..bde9ec744f 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -51,7 +51,8 @@ class RoomListHandler(BaseHandler): def get_local_public_room_list(self, limit=None, since_token=None, search_filter=None, - network_tuple=EMPTY_THIRD_PARTY_ID,): + network_tuple=EMPTY_THIRD_PARTY_ID, + from_federation=False): """Generate a local public room list. There are multiple different lists: the main one plus one per third @@ -82,13 +83,15 @@ class RoomListHandler(BaseHandler): return self.response_cache.wrap( key, self._get_public_room_list, - limit, since_token, network_tuple=network_tuple, + limit, since_token, + network_tuple=network_tuple, from_federation=from_federation, ) @defer.inlineCallbacks def _get_public_room_list(self, limit=None, since_token=None, search_filter=None, - network_tuple=EMPTY_THIRD_PARTY_ID,): + network_tuple=EMPTY_THIRD_PARTY_ID, + from_federation=False,): if since_token and since_token != "END": since_token = RoomListNextBatch.from_token(since_token) else: @@ -208,7 +211,8 @@ class RoomListHandler(BaseHandler): yield concurrently_execute( lambda r: self._append_room_entry_to_chunk( r, rooms_to_num_joined[r], - chunk, limit, search_filter + chunk, limit, search_filter, + from_federation=from_federation, ), batch, 5, ) @@ -279,7 +283,7 @@ class RoomListHandler(BaseHandler): @defer.inlineCallbacks def _append_room_entry_to_chunk(self, room_id, num_joined_users, chunk, limit, - search_filter): + search_filter, from_federation=False): """Generate the entry for a room in the public room list and append it to the `chunk` if it matches the search filter """ @@ -287,16 +291,19 @@ class RoomListHandler(BaseHandler): # We've already got enough, so lets just drop it. return - result = yield self.generate_room_entry(room_id, num_joined_users, - allow_federated=self.config.allow_non_federated_in_public_rooms) + if from_federation: + result = yield self.generate_room_entry(room_id, + self.config.allow_non_federated_in_public_rooms, + num_joined_users) + else: + result = yield self.generate_room_entry(room_id, True, num_joined_users) if result and _matches_room_entry(result, search_filter): chunk.append(result) - @cachedInlineCallbacks(num_args=1, cache_context=True) - def generate_room_entry(self, room_id, num_joined_users, cache_context, - with_alias=True, allow_private=False, - allow_federated=True): + @cachedInlineCallbacks(num_args=2, cache_context=True) + def generate_room_entry(self, room_id, allow_federated, num_joined_users, + cache_context, with_alias=True, allow_private=False): """Returns the entry for a room """ result = { From 07493607a84665be006ec52f897eb904d923721c Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 25 Feb 2019 12:42:30 +0000 Subject: [PATCH 03/14] Docs and arg name clarification --- synapse/handlers/room_list.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index bde9ec744f..0636e5b8eb 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -302,9 +302,22 @@ class RoomListHandler(BaseHandler): chunk.append(result) @cachedInlineCallbacks(num_args=2, cache_context=True) - def generate_room_entry(self, room_id, allow_federated, num_joined_users, + def generate_room_entry(self, room_id, allow_non_federated, num_joined_users, cache_context, with_alias=True, allow_private=False): """Returns the entry for a room + + Args: + room_id (str): The room's ID. + allow_non_federated (bool): Whether rooms with federation + disabled should be shown. + num_joined_users (int): Number of users in the room. + cache_context: Information for cached responses. + with_alias (bool): Whether to return the room's aliases in the result. + allow_private (bool): Whether invite-only rooms should be shown. + + Returns: + Deferred[dict|None]: Returns a room entry as a dictionary, or None if this + room was determined not to be shown publicly. """ result = { "room_id": room_id, @@ -342,7 +355,7 @@ class RoomListHandler(BaseHandler): if not allow_private and join_rule and join_rule != JoinRules.PUBLIC: defer.returnValue(None) - if not allow_federated: + if not allow_non_federated: # Disallow non-federated from appearing create_event = current_state.get((EventTypes.Create, "")) if create_event: From 84c0a20dfeb043f1113a6e213bc7488ef21a0432 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 25 Feb 2019 15:23:27 +0000 Subject: [PATCH 04/14] Simplify call to generate_room_entry --- synapse/handlers/room_list.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 810c624c2b..69b0bc3dd1 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -300,24 +300,24 @@ class RoomListHandler(BaseHandler): # We've already got enough, so lets just drop it. return - if from_federation: - result = yield self.generate_room_entry(room_id, - self.config.allow_non_federated_in_public_rooms, - num_joined_users) - else: - result = yield self.generate_room_entry(room_id, True, num_joined_users) + result = yield self.generate_room_entry(room_id, + num_joined_users) - if result and _matches_room_entry(result, search_filter): + if from_federation and not self.config.allow_non_federated_in_public_rooms: + if result["m.federate"] = False: + # This is a non-federating room and the config has chosen not + # to show these rooms to other servers + chunk.append(None) + else if result and _matches_room_entry(result, search_filter): chunk.append(result) @cachedInlineCallbacks(num_args=2, cache_context=True) - def generate_room_entry(self, room_id, allow_non_federated, num_joined_users, + def generate_room_entry(self, room_id, num_joined_users, cache_context, with_alias=True, allow_private=False): """Returns the entry for a room Args: room_id (str): The room's ID. - allow_non_federated (bool): Whether rooms with federation disabled should be shown. num_joined_users (int): Number of users in the room. cache_context: Information for cached responses. @@ -364,13 +364,9 @@ class RoomListHandler(BaseHandler): if not allow_private and join_rule and join_rule != JoinRules.PUBLIC: defer.returnValue(None) - if not allow_non_federated: - # Disallow non-federated from appearing - create_event = current_state.get((EventTypes.Create, "")) - if create_event: - federate = create_event.content.get("m.federate", True) - if federate == False: - defer.returnValue(None) + # Return whether this room is open to federation users or not + create_event = current_state.get((EventTypes.Create, "")) + result["m.federate"] = create_event.content.get("m.federate", True) if with_alias: aliases = yield self.store.get_aliases_for_room( From 8aaf7ffc4415e9f7da2d34448b29fb2d0cb80574 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 25 Feb 2019 15:27:17 +0000 Subject: [PATCH 05/14] syntax derp --- synapse/handlers/room_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 69b0bc3dd1..b7f450e719 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -304,7 +304,7 @@ class RoomListHandler(BaseHandler): num_joined_users) if from_federation and not self.config.allow_non_federated_in_public_rooms: - if result["m.federate"] = False: + if result["m.federate"] == False: # This is a non-federating room and the config has chosen not # to show these rooms to other servers chunk.append(None) From 1330aa4a8fdff5f6d1ff4bc5d27de674dfcd67e7 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 25 Feb 2019 17:28:19 +0000 Subject: [PATCH 06/14] elif not else if --- synapse/handlers/room_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index b7f450e719..94cabc2a2e 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -308,7 +308,7 @@ class RoomListHandler(BaseHandler): # This is a non-federating room and the config has chosen not # to show these rooms to other servers chunk.append(None) - else if result and _matches_room_entry(result, search_filter): + elif result and _matches_room_entry(result, search_filter): chunk.append(result) @cachedInlineCallbacks(num_args=2, cache_context=True) From 96c408273e3ed8fd18ca3f7530820a02c06c42c1 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Mon, 25 Feb 2019 18:00:17 +0000 Subject: [PATCH 07/14] Fix group's call to generate_room_entry --- synapse/groups/groups_server.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/synapse/groups/groups_server.py b/synapse/groups/groups_server.py index 691752a30c..a7eaead56b 100644 --- a/synapse/groups/groups_server.py +++ b/synapse/groups/groups_server.py @@ -113,8 +113,7 @@ class GroupsServerHandler(object): room_id = room_entry["room_id"] joined_users = yield self.store.get_users_in_room(room_id) entry = yield self.room_list_handler.generate_room_entry( - room_id, True, len(joined_users), - with_alias=False, allow_private=True, + room_id, len(joined_users), with_alias=False, allow_private=True, ) entry = dict(entry) # so we don't change whats cached entry.pop("room_id", None) @@ -544,8 +543,7 @@ class GroupsServerHandler(object): joined_users = yield self.store.get_users_in_room(room_id) entry = yield self.room_list_handler.generate_room_entry( - room_id, True, len(joined_users), - with_alias=False, allow_private=True, + room_id, len(joined_users), with_alias=False, allow_private=True, ) if not entry: From 71669a0fba524e4d8cdb9e0076dca5d2770ef788 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 26 Feb 2019 11:25:00 +0000 Subject: [PATCH 08/14] Address rich comments --- synapse/handlers/room_list.py | 36 +++++++++++++++++++++++++++++------ synapse/server.pyi | 2 +- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 94cabc2a2e..a9725ade37 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -97,7 +97,23 @@ class RoomListHandler(BaseHandler): def _get_public_room_list(self, limit=None, since_token=None, search_filter=None, network_tuple=EMPTY_THIRD_PARTY_ID, - from_federation=False, timeout=None,): + from_federation=False, + timeout=None,): + """Generate a public room list. + + Args: + limit (int): Maximum amount of rooms to return. + since_token (str) + search_filter (dict): Dictionary to filter rooms by. + network_tuple (ThirdPartyInstanceID): Which public list to use. + This can be (None, None) to indicate the main list, or a particular + appservice and network id to use an appservice specific one. + Setting to None returns all public rooms across all lists. + from_federation (bool): Whether this request originated from a + federating server or a client. Used for room filtering. + timeout (int): Amount of seconds to wait for a response before + timing out. + """ if since_token and since_token != "END": since_token = RoomListNextBatch.from_token(since_token) else: @@ -295,19 +311,28 @@ class RoomListHandler(BaseHandler): search_filter, from_federation=False): """Generate the entry for a room in the public room list and append it to the `chunk` if it matches the search filter + + Args: + room_id (str): The ID of the room. + num_joined_users (int): The number of joined users in the room. + chunk (list) + limit (int): Maximum amount of rooms to display. Function will + return if length of chunk is greater than limit + 1. + search_filter (dict) + from_federation (bool): Whether this request originated from a + federating server or a client. Used for room filtering. """ if limit and len(chunk) > limit + 1: # We've already got enough, so lets just drop it. return - result = yield self.generate_room_entry(room_id, - num_joined_users) + result = yield self.generate_room_entry(room_id, num_joined_users) if from_federation and not self.config.allow_non_federated_in_public_rooms: - if result["m.federate"] == False: + if result["m.federate"] is False: # This is a non-federating room and the config has chosen not # to show these rooms to other servers - chunk.append(None) + return elif result and _matches_room_entry(result, search_filter): chunk.append(result) @@ -318,7 +343,6 @@ class RoomListHandler(BaseHandler): Args: room_id (str): The room's ID. - disabled should be shown. num_joined_users (int): Number of users in the room. cache_context: Information for cached responses. with_alias (bool): Whether to return the room's aliases in the result. diff --git a/synapse/server.pyi b/synapse/server.pyi index 06cd083a74..fb8df56cd5 100644 --- a/synapse/server.pyi +++ b/synapse/server.pyi @@ -7,9 +7,9 @@ import synapse.handlers.auth import synapse.handlers.deactivate_account import synapse.handlers.device import synapse.handlers.e2e_keys +import synapse.handlers.message import synapse.handlers.room import synapse.handlers.room_member -import synapse.handlers.message import synapse.handlers.set_password import synapse.rest.media.v1.media_repository import synapse.server_notices.server_notices_manager From 6946c20111cb7c460deb340b61236dce9f4fd878 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 26 Feb 2019 11:27:19 +0000 Subject: [PATCH 09/14] Result may be None --- synapse/handlers/room_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index a9725ade37..7c21f142a0 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -329,7 +329,7 @@ class RoomListHandler(BaseHandler): result = yield self.generate_room_entry(room_id, num_joined_users) if from_federation and not self.config.allow_non_federated_in_public_rooms: - if result["m.federate"] is False: + if not result or result["m.federate"] is False: # This is a non-federating room and the config has chosen not # to show these rooms to other servers return From 6728bf39405c52e4f2473c1e19a7648134361c15 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 26 Feb 2019 11:52:52 +0000 Subject: [PATCH 10/14] Make not showing non-federated rooms the default --- synapse/config/room_directory.py | 12 ------------ synapse/handlers/room_list.py | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/synapse/config/room_directory.py b/synapse/config/room_directory.py index 3322cf2eea..9b897abe3c 100644 --- a/synapse/config/room_directory.py +++ b/synapse/config/room_directory.py @@ -52,10 +52,6 @@ class RoomDirectoryConfig(Config): ) ] - self.allow_non_federated_in_public_rooms = config.get( - "allow_non_federated_in_public_rooms", True, - ) - def default_config(self, config_dir_path, server_name, **kwargs): return """ # The `alias_creation` option controls who's allowed to create aliases @@ -114,14 +110,6 @@ class RoomDirectoryConfig(Config): # alias: "*" # room_id: "*" # action: allow - - # Specify whether rooms that only allow local users to join should be - # shown in the federation public room directory. - # - # Note that this does not affect the room directory shown to users on - # this homeserver, only those on other homeservers. - # - #allow_non_federated_in_public_rooms: True """ def is_alias_creation_allowed(self, user_id, room_id, alias): diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 7c21f142a0..f1a51a7ca9 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -328,7 +328,7 @@ class RoomListHandler(BaseHandler): result = yield self.generate_room_entry(room_id, num_joined_users) - if from_federation and not self.config.allow_non_federated_in_public_rooms: + if from_federation: if not result or result["m.federate"] is False: # This is a non-federating room and the config has chosen not # to show these rooms to other servers From 40c2271680501c5ca2c29349d62df42d80b953db Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 26 Feb 2019 12:04:34 +0000 Subject: [PATCH 11/14] Clean up room chunk logic --- synapse/handlers/room_list.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index f1a51a7ca9..e6038a1069 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -327,13 +327,15 @@ class RoomListHandler(BaseHandler): return result = yield self.generate_room_entry(room_id, num_joined_users) + if not result: + return - if from_federation: - if not result or result["m.federate"] is False: - # This is a non-federating room and the config has chosen not - # to show these rooms to other servers - return - elif result and _matches_room_entry(result, search_filter): + if from_federation and result["m.federate"] is False: + # This is a room that other servers cannot join. Do not show them + # this room. + return + + if _matches_room_entry(result, search_filter): chunk.append(result) @cachedInlineCallbacks(num_args=2, cache_context=True) From 16565e67dbc81ddf5fc16d39f82accbd508ac13f Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 26 Feb 2019 12:12:48 +0000 Subject: [PATCH 12/14] Correct docstring types and chunk logic --- synapse/handlers/room_list.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index e6038a1069..7ab8476680 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -59,9 +59,9 @@ class RoomListHandler(BaseHandler): party network. A client can ask for a specific list or to return all. Args: - limit (int) - since_token (str) - search_filter (dict) + limit (int|None) + since_token (str|None) + search_filter (dict|None) network_tuple (ThirdPartyInstanceID): Which public list to use. This can be (None, None) to indicate the main list, or a particular appservice and network id to use an appservice specific one. @@ -102,16 +102,16 @@ class RoomListHandler(BaseHandler): """Generate a public room list. Args: - limit (int): Maximum amount of rooms to return. - since_token (str) - search_filter (dict): Dictionary to filter rooms by. + limit (int|None): Maximum amount of rooms to return. + since_token (str|None) + search_filter (dict|None): Dictionary to filter rooms by. network_tuple (ThirdPartyInstanceID): Which public list to use. This can be (None, None) to indicate the main list, or a particular appservice and network id to use an appservice specific one. Setting to None returns all public rooms across all lists. from_federation (bool): Whether this request originated from a federating server or a client. Used for room filtering. - timeout (int): Amount of seconds to wait for a response before + timeout (int|None): Amount of seconds to wait for a response before timing out. """ if since_token and since_token != "END": @@ -316,9 +316,9 @@ class RoomListHandler(BaseHandler): room_id (str): The ID of the room. num_joined_users (int): The number of joined users in the room. chunk (list) - limit (int): Maximum amount of rooms to display. Function will + limit (int|None): Maximum amount of rooms to display. Function will return if length of chunk is greater than limit + 1. - search_filter (dict) + search_filter (dict|None) from_federation (bool): Whether this request originated from a federating server or a client. Used for room filtering. """ @@ -330,7 +330,8 @@ class RoomListHandler(BaseHandler): if not result: return - if from_federation and result["m.federate"] is False: + if from_federation: + if "m.federate" in result and not result["m.federate"]: # This is a room that other servers cannot join. Do not show them # this room. return From a712aa3a9c5c58eca6ecfa0cb23636035fbbf449 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 26 Feb 2019 12:13:55 +0000 Subject: [PATCH 13/14] Correct indent --- synapse/handlers/room_list.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 7ab8476680..0ce274e9ae 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -332,9 +332,9 @@ class RoomListHandler(BaseHandler): if from_federation: if "m.federate" in result and not result["m.federate"]: - # This is a room that other servers cannot join. Do not show them - # this room. - return + # This is a room that other servers cannot join. Do not show them + # this room. + return if _matches_room_entry(result, search_filter): chunk.append(result) From c4414768af5e2213b1ad2b16bc8e1b8062fd1e49 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 26 Feb 2019 12:22:34 +0000 Subject: [PATCH 14/14] Cleaner chunk logic --- synapse/handlers/room_list.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index 0ce274e9ae..c02fedcfe4 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -330,11 +330,10 @@ class RoomListHandler(BaseHandler): if not result: return - if from_federation: - if "m.federate" in result and not result["m.federate"]: - # This is a room that other servers cannot join. Do not show them - # this room. - return + if from_federation and not result.get("m.federate", True): + # This is a room that other servers cannot join. Do not show them + # this room. + return if _matches_room_entry(result, search_filter): chunk.append(result)