From 36c6ffa541e4a407d6ec8bf10b46ccda02f2b4f4 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 30 Sep 2023 07:53:28 +0200 Subject: [PATCH] fix(neon): fix storage in PushNotificationsBloc Signed-off-by: Nikolas Rimikis --- .../neon/neon/lib/src/blocs/push_notifications.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/neon/neon/lib/src/blocs/push_notifications.dart b/packages/neon/neon/lib/src/blocs/push_notifications.dart index d4715cd7..5452bb3d 100644 --- a/packages/neon/neon/lib/src/blocs/push_notifications.dart +++ b/packages/neon/neon/lib/src/blocs/push_notifications.dart @@ -35,7 +35,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, } final AccountsBloc _accountsBloc; - late final _storage = const AppStorage(StorageKeys.notifications); + late final _storage = const AppStorage(StorageKeys.lastEndpoint); final GlobalOptions _globalOptions; StreamSubscription>? _accountsListener; @@ -46,8 +46,6 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, _globalOptions.pushNotificationsEnabled.removeListener(_pushNotificationsEnabledListener); } - String _keyLastEndpoint(final Account account) => 'last-endpoint-${account.id}'; - Future _pushNotificationsEnabledListener() async { if (_globalOptions.pushNotificationsEnabled.value) { await _setupUnifiedPush(); @@ -72,7 +70,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, return; } - if (_storage.getString(_keyLastEndpoint(account)) == endpoint) { + if (_storage.getString(account.id) == endpoint) { debugPrint('Endpoint not changed'); return; } @@ -85,7 +83,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, proxyServer: '$endpoint#', // This is a hack to make the Nextcloud server directly push to the endpoint ); - await _storage.setString(_keyLastEndpoint(account), endpoint); + await _storage.setString(account.id, endpoint); debugPrint( 'Account $instance registered for push notifications ${json.encode(subscription.body.ocs.data.toJson())}', @@ -117,7 +115,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents, try { await account.client.notifications.push.removeDevice(); await UnifiedPush.unregister(account.id); - await _storage.remove(_keyLastEndpoint(account)); + await _storage.remove(account.id); } catch (e) { debugPrint('Failed to unregister device: $e'); }