From c94fb2db07141db75dd4b340fd972ce854c9d971 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 7 Feb 2021 02:41:33 +0100 Subject: [PATCH] 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. --- grouprise/features/matrix_chat/matrix_bot.py | 29 +------------------- grouprise/features/matrix_chat/signals.py | 7 +++-- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/grouprise/features/matrix_chat/matrix_bot.py b/grouprise/features/matrix_chat/matrix_bot.py index 93d14faf0..e1ea960a8 100644 --- a/grouprise/features/matrix_chat/matrix_bot.py +++ b/grouprise/features/matrix_chat/matrix_bot.py @@ -69,34 +69,7 @@ async def synchronize_rooms_of_group(self, group): 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): diff --git a/grouprise/features/matrix_chat/signals.py b/grouprise/features/matrix_chat/signals.py index d4c294eab..708697a42 100644 --- a/grouprise/features/matrix_chat/signals.py +++ b/grouprise/features/matrix_chat/signals.py @@ -17,9 +17,10 @@ @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):