From 809bbd979efe20f5deee6e94da036165151eb132 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 19 Nov 2024 16:26:01 +0100 Subject: [PATCH] feat(neon_framework): Implement remote wipe Signed-off-by: provokateurin --- .../lib/src/blocs/accounts.dart | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/packages/neon_framework/lib/src/blocs/accounts.dart b/packages/neon_framework/lib/src/blocs/accounts.dart index ba71bae42d3..7ceb0df6537 100644 --- a/packages/neon_framework/lib/src/blocs/accounts.dart +++ b/packages/neon_framework/lib/src/blocs/accounts.dart @@ -111,6 +111,7 @@ class _AccountsBloc extends Bloc implements AccountsBloc { for (final app in allAppImplementations) { app.blocsCache.pruneAgainst(accounts); } + unawaited(checkRemoteWipe(accounts)); }); } @@ -129,6 +130,7 @@ class _AccountsBloc extends Bloc implements AccountsBloc { final weatherStatusBlocs = AccountCache(); final maintenanceModeBlocs = AccountCache(); final referencesBlocs = AccountCache(); + final remoteWipeChecks = {}; @override void dispose() { @@ -228,4 +230,45 @@ class _AccountsBloc extends Bloc implements AccountsBloc { account: account, capabilities: getCapabilitiesBlocFor(account).capabilities, ); + + Future checkRemoteWipe(BuiltList accounts) async { + for (final account in accounts) { + // Only check each account once per app start + if (remoteWipeChecks.contains(account)) { + return; + } + remoteWipeChecks.add(account); + + log.finer('Checking remote wipe status for account ${account.id}.'); + + try { + final wipe = await _accountRepository.getRemoteWipeStatus(account); + if (!wipe) { + return; + } + + log.finer('Wiping account ${account.id}.'); + + await removeAccount(account); + + try { + await _accountRepository.postRemoteWipeSuccess(account); + } on PostRemoteWipeSuccessFailure catch (error, stackTrace) { + log.finer( + 'Failed to post remote wipe success for account ${account.id}.', + error, + stackTrace, + ); + } + + log.finer('Wiped account ${account.id}.'); + } on GetRemoteWipeStatusFailure catch (error, stackTrace) { + log.finer( + 'Failed to get remote wipe status for account ${account.id}.', + error, + stackTrace, + ); + } + } + } }