Skip to content

Commit

Permalink
[TEST] Synchronize the latest data in hive database when in backgroun…
Browse files Browse the repository at this point in the history
…d mode
  • Loading branch information
dab246 committed Jun 18, 2024
1 parent b169594 commit 1097d84
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/features/login/data/local/account_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ class AccountCacheManager {
log('AccountCacheManager::deleteCurrentAccount(): $hashId');
return _accountCacheClient.deleteItem(hashId);
}

Future<void> closeAccountHiveCacheBox() => _accountCacheClient.closeBox();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ class AuthenticationInfoCacheManager {
Future<void> removeAuthenticationInfo() {
return _authenticationInfoCacheClient.deleteItem(AuthenticationInfoCache.keyCacheValue);
}

Future<void> closeAuthenticationInfoHiveCacheBox() => _authenticationInfoCacheClient.closeBox();
}
2 changes: 2 additions & 0 deletions lib/features/login/data/local/token_oidc_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ class TokenOidcCacheManager {
log('TokenOidcCacheManager::deleteTokenOidc:');
await _tokenOidcCacheClient.clearAllData();
}

Future<void> closeTokenOIDCHiveCacheBox() => _tokenOidcCacheClient.closeBox();
}
2 changes: 2 additions & 0 deletions lib/features/mailbox/data/local/state_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class StateCacheManager {
final stateKey = TupleKey(stateCache.type.name, accountId.asString, userName.value).encodeKey;
return await _stateCacheClient.insertItem(stateKey, stateCache);
}

Future<void> closeStateHiveCacheBox() => _stateCacheClient.closeBox();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ import 'package:tmail_ui_user/features/home/domain/extensions/session_extensions
import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart';
import 'package:tmail_ui_user/features/home/domain/usecases/get_session_interactor.dart';
import 'package:tmail_ui_user/features/home/presentation/home_bindings.dart';
import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart';
import 'package:tmail_ui_user/features/login/data/local/authentication_info_cache_manager.dart';
import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart';
import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart';
import 'package:tmail_ui_user/features/login/domain/state/get_credential_state.dart';
import 'package:tmail_ui_user/features/login/domain/state/get_stored_token_oidc_state.dart';
import 'package:tmail_ui_user/features/login/domain/usecases/get_authenticated_account_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/action/fcm_action.dart';
import 'package:tmail_ui_user/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart';
Expand All @@ -48,6 +52,10 @@ class FcmMessageController extends FcmBaseController {
DynamicUrlInterceptors? _dynamicUrlInterceptors;
AuthorizationInterceptors? _authorizationInterceptors;
GetSessionInteractor? _getSessionInteractor;
AccountCacheManager? _accountCacheManager;
TokenOidcCacheManager? _tokenOidcCacheManager;
StateCacheManager? _stateCacheManager;
AuthenticationInfoCacheManager? _authenticationInfoCacheManager;

FcmMessageController._internal();

Expand Down Expand Up @@ -99,7 +107,7 @@ class FcmMessageController extends FcmBaseController {
}
}

void _handleBackgroundMessageAction(Map<String, dynamic> payloadData) async {
Future<void> _handleBackgroundMessageAction(Map<String, dynamic> payloadData) async {
log('FcmMessageController::_handleBackgroundMessageAction():payloadData: $payloadData');
final stateChange = FcmUtils.instance.convertFirebaseDataMessageToStateChange(payloadData);
await _initialAppConfig();
Expand Down Expand Up @@ -187,13 +195,28 @@ class FcmMessageController extends FcmBaseController {
});

_getInteractorBindings();

await Future.wait([
if (_accountCacheManager != null)
_accountCacheManager!.closeAccountHiveCacheBox(),
if (_tokenOidcCacheManager != null)
_tokenOidcCacheManager!.closeTokenOIDCHiveCacheBox(),
if (_stateCacheManager != null)
_stateCacheManager!.closeStateHiveCacheBox(),
if (_authenticationInfoCacheManager != null)
_authenticationInfoCacheManager!.closeAuthenticationInfoHiveCacheBox(),
]);
}

void _getInteractorBindings() {
_getAuthenticatedAccountInteractor = getBinding<GetAuthenticatedAccountInteractor>();
_dynamicUrlInterceptors = getBinding<DynamicUrlInterceptors>();
_authorizationInterceptors = getBinding<AuthorizationInterceptors>();
_getSessionInteractor = getBinding<GetSessionInteractor>();
_accountCacheManager = getBinding<AccountCacheManager>();
_tokenOidcCacheManager = getBinding<TokenOidcCacheManager>();
_stateCacheManager = getBinding<StateCacheManager>();
_authenticationInfoCacheManager = getBinding<AuthenticationInfoCacheManager>();

FcmTokenController.instance.initialBindingInteractor();
}
Expand Down

0 comments on commit 1097d84

Please sign in to comment.