From df39af322501ac1d501cc333005ee5375550d7f8 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:25:21 +0100 Subject: [PATCH] Do not update fb token when delete pull only token --- .../generated_providers/token_notifier.dart | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/utils/riverpod/riverpod_providers/generated_providers/token_notifier.dart b/lib/utils/riverpod/riverpod_providers/generated_providers/token_notifier.dart index b1d27453..a239d97f 100644 --- a/lib/utils/riverpod/riverpod_providers/generated_providers/token_notifier.dart +++ b/lib/utils/riverpod/riverpod_providers/generated_providers/token_notifier.dart @@ -479,7 +479,10 @@ class TokenNotifier extends _$TokenNotifier with ResultHandler { await removeTokens(tokens); } - Future _removePushToken(PushToken token) async { + Future _removePushToken(PushToken token) async { + if (token.fbToken == null) { + return _removeToken(token); + } try { await _firebaseUtils.deleteFirebaseToken(); } on SocketException { @@ -488,23 +491,36 @@ class TokenNotifier extends _$TokenNotifier with ResultHandler { AppLocalizations.of(globalNavigatorKey.currentContext!)!.errorUnlinkingPushToken(token.label), AppLocalizations.of(globalNavigatorKey.currentContext!)!.checkYourNetwork, ); + return false; + } + final deleted = await _removeToken(token); + if (deleted) { + Logger.info('Push token "${token.id}" removed successfully.'); + } else { + Logger.warning('Push token "${token.id}" could not be removed.'); } + final fbToken = await _firebaseUtils.getFBToken(); - _firebaseUtils.getFBToken().then((fbToken) async { - if (fbToken == null) { - await _updateTokens(state.pushTokens, (p0) => p0.copyWith(fbToken: null)); - Logger.warning('Could not update firebase token because no firebase token is available.'); - ref.read(statusMessageProvider.notifier).state = ( - AppLocalizations.of(globalNavigatorKey.currentContext!)!.errorSynchronizationNoNetworkConnection, - AppLocalizations.of(globalNavigatorKey.currentContext!)!.syncFbTokenManuallyWhenNetworkIsAvailable, - ); - } - final (notUpdated, _) = (await updateFirebaseToken(fbToken)) ?? ([], []); - await _updateTokens(notUpdated, (p0) => p0.copyWith(fbToken: null)); - return; - }); - await _removeToken(token); - Logger.info('Push token "${token.id}" removed successfully.'); + if (fbToken == null) { + await _updateTokens(state.pushTokens, (p0) => p0.copyWith(fbToken: null)); + Logger.warning('Could not update firebase token because no firebase token is available.'); + ref.read(statusMessageProvider.notifier).state = ( + AppLocalizations.of(globalNavigatorKey.currentContext!)!.errorSynchronizationNoNetworkConnection, + AppLocalizations.of(globalNavigatorKey.currentContext!)!.syncFbTokenManuallyWhenNetworkIsAvailable, + ); + return deleted; + } + + final (notUpdated, _) = (await updateFirebaseToken(fbToken)) ?? ([], []); + await _updateTokens(notUpdated, (p0) => p0.copyWith(fbToken: null)); + if (notUpdated.isNotEmpty) { + Logger.warning('Could not update firebase token for ${notUpdated.length} tokens.'); + ref.read(statusMessageProvider.notifier).state = ( + AppLocalizations.of(globalNavigatorKey.currentContext!)!.errorSynchronizationNoNetworkConnection, + AppLocalizations.of(globalNavigatorKey.currentContext!)!.syncFbTokenManuallyWhenNetworkIsAvailable, + ); + } + return deleted; } Future rolloutPushToken(PushToken token) async {