From 76327354779e2b9f961686a94c474dd1c5232847 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Fri, 17 Mar 2023 17:03:43 +0100 Subject: [PATCH] neon: Always call push notification received handler --- packages/neon/lib/src/utils/push_utils.dart | 107 ++++++++++---------- 1 file changed, 52 insertions(+), 55 deletions(-) diff --git a/packages/neon/lib/src/utils/push_utils.dart b/packages/neon/lib/src/utils/push_utils.dart index 2ed47a5f..df9bbcdb 100644 --- a/packages/neon/lib/src/utils/push_utils.dart +++ b/packages/neon/lib/src/utils/push_utils.dart @@ -64,67 +64,64 @@ class PushUtils { if (notification.subject.delete ?? false) { await localNotificationsPlugin.cancel(_getNotificationID(instance, notification)); - return; - } - if (notification.subject.deleteAll ?? false) { + } else if (notification.subject.deleteAll ?? false) { await localNotificationsPlugin.cancelAll(); - return; - } - if (notification.type == 'background') { + Global.onPushNotificationReceived?.call(instance); + } else if (notification.type == 'background') { debugPrint('Got unknown background notification ${json.encode(notification.toJson())}'); - return; - } - - final localizations = await appLocalizationsFromSystem(); - - final platform = await getNeonPlatform(); - final cache = Cache(platform); - await cache.init(); - final requestManager = RequestManager(cache); - final allAppImplementations = getAppImplementations(sharedPreferences, requestManager, platform); - - final matchingAppImplementations = - allAppImplementations.where((final a) => a.id == notification.subject.app).toList(); - late AppImplementation app; - if (matchingAppImplementations.isNotEmpty) { - app = matchingAppImplementations.single; } else { - app = allAppImplementations.singleWhere((final a) => a.id == 'notifications'); - } - - final appName = app.nameFromLocalization(localizations); + final localizations = await appLocalizationsFromSystem(); + + final platform = await getNeonPlatform(); + final cache = Cache(platform); + await cache.init(); + final requestManager = RequestManager(cache); + final allAppImplementations = getAppImplementations(sharedPreferences, requestManager, platform); + + final matchingAppImplementations = + allAppImplementations.where((final a) => a.id == notification.subject.app).toList(); + late AppImplementation app; + if (matchingAppImplementations.isNotEmpty) { + app = matchingAppImplementations.single; + } else { + app = allAppImplementations.singleWhere((final a) => a.id == 'notifications'); + } - await localNotificationsPlugin.show( - _getNotificationID(instance, notification), - appName, - notification.subject.subject, - NotificationDetails( - android: AndroidNotificationDetails( - app.id, - appName, - groupKey: 'app_${app.id}', - icon: '@mipmap/app_${app.id}', - color: themePrimaryColor, - category: notification.type == 'voip' ? AndroidNotificationCategory.call : null, - importance: Importance.max, - priority: notification.priority == 'high' - ? (notification.type == 'voip' ? Priority.max : Priority.high) - : Priority.defaultPriority, + final appName = app.nameFromLocalization(localizations); + + await localNotificationsPlugin.show( + _getNotificationID(instance, notification), + appName, + notification.subject.subject, + NotificationDetails( + android: AndroidNotificationDetails( + app.id, + appName, + groupKey: 'app_${app.id}', + icon: '@mipmap/app_${app.id}', + color: themePrimaryColor, + category: notification.type == 'voip' ? AndroidNotificationCategory.call : null, + importance: Importance.max, + priority: notification.priority == 'high' + ? (notification.type == 'voip' ? Priority.max : Priority.high) + : Priority.defaultPriority, + ), + linux: LinuxNotificationDetails( + icon: AssetsLinuxIcon('assets/apps/${app.id}.svg'), + urgency: + notification.type == 'voip' ? LinuxNotificationUrgency.critical : LinuxNotificationUrgency.normal, + ), ), - linux: LinuxNotificationDetails( - icon: AssetsLinuxIcon('assets/apps/${app.id}.svg'), - urgency: notification.type == 'voip' ? LinuxNotificationUrgency.critical : LinuxNotificationUrgency.normal, + payload: json.encode( + PushNotification( + accountID: instance, + priority: notification.priority, + type: notification.type, + subject: notification.subject, + ).toJson(), ), - ), - payload: json.encode( - PushNotification( - accountID: instance, - priority: notification.priority, - type: notification.type, - subject: notification.subject, - ).toJson(), - ), - ); + ); + } Global.onPushNotificationReceived?.call(instance); }