Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix-pushrequst-on-new-push-tokens #340

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/state_notifiers/token_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,17 @@ class TokenNotifier extends StateNotifier<TokenState> {
await _saveOrReplaceTokensRepo(updatedTokens);
}

Future<void> updateToken<T extends Token>(T token, T Function(T) updater) async {
Future<T?> updateToken<T extends Token>(T token, T Function(T) updater) async {
await isLoading;
final current = state.currentOf<T>(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<void> updateTokens<T extends Token>(List<T> token, T Function(T) updater) async {
Expand Down Expand Up @@ -273,7 +274,11 @@ class TokenNotifier extends StateNotifier<TokenState> {

// 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)
Expand Down Expand Up @@ -387,7 +392,7 @@ class TokenNotifier extends StateNotifier<TokenState> {
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);
Expand Down
Loading