1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 02:06:52 +00:00

Define rooms avatar

This commit is contained in:
Yohann D'ANELLO 2020-10-29 23:57:29 +01:00
parent 79836f0d94
commit 971169fe2c
2 changed files with 14 additions and 2 deletions

View File

@ -46,6 +46,9 @@ class Command(BaseCommand):
preset=RoomPreset.public_chat,
)
Matrix.set_room_avatar("#annonces:correspondances-maths.fr", avatar_uri)
Matrix.set_room_avatar("#faq:correspondances-maths.fr", avatar_uri)
Matrix.set_room_power_level_event("#annonces:correspondances-maths.fr", "events_default", 50)
for r in Registration.objects.all():

View File

@ -74,8 +74,6 @@ class Matrix:
initial_state=(),
power_level_override: Optional[Dict[str, Any]] = None,
) -> Union[RoomCreateResponse, RoomCreateError]:
resp: Union[RoomCreateResponse, RoomCreateError]
client = await cls._get_client()
return await client.room_create(
visibility, alias, name, topic, room_version, federate, is_direct, preset, invite, initial_state,
@ -131,3 +129,14 @@ class Matrix:
else:
content[event] = power_level
return await client.room_put_state(room_id, "m.room.power_levels", content=content, state_key=resp.state_key)
@classmethod
@async_to_sync
async def set_room_avatar(cls, room_id: str, avatar_uri: str)\
-> Union[RoomPutStateResponse, RoomPutStateError]:
client = await cls._get_client()
if room_id.startswith("#"):
room_id = await cls.resolve_room_alias(room_id)
return await client.room_put_state(room_id, "m.room.avatar", content={
"url": avatar_uri
}, state_key="")