diff --git a/lib/state_notifiers/token_notifier.dart b/lib/state_notifiers/token_notifier.dart index 2317f4eef..296235aad 100644 --- a/lib/state_notifiers/token_notifier.dart +++ b/lib/state_notifiers/token_notifier.dart @@ -158,16 +158,17 @@ class TokenNotifier extends StateNotifier { await _saveOrReplaceTokensRepo(updatedTokens); } - Future updateToken(T token, T Function(T) updater) async { + Future updateToken(T token, T Function(T) updater) async { await isLoading; final current = state.currentOf(token); if (current == null) { Logger.warning('Tried to update a token that does not exist.', name: 'token_notifier.dart#updateToken'); - return; + return null; } final updated = updater(current); state = state.replaceToken(updated); await _saveOrReplaceTokensRepo([updated]); + return updated; } Future updateTokens(List token, T Function(T) updater) async { @@ -273,7 +274,11 @@ class TokenNotifier extends StateNotifier { // Re-add url and sslverify to android legacy tokens: if (token.url == null) { - token = token.copyWith(url: pr.uri, sslVerify: pr.sslVerify); + token = await updateToken(token, (p0) => p0.copyWith(url: pr.uri, sslVerify: pr.sslVerify)); + } + if (token == null) { + Logger.warning('The requested token does not exist anymore', name: 'token_notifier.dart#addPushRequestToToken'); + return false; } bool isVerified = token.privateTokenKey == null ? await _legacy.verify(token.serial, signedData, signature) @@ -387,7 +392,7 @@ class TokenNotifier extends StateNotifier { updateToken(token, (p0) => p0.copyWith(rolloutState: PushTokenRollOutState.parsingResponse)); try { RSAPublicKey publicServerKey = await _parseRollOutResponse(response); - token = token.withPublicServerKey(publicServerKey); + updateToken(token, (p0) => p0.withPublicServerKey(publicServerKey)); } on FormatException catch (e, s) { showMessage(message: "Couldn't parsing RSA public key: ${e.message}", duration: const Duration(seconds: 3)); Logger.warning('Error while parsing RSA public key.', name: 'token_notifier.dart#rolloutPushToken', error: e, stackTrace: s);