summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/register.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index da914c46ff..01cf7ab58e 100644
--- a/synapse/handlers/register.py
+++ b/synapse/handlers/register.py
@@ -220,8 +220,26 @@ 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
+        if self.hs.config.autocreate_auto_join_rooms:
+            count = yield self.store.count_all_users()
+            auto_create_rooms = count == 1
+
         for r in self.hs.config.auto_join_rooms:
             try:
+                if auto_create_rooms and RoomAlias.is_valid(r):
+                    room_creation_handler = self.hs.get_room_creation_handler()
+                    # create room expects the localpart of the room alias
+                    room_alias_localpart = RoomAlias.from_string(r).localpart
+                    yield room_creation_handler.create_room(
+                        fake_requester,
+                        config={
+                            "preset": "public_chat",
+                            "room_alias_name": room_alias_localpart
+                        },
+                        ratelimit=False,
+                    )
                 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)
@@ -513,6 +531,7 @@ class RegistrationHandler(BaseHandler):
 
     @defer.inlineCallbacks
     def _join_user_to_room(self, requester, room_identifier):
+
         room_id = None
         room_member_handler = self.hs.get_room_member_handler()
         if RoomID.is_valid(room_identifier):