diff --git a/lib/utils/push_helper.dart b/lib/utils/push_helper.dart index 591549e9..7ca810a8 100644 --- a/lib/utils/push_helper.dart +++ b/lib/utils/push_helper.dart @@ -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 pushHelper( PushNotification notification, { @@ -53,6 +55,7 @@ Future 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 _tryPushHelper( ), importance: Importance.high, priority: Priority.max, - groupKey: event.room.spaceParents.firstOrNull?.roomId ?? 'rooms', + groupKey: groupKey, actions: event.type == EventTypes.RoomMember || !useNotificationActions ? null : [ @@ -300,6 +303,40 @@ Future _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!'); }