From a0f78264299936d7979cf68dfa04211bc835a11a Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 13 Aug 2024 09:54:25 +0200 Subject: [PATCH] fix(neon_framework,neon_talk): Fix avatars not updating on brightness changes Signed-off-by: provokateurin --- .../neon_talk/lib/src/widgets/room_avatar.dart | 16 +++++++++++----- packages/neon/neon_talk/test/message_test.dart | 1 + .../neon/neon_talk/test/rich_object_test.dart | 1 + packages/neon/neon_talk/test/room_page_test.dart | 1 + .../lib/src/widgets/user_avatar.dart | 1 + 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/neon/neon_talk/lib/src/widgets/room_avatar.dart b/packages/neon/neon_talk/lib/src/widgets/room_avatar.dart index 9b6efcc0f10..1d3411fdd7f 100644 --- a/packages/neon/neon_talk/lib/src/widgets/room_avatar.dart +++ b/packages/neon/neon_talk/lib/src/widgets/room_avatar.dart @@ -24,17 +24,23 @@ class TalkRoomAvatar extends StatelessWidget { Widget build(BuildContext context) { if (room.isCustomAvatar) { final brightness = Theme.of(context).brightness; + final account = NeonProvider.of(context); return CircleAvatar( child: ClipOval( child: NeonApiImage( - getRequest: (client) => switch (brightness) { - Brightness.dark => client.spreed.avatar.$getAvatarDark_Request(token: room.token), - Brightness.light => client.spreed.avatar.$getAvatar_Request(token: room.token), - }, + key: Key('room-avatar-${account.id}-${room.token}-$brightness'), + account: account, etag: room.avatarVersion, expires: null, - account: NeonProvider.of(context), + getRequest: (client) => switch (brightness) { + Brightness.dark => client.spreed.avatar.$getAvatarDark_Request( + token: room.token, + ), + Brightness.light => client.spreed.avatar.$getAvatar_Request( + token: room.token, + ), + }, ), ), ); diff --git a/packages/neon/neon_talk/test/message_test.dart b/packages/neon/neon_talk/test/message_test.dart index 56dfec5086f..864ebad0274 100644 --- a/packages/neon/neon_talk/test/message_test.dart +++ b/packages/neon/neon_talk/test/message_test.dart @@ -1575,6 +1575,7 @@ void main() { .thenAnswer((_) => BehaviorSubject.seeded(Result.success(userDetails))); final account = MockAccount(); + when(() => account.id).thenReturn('id'); when(() => account.username).thenReturn('username'); when(() => account.client).thenReturn(NextcloudClient(Uri())); diff --git a/packages/neon/neon_talk/test/rich_object_test.dart b/packages/neon/neon_talk/test/rich_object_test.dart index f9b4f31ac85..1204e20f3d2 100644 --- a/packages/neon/neon_talk/test/rich_object_test.dart +++ b/packages/neon/neon_talk/test/rich_object_test.dart @@ -30,6 +30,7 @@ void main() { setUp(() { account = MockAccount(); + when(() => account.id).thenReturn('id'); when(() => account.username).thenReturn('username'); when(() => account.serverURL).thenReturn(Uri.parse('http://example.com')); when(() => account.client).thenReturn( diff --git a/packages/neon/neon_talk/test/room_page_test.dart b/packages/neon/neon_talk/test/room_page_test.dart index bce31613d2f..3a0e1f258b5 100644 --- a/packages/neon/neon_talk/test/room_page_test.dart +++ b/packages/neon/neon_talk/test/room_page_test.dart @@ -164,6 +164,7 @@ void main() { when(() => bloc.reactions).thenAnswer((_) => BehaviorSubject.seeded(BuiltMap())); final account = MockAccount(); + when(() => account.id).thenReturn('id'); when(() => account.client).thenReturn(NextcloudClient(Uri.parse(''))); await tester.pumpWidgetWithAccessibility( diff --git a/packages/neon_framework/lib/src/widgets/user_avatar.dart b/packages/neon_framework/lib/src/widgets/user_avatar.dart index 87c3d41f53a..497c864ae66 100644 --- a/packages/neon_framework/lib/src/widgets/user_avatar.dart +++ b/packages/neon_framework/lib/src/widgets/user_avatar.dart @@ -68,6 +68,7 @@ class _UserAvatarState extends State { radius: size / 2, child: ClipOval( child: NeonApiImage( + key: Key('avatar-${widget.account.id}-$username-$brightness-$pixelSize'), account: widget.account, etag: null, expires: null,