Merge pull request #2648 from krille-chan/krille/use-correct-person-for-android-notification-reply

fix: Use correct own person for android notification replies
This commit is contained in:
Krille-chan 2026-03-05 10:09:59 +01:00 committed by GitHub
commit 127c3fd7bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 124 deletions

View file

@ -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<void> 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>[
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(),
);
}
}
}
}

View file

@ -162,43 +162,15 @@ Future<void> _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<void> _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<void> _setShortcut(
),
);
}
extension on Client {
Future<Uint8List?> 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;
}
}
}