feat: Add Android summary notification

This commit is contained in:
krille-chan 2026-04-19 11:44:21 +09:00
commit 8e3f46eee6
No known key found for this signature in database

View file

@ -17,6 +17,8 @@ import 'package:flutter_shortcuts_new/flutter_shortcuts_new.dart';
import 'package:matrix/matrix.dart';
const notificationAvatarDimension = 128;
const String groupKey = 'im.fluffychat.messages';
const int summaryId = -1;
Future<void> pushHelper(
PushNotification notification, {
@ -53,6 +55,7 @@ Future<void> pushHelper(
AppSettings.applicationName.value,
(notification.counts?.unread ?? 0).toString(),
),
groupKey: groupKey,
importance: Importance.high,
priority: Priority.max,
shortcutId: notification.roomId,
@ -252,7 +255,7 @@ Future<void> _tryPushHelper(
),
importance: Importance.high,
priority: Priority.max,
groupKey: event.room.spaceParents.firstOrNull?.roomId ?? 'rooms',
groupKey: groupKey,
actions: event.type == EventTypes.RoomMember || !useNotificationActions
? null
: <AndroidNotificationAction>[
@ -300,6 +303,40 @@ Future<void> _tryPushHelper(
event.eventId,
).toString(),
);
// Send summary notification on Android
if (PlatformInfos.isAndroid) {
final activeNotifications =
(await flutterLocalNotificationsPlugin.getActiveNotifications())
.where((n) => n.groupKey == groupKey)
.toList();
if (activeNotifications.isEmpty) {
return;
}
final title = l10n.unreadChatsInApp(
AppSettings.applicationName.value,
activeNotifications.length.toString(),
);
await flutterLocalNotificationsPlugin.show(
id: summaryId,
notificationDetails: NotificationDetails(
android: AndroidNotificationDetails(
AppConfig.pushNotificationsChannelId,
l10n.incomingMessages,
groupKey: groupKey,
setAsGroupSummary: true,
styleInformation: InboxStyleInformation(
activeNotifications.map((n) => n.body ?? '').toList(),
contentTitle: title,
summaryText: title,
),
),
),
);
}
Logs().v('Push helper has been completed!');
}