Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add module API method to create a room #13429

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13429.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a module API method to create a room.
59 changes: 59 additions & 0 deletions synapse/module_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,65 @@ async def get_monthly_active_users_by_service(
start_timestamp, end_timestamp
)

async def create_room(
self,
user_id: str,
config: JsonDict,
ratelimit: bool = True,
creator_join_profile: Optional[JsonDict] = None,
) -> Tuple[dict, int]:
"""Creates a new room.

Args:
user_id:
The user who requested the room creation.
config : A dict of configuration options. See "Request body" of:
https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3createroom
ratelimit: set to False to disable the rate limiter.

creator_join_profile:
Set to override the displayname and avatar for the creating
user in this room. If unset, displayname and avatar will be
derived from the user's profile. If set, should contain the
values to go in the body of the 'join' event (typically
`avatar_url` and/or `displayname`.

Returns:
First, a dict containing the keys `room_id` and, if an alias
was, requested, `room_alias`. Secondly, the stream_id of the
last persisted event.
Raises:
SynapseError if the user does not exist, room ID couldn't be stored, or
something went horribly wrong.
ResourceLimitError if server is blocked to some resource being
exceeded.
"""
user_info = await self.get_userinfo_by_id(user_id)
if user_info is None:
raise SynapseError(400, f"User ({user_id}) not found")

if user_info.appservice_id is not None:
app_service = self._store.get_app_service_by_id(
str(user_info.appservice_id)
)
else:
app_service = None

requester = create_requester(
user_id=user_id,
is_guest=user_info.is_guest,
shadow_banned=user_info.is_shadow_banned,
app_service=app_service,
authenticated_entity=self.server_name,
)

return await self._hs.get_room_creation_handler().create_room(
requester=requester,
config=config,
ratelimit=ratelimit,
creator_join_profile=creator_join_profile,
)


class PublicRoomListManager:
"""Contains methods for adding to, removing from and querying whether a room
Expand Down