mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-06-03 06:07:26 +02:00
chore: Make push helper more fail safe
This commit is contained in:
parent
06d3a3a4c8
commit
8c9bda338b
@ -19,6 +19,43 @@ Future<void> pushHelper(
|
|||||||
L10n? l10n,
|
L10n? l10n,
|
||||||
String? activeRoomId,
|
String? activeRoomId,
|
||||||
Future<dynamic> Function(String?)? onSelectNotification,
|
Future<dynamic> Function(String?)? onSelectNotification,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
await _tryPushHelper(
|
||||||
|
notification,
|
||||||
|
client: client,
|
||||||
|
l10n: l10n,
|
||||||
|
activeRoomId: activeRoomId,
|
||||||
|
onSelectNotification: onSelectNotification,
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
Logs().wtf('Push Helper has crashed!', e, s);
|
||||||
|
|
||||||
|
// Initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
|
||||||
|
final _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||||
|
await _flutterLocalNotificationsPlugin.initialize(
|
||||||
|
const InitializationSettings(
|
||||||
|
android: AndroidInitializationSettings('notifications_icon'),
|
||||||
|
iOS: IOSInitializationSettings(),
|
||||||
|
),
|
||||||
|
onSelectNotification: onSelectNotification,
|
||||||
|
);
|
||||||
|
_flutterLocalNotificationsPlugin.show(
|
||||||
|
0,
|
||||||
|
l10n?.newMessageInFluffyChat,
|
||||||
|
l10n?.openAppToReadMessages,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _tryPushHelper(
|
||||||
|
PushNotification notification, {
|
||||||
|
Client? client,
|
||||||
|
L10n? l10n,
|
||||||
|
String? activeRoomId,
|
||||||
|
Future<dynamic> Function(String?)? onSelectNotification,
|
||||||
}) async {
|
}) async {
|
||||||
final isBackgroundMessage = client == null;
|
final isBackgroundMessage = client == null;
|
||||||
Logs().v(
|
Logs().v(
|
||||||
@ -52,12 +89,14 @@ Future<void> pushHelper(
|
|||||||
|
|
||||||
if (event == null) {
|
if (event == null) {
|
||||||
Logs().v('Notification is a clearing indicator.');
|
Logs().v('Notification is a clearing indicator.');
|
||||||
|
if (notification.counts?.unread == 0) {
|
||||||
if (notification.counts == null || notification.counts?.unread == 0) {
|
if (notification.counts == null || notification.counts?.unread == 0) {
|
||||||
await _flutterLocalNotificationsPlugin.cancelAll();
|
await _flutterLocalNotificationsPlugin.cancelAll();
|
||||||
final store = await SharedPreferences.getInstance();
|
final store = await SharedPreferences.getInstance();
|
||||||
await store.setString(
|
await store.setString(
|
||||||
SettingKeys.notificationCurrentIds, json.encode({}));
|
SettingKeys.notificationCurrentIds, json.encode({}));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logs().v('Push helper got notification event.');
|
Logs().v('Push helper got notification event.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user