diff options
author | Neil Johnson <neil@matrix.org> | 2018-10-25 15:00:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-25 15:00:40 +0100 |
commit | c99b6c66bf023af8f5aa4a7aaa04eac682ce3860 (patch) | |
tree | f6c28616c938cedecc18b7d8326cffa175c7395c /synapse/handlers/register.py | |
parent | oops, run the check_isort build (diff) | |
parent | Merge branch 'develop' of github.com:matrix-org/synapse into matthew/autocrea... (diff) | |
download | synapse-c99b6c66bf023af8f5aa4a7aaa04eac682ce3860.tar.xz |
Merge pull request #3975 from matrix-org/matthew/autocreate_autojoin
Autocreate autojoin rooms
Diffstat (limited to 'synapse/handlers/register.py')
-rw-r--r-- | synapse/handlers/register.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index da914c46ff..e9d7b25a36 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -50,6 +50,7 @@ class RegistrationHandler(BaseHandler): self._auth_handler = hs.get_auth_handler() self.profile_handler = hs.get_profile_handler() self.user_directory_handler = hs.get_user_directory_handler() + self.room_creation_handler = self.hs.get_room_creation_handler() self.captcha_client = CaptchaServerHttpClient(hs) self._next_generated_user_id = None @@ -220,9 +221,36 @@ class RegistrationHandler(BaseHandler): # auto-join the user to any rooms we're supposed to dump them into fake_requester = create_requester(user_id) + + # try to create the room if we're the first user on the server + should_auto_create_rooms = False + if self.hs.config.autocreate_auto_join_rooms: + count = yield self.store.count_all_users() + should_auto_create_rooms = count == 1 + for r in self.hs.config.auto_join_rooms: try: - yield self._join_user_to_room(fake_requester, r) + if should_auto_create_rooms: + room_alias = RoomAlias.from_string(r) + if self.hs.hostname != room_alias.domain: + logger.warning( + 'Cannot create room alias %s, ' + 'it does not match server domain', + r, + ) + else: + # create room expects the localpart of the room alias + room_alias_localpart = room_alias.localpart + yield self.room_creation_handler.create_room( + fake_requester, + config={ + "preset": "public_chat", + "room_alias_name": room_alias_localpart + }, + ratelimit=False, + ) + else: + yield self._join_user_to_room(fake_requester, r) except Exception as e: logger.error("Failed to join new user to %r: %r", r, e) |