Simplify room creation code

This commit is contained in:
Daniel Wagner-Hall 2016-02-15 18:13:10 +00:00
parent 4de08a4672
commit e560045cfd
2 changed files with 31 additions and 55 deletions

View File

@ -81,20 +81,20 @@ class RoomCreationHandler(BaseHandler):
}
@defer.inlineCallbacks
def create_room(self, user_id, room_id, config):
def create_room(self, requester, config):
""" Creates a new room.
Args:
user_id (str): The ID of the user creating the new room.
room_id (str): The proposed ID for the new room. Can be None, in
which case one will be created for you.
requester (Requester): The user who requested the room creation.
config (dict) : A dict of configuration options.
Returns:
The new room ID.
Raises:
SynapseError if the room ID was taken, couldn't be stored, or
something went horribly wrong.
SynapseError if the room ID couldn't be stored, or something went
horribly wrong.
"""
user_id = requester.user.to_string()
self.ratelimit(user_id)
if "room_alias_name" in config:
@ -126,18 +126,6 @@ class RoomCreationHandler(BaseHandler):
is_public = config.get("visibility", None) == "public"
if room_id:
# Ensure room_id is the correct type
room_id_obj = RoomID.from_string(room_id)
if not self.hs.is_mine(room_id_obj):
raise SynapseError(400, "Room id must be local")
yield self.store.store_room(
room_id=room_id,
room_creator_user_id=user_id,
is_public=is_public
)
else:
# autogen room IDs and try to create it. We may clash, so just
# try a few times till one goes through, giving up eventually.
attempts = 0

View File

@ -63,24 +63,12 @@ class RoomCreateRestServlet(ClientV1RestServlet):
def on_POST(self, request):
requester = yield self.auth.get_user_by_req(request)
room_config = self.get_room_config(request)
info = yield self.make_room(
room_config,
requester.user,
None,
)
room_config.update(info)
defer.returnValue((200, info))
@defer.inlineCallbacks
def make_room(self, room_config, auth_user, room_id):
handler = self.handlers.room_creation_handler
info = yield handler.create_room(
user_id=auth_user.to_string(),
room_id=room_id,
config=room_config
requester, self.get_room_config(request)
)
defer.returnValue(info)
defer.returnValue((200, info))
def get_room_config(self, request):
try: