Config option to prevent showing non-fed rooms in fed /publicRooms

This commit is contained in:
Andrew Morgan 2019-02-22 12:11:43 +00:00
parent 2712a9ef8f
commit ffa64f373a
2 changed files with 26 additions and 2 deletions

View file

@ -27,6 +27,10 @@ class RoomDirectoryConfig(Config):
for rule in alias_creation_rules 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): def default_config(self, config_dir_path, server_name, **kwargs):
return """ return """
# The `alias_creation` option controls who's allowed to create aliases # The `alias_creation` option controls who's allowed to create aliases
@ -42,6 +46,13 @@ class RoomDirectoryConfig(Config):
- user_id: "*" - user_id: "*"
alias: "*" alias: "*"
action: allow 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): def is_alias_creation_allowed(self, user_id, alias):

View file

@ -47,6 +47,7 @@ class RoomListHandler(BaseHandler):
self.response_cache = ResponseCache(hs, "room_list") self.response_cache = ResponseCache(hs, "room_list")
self.remote_response_cache = ResponseCache(hs, "remote_room_list", self.remote_response_cache = ResponseCache(hs, "remote_room_list",
timeout_ms=30 * 1000) timeout_ms=30 * 1000)
self.config = hs.get_config()
def get_local_public_room_list(self, limit=None, since_token=None, def get_local_public_room_list(self, limit=None, since_token=None,
search_filter=None, search_filter=None,
@ -286,14 +287,16 @@ class RoomListHandler(BaseHandler):
# We've already got enough, so lets just drop it. # We've already got enough, so lets just drop it.
return 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): if result and _matches_room_entry(result, search_filter):
chunk.append(result) chunk.append(result)
@cachedInlineCallbacks(num_args=1, cache_context=True) @cachedInlineCallbacks(num_args=1, cache_context=True)
def generate_room_entry(self, room_id, num_joined_users, cache_context, 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 """Returns the entry for a room
""" """
result = { result = {
@ -308,6 +311,7 @@ class RoomListHandler(BaseHandler):
event_map = yield self.store.get_events([ event_map = yield self.store.get_events([
event_id for key, event_id in iteritems(current_state_ids) event_id for key, event_id in iteritems(current_state_ids)
if key[0] in ( if key[0] in (
EventTypes.Create,
EventTypes.JoinRules, EventTypes.JoinRules,
EventTypes.Name, EventTypes.Name,
EventTypes.Topic, EventTypes.Topic,
@ -324,12 +328,21 @@ class RoomListHandler(BaseHandler):
} }
# Double check that this is actually a public room. # Double check that this is actually a public room.
join_rules_event = current_state.get((EventTypes.JoinRules, "")) join_rules_event = current_state.get((EventTypes.JoinRules, ""))
if join_rules_event: if join_rules_event:
join_rule = join_rules_event.content.get("join_rule", None) join_rule = join_rules_event.content.get("join_rule", None)
if not allow_private and join_rule and join_rule != JoinRules.PUBLIC: if not allow_private and join_rule and join_rule != JoinRules.PUBLIC:
defer.returnValue(None) 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: if with_alias:
aliases = yield self.store.get_aliases_for_room( aliases = yield self.store.get_aliases_for_room(
room_id, on_invalidate=cache_context.invalidate room_id, on_invalidate=cache_context.invalidate