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

Commit 7a87188

Browse files
committed
Add - module API method to create a room.
1 parent d548d8f commit 7a87188

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

synapse/module_api/__init__.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,65 @@ async def get_monthly_active_users_by_service(
14521452
start_timestamp, end_timestamp
14531453
)
14541454

1455+
async def create_room(
1456+
self,
1457+
user_id: str,
1458+
config: JsonDict,
1459+
ratelimit: bool = True,
1460+
creator_join_profile: Optional[JsonDict] = None,
1461+
) -> Tuple[dict, int]:
1462+
"""Creates a new room.
1463+
1464+
Args:
1465+
user_id:
1466+
The user who requested the room creation.
1467+
config : A dict of configuration options. See "Request body" of:
1468+
https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3createroom
1469+
ratelimit: set to False to disable the rate limiter.
1470+
1471+
creator_join_profile:
1472+
Set to override the displayname and avatar for the creating
1473+
user in this room. If unset, displayname and avatar will be
1474+
derived from the user's profile. If set, should contain the
1475+
values to go in the body of the 'join' event (typically
1476+
`avatar_url` and/or `displayname`.
1477+
1478+
Returns:
1479+
First, a dict containing the keys `room_id` and, if an alias
1480+
was, requested, `room_alias`. Secondly, the stream_id of the
1481+
last persisted event.
1482+
Raises:
1483+
SynapseError if the user does not exist, room ID couldn't be stored, or
1484+
something went horribly wrong.
1485+
ResourceLimitError if server is blocked to some resource being
1486+
exceeded.
1487+
"""
1488+
user_info = await self.get_userinfo_by_id(user_id)
1489+
if user_info is None:
1490+
raise SynapseError(400, f"User ({user_id}) not found")
1491+
1492+
if user_info.appservice_id is not None:
1493+
app_service = self._store.get_app_service_by_id(
1494+
str(user_info.appservice_id)
1495+
)
1496+
else:
1497+
app_service = None
1498+
1499+
requester = create_requester(
1500+
user_id=user_id,
1501+
is_guest=user_info.is_guest,
1502+
shadow_banned=user_info.is_shadow_banned,
1503+
app_service=app_service,
1504+
authenticated_entity=self.server_name,
1505+
)
1506+
1507+
return await self._hs.get_room_creation_handler().create_room(
1508+
requester=requester,
1509+
config=config,
1510+
ratelimit=ratelimit,
1511+
creator_join_profile=creator_join_profile,
1512+
)
1513+
14551514

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

0 commit comments

Comments
 (0)