feat: Add Android summary notification
This commit is contained in:
parent
052c9065b8
commit
8e3f46eee6
1 changed files with 38 additions and 1 deletions
|
|
@ -17,6 +17,8 @@ import 'package:flutter_shortcuts_new/flutter_shortcuts_new.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
|
||||||
const notificationAvatarDimension = 128;
|
const notificationAvatarDimension = 128;
|
||||||
|
const String groupKey = 'im.fluffychat.messages';
|
||||||
|
const int summaryId = -1;
|
||||||
|
|
||||||
Future<void> pushHelper(
|
Future<void> pushHelper(
|
||||||
PushNotification notification, {
|
PushNotification notification, {
|
||||||
|
|
@ -53,6 +55,7 @@ Future<void> pushHelper(
|
||||||
AppSettings.applicationName.value,
|
AppSettings.applicationName.value,
|
||||||
(notification.counts?.unread ?? 0).toString(),
|
(notification.counts?.unread ?? 0).toString(),
|
||||||
),
|
),
|
||||||
|
groupKey: groupKey,
|
||||||
importance: Importance.high,
|
importance: Importance.high,
|
||||||
priority: Priority.max,
|
priority: Priority.max,
|
||||||
shortcutId: notification.roomId,
|
shortcutId: notification.roomId,
|
||||||
|
|
@ -252,7 +255,7 @@ Future<void> _tryPushHelper(
|
||||||
),
|
),
|
||||||
importance: Importance.high,
|
importance: Importance.high,
|
||||||
priority: Priority.max,
|
priority: Priority.max,
|
||||||
groupKey: event.room.spaceParents.firstOrNull?.roomId ?? 'rooms',
|
groupKey: groupKey,
|
||||||
actions: event.type == EventTypes.RoomMember || !useNotificationActions
|
actions: event.type == EventTypes.RoomMember || !useNotificationActions
|
||||||
? null
|
? null
|
||||||
: <AndroidNotificationAction>[
|
: <AndroidNotificationAction>[
|
||||||
|
|
@ -300,6 +303,40 @@ Future<void> _tryPushHelper(
|
||||||
event.eventId,
|
event.eventId,
|
||||||
).toString(),
|
).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!');
|
Logs().v('Push helper has been completed!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue