|
|
@ -64,67 +64,64 @@ class PushUtils { |
|
|
|
|
|
|
|
|
|
|
|
if (notification.subject.delete ?? false) { |
|
|
|
if (notification.subject.delete ?? false) { |
|
|
|
await localNotificationsPlugin.cancel(_getNotificationID(instance, notification)); |
|
|
|
await localNotificationsPlugin.cancel(_getNotificationID(instance, notification)); |
|
|
|
return; |
|
|
|
} else if (notification.subject.deleteAll ?? false) { |
|
|
|
} |
|
|
|
|
|
|
|
if (notification.subject.deleteAll ?? false) { |
|
|
|
|
|
|
|
await localNotificationsPlugin.cancelAll(); |
|
|
|
await localNotificationsPlugin.cancelAll(); |
|
|
|
return; |
|
|
|
Global.onPushNotificationReceived?.call(instance); |
|
|
|
} |
|
|
|
} else if (notification.type == 'background') { |
|
|
|
if (notification.type == 'background') { |
|
|
|
|
|
|
|
debugPrint('Got unknown background notification ${json.encode(notification.toJson())}'); |
|
|
|
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 { |
|
|
|
} else { |
|
|
|
app = allAppImplementations.singleWhere((final a) => a.id == 'notifications'); |
|
|
|
final localizations = await appLocalizationsFromSystem(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final platform = await getNeonPlatform(); |
|
|
|
final appName = app.nameFromLocalization(localizations); |
|
|
|
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( |
|
|
|
final appName = app.nameFromLocalization(localizations); |
|
|
|
_getNotificationID(instance, notification), |
|
|
|
|
|
|
|
appName, |
|
|
|
await localNotificationsPlugin.show( |
|
|
|
notification.subject.subject, |
|
|
|
_getNotificationID(instance, notification), |
|
|
|
NotificationDetails( |
|
|
|
appName, |
|
|
|
android: AndroidNotificationDetails( |
|
|
|
notification.subject.subject, |
|
|
|
app.id, |
|
|
|
NotificationDetails( |
|
|
|
appName, |
|
|
|
android: AndroidNotificationDetails( |
|
|
|
groupKey: 'app_${app.id}', |
|
|
|
app.id, |
|
|
|
icon: '@mipmap/app_${app.id}', |
|
|
|
appName, |
|
|
|
color: themePrimaryColor, |
|
|
|
groupKey: 'app_${app.id}', |
|
|
|
category: notification.type == 'voip' ? AndroidNotificationCategory.call : null, |
|
|
|
icon: '@mipmap/app_${app.id}', |
|
|
|
importance: Importance.max, |
|
|
|
color: themePrimaryColor, |
|
|
|
priority: notification.priority == 'high' |
|
|
|
category: notification.type == 'voip' ? AndroidNotificationCategory.call : null, |
|
|
|
? (notification.type == 'voip' ? Priority.max : Priority.high) |
|
|
|
importance: Importance.max, |
|
|
|
: Priority.defaultPriority, |
|
|
|
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( |
|
|
|
payload: json.encode( |
|
|
|
icon: AssetsLinuxIcon('assets/apps/${app.id}.svg'), |
|
|
|
PushNotification( |
|
|
|
urgency: notification.type == 'voip' ? LinuxNotificationUrgency.critical : LinuxNotificationUrgency.normal, |
|
|
|
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); |
|
|
|
Global.onPushNotificationReceived?.call(instance); |
|
|
|
} |
|
|
|
} |
|
|
|