Skip to content

Commit

Permalink
feat(matrix_chat): remove upload of room avatar
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sumpfralle committed May 16, 2021
1 parent 99210e1 commit c94fb2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
29 changes: 1 addition & 28 deletions grouprise/features/matrix_chat/matrix_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions grouprise/features/matrix_chat/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c94fb2d

Please sign in to comment.