Browse Source

fix(neon): fix storage in PushNotificationsBloc

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/886/head
Nikolas Rimikis 1 year ago
parent
commit
36c6ffa541
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 10
      packages/neon/neon/lib/src/blocs/push_notifications.dart

10
packages/neon/neon/lib/src/blocs/push_notifications.dart

@ -35,7 +35,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
} }
final AccountsBloc _accountsBloc; final AccountsBloc _accountsBloc;
late final _storage = const AppStorage(StorageKeys.notifications); late final _storage = const AppStorage(StorageKeys.lastEndpoint);
final GlobalOptions _globalOptions; final GlobalOptions _globalOptions;
StreamSubscription<List<Account>>? _accountsListener; StreamSubscription<List<Account>>? _accountsListener;
@ -46,8 +46,6 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
_globalOptions.pushNotificationsEnabled.removeListener(_pushNotificationsEnabledListener); _globalOptions.pushNotificationsEnabled.removeListener(_pushNotificationsEnabledListener);
} }
String _keyLastEndpoint(final Account account) => 'last-endpoint-${account.id}';
Future<void> _pushNotificationsEnabledListener() async { Future<void> _pushNotificationsEnabledListener() async {
if (_globalOptions.pushNotificationsEnabled.value) { if (_globalOptions.pushNotificationsEnabled.value) {
await _setupUnifiedPush(); await _setupUnifiedPush();
@ -72,7 +70,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
return; return;
} }
if (_storage.getString(_keyLastEndpoint(account)) == endpoint) { if (_storage.getString(account.id) == endpoint) {
debugPrint('Endpoint not changed'); debugPrint('Endpoint not changed');
return; 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 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( debugPrint(
'Account $instance registered for push notifications ${json.encode(subscription.body.ocs.data.toJson())}', 'Account $instance registered for push notifications ${json.encode(subscription.body.ocs.data.toJson())}',
@ -117,7 +115,7 @@ class PushNotificationsBloc extends Bloc implements PushNotificationsBlocEvents,
try { try {
await account.client.notifications.push.removeDevice(); await account.client.notifications.push.removeDevice();
await UnifiedPush.unregister(account.id); await UnifiedPush.unregister(account.id);
await _storage.remove(_keyLastEndpoint(account)); await _storage.remove(account.id);
} catch (e) { } catch (e) {
debugPrint('Failed to unregister device: $e'); debugPrint('Failed to unregister device: $e');
} }

Loading…
Cancel
Save