From 6633ebc376c7e37525ce454721de04e8d0c0f18d Mon Sep 17 00:00:00 2001 From: Malin Errenst Date: Wed, 28 Jun 2023 11:28:07 +0200 Subject: [PATCH] feat: Added grouping to message notification channels --- lib/utils/push_helper.dart | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/utils/push_helper.dart b/lib/utils/push_helper.dart index 16cd0f0e..b5111c4c 100644 --- a/lib/utils/push_helper.dart +++ b/lib/utils/push_helper.dart @@ -198,11 +198,33 @@ Future _tryPushHelper( final roomName = event.room.getLocalizedDisplayname(MatrixLocals(l10n)); + final notificationGroupId = + event.room.isDirectChat ? 'directChats' : 'groupChats'; + final groupName = event.room.isDirectChat ? l10n.directChats : l10n.groups; + + final messageRooms = AndroidNotificationChannelGroup( + notificationGroupId, + groupName, + ); + final roomsChannel = AndroidNotificationChannel( + event.room.id, + roomName, + groupId: notificationGroupId, + ); + + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.createNotificationChannelGroup(messageRooms); + await flutterLocalNotificationsPlugin + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.createNotificationChannel(roomsChannel); + final androidPlatformChannelSpecifics = AndroidNotificationDetails( event.room.id, roomName, - channelDescription: - event.room.isDirectChat ? l10n.directChats : l10n.groups, + channelDescription: groupName, number: notification.counts?.unread, category: AndroidNotificationCategory.message, styleInformation: messagingStyleInformation ?? @@ -215,7 +237,7 @@ Future _tryPushHelper( ticker: l10n.unreadChats(notification.counts?.unread ?? 1), importance: Importance.max, priority: Priority.max, - groupKey: event.room.id, + groupKey: notificationGroupId, ); const iOSPlatformChannelSpecifics = DarwinNotificationDetails(); final platformChannelSpecifics = NotificationDetails(