Skip to content

Commit

Permalink
Do not update fb token when delete pull only token
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Nov 26, 2024
1 parent bb9affd commit df39af3
Showing 1 changed file with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,10 @@ class TokenNotifier extends _$TokenNotifier with ResultHandler {
await removeTokens(tokens);
}

Future<void> _removePushToken(PushToken token) async {
Future<bool> _removePushToken(PushToken token) async {
if (token.fbToken == null) {
return _removeToken(token);
}
try {
await _firebaseUtils.deleteFirebaseToken();
} on SocketException {
Expand All @@ -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)) ?? (<PushToken>[], <PushToken>[]);
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)) ?? (<PushToken>[], <PushToken>[]);
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<bool> rolloutPushToken(PushToken token) async {
Expand Down

0 comments on commit df39af3

Please sign in to comment.