From c206a515156337ec59fd18d20ab3b40ea7a63f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Thu, 5 Mar 2026 09:09:27 +0100 Subject: [PATCH] fix: Use correct own person for android notification replies --- .../notification_background_handler.dart | 83 +------------------ lib/utils/push_helper.dart | 75 ++++++++--------- 2 files changed, 34 insertions(+), 124 deletions(-) diff --git a/lib/utils/notification_background_handler.dart b/lib/utils/notification_background_handler.dart index 6c257e9a1..c3d14eeb4 100644 --- a/lib/utils/notification_background_handler.dart +++ b/lib/utils/notification_background_handler.dart @@ -9,10 +9,7 @@ import 'package:go_router/go_router.dart'; import 'package:matrix/matrix.dart'; import 'package:fluffychat/l10n/l10n.dart'; -import 'package:fluffychat/utils/client_download_content_extension.dart'; import 'package:fluffychat/utils/client_manager.dart'; -import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_locals.dart'; -import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/utils/push_helper.dart'; import '../config/app_config.dart'; import '../config/setting_keys.dart'; @@ -172,89 +169,11 @@ Future notificationTap( ); } - final eventId = await room.sendTextEvent( + await room.sendTextEvent( input, parseCommands: false, displayPendingEvent: false, ); - - if (PlatformInfos.isAndroid) { - final ownProfile = await room.client.fetchOwnProfile(); - final avatar = ownProfile.avatarUrl; - final avatarFile = avatar == null - ? null - : await client - .downloadMxcCached( - avatar, - thumbnailMethod: ThumbnailMethod.crop, - width: notificationAvatarDimension, - height: notificationAvatarDimension, - animated: false, - isThumbnail: true, - rounded: true, - ) - .timeout(const Duration(seconds: 3)); - final messagingStyleInformation = - await AndroidFlutterLocalNotificationsPlugin() - .getActiveNotificationMessagingStyle(id: room.id.hashCode); - if (messagingStyleInformation == null) return; - l10n ??= await lookupL10n(PlatformDispatcher.instance.locale); - messagingStyleInformation.messages?.add( - Message( - input, - DateTime.now(), - Person( - key: room.client.userID, - name: l10n.you, - icon: avatarFile == null - ? null - : ByteArrayAndroidIcon(avatarFile), - ), - ), - ); - - await FlutterLocalNotificationsPlugin().show( - id: room.id.hashCode, - title: room.getLocalizedDisplayname(MatrixLocals(l10n)), - body: input, - notificationDetails: NotificationDetails( - android: AndroidNotificationDetails( - AppConfig.pushNotificationsChannelId, - l10n.incomingMessages, - category: AndroidNotificationCategory.message, - shortcutId: room.id, - styleInformation: messagingStyleInformation, - groupKey: room.id, - playSound: false, - enableVibration: false, - actions: [ - AndroidNotificationAction( - FluffyChatNotificationActions.reply.name, - l10n.reply, - inputs: [ - AndroidNotificationActionInput( - label: l10n.writeAMessage, - ), - ], - cancelNotification: false, - allowGeneratedReplies: true, - semanticAction: SemanticAction.reply, - ), - AndroidNotificationAction( - FluffyChatNotificationActions.markAsRead.name, - l10n.markAsRead, - semanticAction: SemanticAction.markAsRead, - ), - ], - ), - ), - payload: FluffyChatPushPayload( - client.clientName, - room.id, - eventId, - ).toString(), - ); - } } } } diff --git a/lib/utils/push_helper.dart b/lib/utils/push_helper.dart index 4b10623e3..097aaa55b 100644 --- a/lib/utils/push_helper.dart +++ b/lib/utils/push_helper.dart @@ -162,43 +162,15 @@ Future _tryPushHelper( ? avatar : event.senderFromMemoryOrFallback.avatarUrl; - Uint8List? roomAvatarFile, senderAvatarFile; - try { - roomAvatarFile = avatar == null - ? null - : await client - .downloadMxcCached( - avatar, - thumbnailMethod: ThumbnailMethod.crop, - width: notificationAvatarDimension, - height: notificationAvatarDimension, - animated: false, - isThumbnail: true, - rounded: true, - ) - .timeout(const Duration(seconds: 3)); - } catch (e, s) { - Logs().e('Unable to get avatar picture', e, s); - } - try { - senderAvatarFile = event.room.isDirectChat - ? roomAvatarFile - : senderAvatar == null - ? null - : await client - .downloadMxcCached( - senderAvatar, - thumbnailMethod: ThumbnailMethod.crop, - width: notificationAvatarDimension, - height: notificationAvatarDimension, - animated: false, - isThumbnail: true, - rounded: true, - ) - .timeout(const Duration(seconds: 3)); - } catch (e, s) { - Logs().e('Unable to get avatar picture', e, s); - } + final ownUser = event.room.unsafeGetUserFromMemoryOrFallback(client.userID!); + + final userAvatarFile = await client.tryDownloadNotificationAvatar( + ownUser.avatarUrl, + ); + final roomAvatarFile = await client.tryDownloadNotificationAvatar(avatar); + final senderAvatarFile = await client.tryDownloadNotificationAvatar( + senderAvatar, + ); final id = notification.roomId.hashCode; @@ -262,12 +234,11 @@ Future _tryPushHelper( messagingStyleInformation ?? MessagingStyleInformation( Person( - name: senderName, - icon: roomAvatarFile == null + name: ownUser.calcDisplayname(), + icon: userAvatarFile == null ? null - : ByteArrayAndroidIcon(roomAvatarFile), - key: event.roomId, - important: event.room.isFavourite, + : ByteArrayAndroidIcon(userAvatarFile), + key: event.room.client.userID, ), conversationTitle: event.room.isDirectChat ? null : roomName, groupConversation: !event.room.isDirectChat, @@ -372,3 +343,23 @@ Future _setShortcut( ), ); } + +extension on Client { + Future tryDownloadNotificationAvatar(Uri? avatar) async { + if (avatar == null) return null; + try { + return await downloadMxcCached( + avatar, + thumbnailMethod: ThumbnailMethod.crop, + width: notificationAvatarDimension, + height: notificationAvatarDimension, + animated: false, + isThumbnail: true, + rounded: true, + ).timeout(const Duration(seconds: 3)); + } catch (e, s) { + Logs().e('Unable to get avatar picture', e, s); + return null; + } + } +}