Commit 8caba055 authored by Lars Kruse's avatar Lars Kruse
Browse files

feat(matrix_chat): remove upload of room avatar

The previous implementation specified the room avatar via an https-URL
(pointing to the media published by grouprise).
But the most commonly used Matrix client (element) uses only "mxc://"
URLs.  These are based on file uploads to the Matrix server.
It would be rather hard to synchronize avatars due to this storage
layer, since we cannot determine, whether an avatar needs an update or
not.

Thus we do not support the synchronization of avatar images between the
grouprise group and the corresponding Matrix rooms for now.
parent 80a20b07
......@@ -69,34 +69,7 @@ class MatrixBot:
except MatrixError as exc:
logger.error(f"Failed to synchronize room: {exc}")
continue
avatar_changed = False
if group.avatar:
grouprise_avatar_url = full_url(group.avatar_64.url)
response = await self.client.room_get_state_event(
room.room_id, "m.room.avatar"
)
if isinstance(response, nio.responses.RoomGetStateEventResponse):
current_matrix_avatar_url = response.content.get("url")
elif isinstance(response, nio.responses.RoomGetStateEventError) and (
response.status_code == "M_NOT_FOUND"
):
current_matrix_avatar_url = None
else:
logger.warning(
f"Failed to retrieve current avatar of group '{group}': {response}"
)
continue
if current_matrix_avatar_url != grouprise_avatar_url:
response = await self.client.room_put_state(
room.room_id, "m.room.avatar", {"url": grouprise_avatar_url}
)
if isinstance(response, nio.responses.RoomPutStateResponse):
avatar_changed = True
else:
logger.warning(
f"Failed to update avatar for room '{room}': {response}"
)
if created or avatar_changed:
if created:
yield room
async def _get_or_create_room(self, group, is_private):
......
......@@ -17,9 +17,10 @@ logger = logging.getLogger(__name__)
@receiver(post_save, sender=grouprise.features.groups.models.Group)
@db_task()
def update_matrix_rooms_for_group(sender, instance, created, update_fields, **kwargs):
if created or (update_fields and "logo" in update_fields):
def update_matrix_rooms_for_group(sender, instance, created, **kwargs):
if created:
_sync_rooms_delayed(instance)
@db_task()
def _sync_rooms_delayed(group):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment