diff --git a/synapse/config/server.py b/synapse/config/server.py index 1b8968608..2913f64dd 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -178,6 +178,12 @@ class ServerConfig(Config): # events with profile information that differ from the target's global profile. self.allow_per_room_profiles = config.get("allow_per_room_profiles", True) + # Whether to show the users on this homeserver in the user directory. Defaults to + # True. + self.show_users_in_user_directory = config.get( + "show_users_in_user_directory", True, + ) + self.listeners = [] for listener in config.get("listeners", []): if not isinstance(listener.get("port", None), int): @@ -577,6 +583,11 @@ class ServerConfig(Config): # Defaults to 'true'. # #allow_per_room_profiles: false + + # Whether to show the users on this homeserver in the user directory. Defaults to + # 'true'. + # + #show_users_in_user_directory: false """ % locals() def read_arguments(self, args): diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 68d87163a..bd8f522fa 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -74,6 +74,8 @@ class RegistrationHandler(BaseHandler): ) self._server_notices_mxid = hs.config.server_notices_mxid + self._show_in_user_directory = self.hs.show_users_in_user_directory + if hs.config.worker_app: self._register_client = ReplicationRegisterServlet.make_client(hs) self._register_device_client = ( @@ -289,6 +291,14 @@ class RegistrationHandler(BaseHandler): user_id, threepid_dict, None, False, ) + # Prevent the new user from showing up in the user directory if the server + # mandates it. + if self._show_in_user_directory: + yield self.store.add_account_data_for_user( + user_id, "im.vector.hide_profile", {'hide_profile': True}, + ) + yield self.profile_handler.set_active(user, False, True) + defer.returnValue((user_id, token)) @defer.inlineCallbacks