Remove closeBox when open box in hive database
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -52,12 +52,8 @@ abstract class HiveCacheClient<T> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<T?> getItem(String key, {bool needToReopen = false}) {
|
Future<T?> getItem(String key) {
|
||||||
log('$runtimeType::getItem() key: $encryption - needToReopen: $needToReopen');
|
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
if (needToReopen) {
|
|
||||||
await closeBox();
|
|
||||||
}
|
|
||||||
final boxItem = encryption
|
final boxItem = encryption
|
||||||
? await openBoxEncryption()
|
? await openBoxEncryption()
|
||||||
: await openBox();
|
: await openBox();
|
||||||
|
|||||||
@@ -47,6 +47,4 @@ class AccountCacheManager {
|
|||||||
log('AccountCacheManager::deleteCurrentAccount(): $hashId');
|
log('AccountCacheManager::deleteCurrentAccount(): $hashId');
|
||||||
return _accountCacheClient.deleteItem(hashId);
|
return _accountCacheClient.deleteItem(hashId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeAccountHiveCacheBox() => _accountCacheClient.closeBox();
|
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,4 @@ class AuthenticationInfoCacheManager {
|
|||||||
Future<void> removeAuthenticationInfo() {
|
Future<void> removeAuthenticationInfo() {
|
||||||
return _authenticationInfoCacheClient.deleteItem(AuthenticationInfoCache.keyCacheValue);
|
return _authenticationInfoCacheClient.deleteItem(AuthenticationInfoCache.keyCacheValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeAuthenticationInfoHiveCacheBox() => _authenticationInfoCacheClient.closeBox();
|
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,4 @@ class TokenOidcCacheManager {
|
|||||||
Future<void> deleteTokenOidc() async {
|
Future<void> deleteTokenOidc() async {
|
||||||
await _tokenOidcCacheClient.clearAllData();
|
await _tokenOidcCacheClient.clearAllData();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeTokenOIDCHiveCacheBox() => _tokenOidcCacheClient.closeBox();
|
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,4 @@ class StateCacheManager {
|
|||||||
final stateKey = TupleKey(stateType.name, accountId.asString, userName.value).encodeKey;
|
final stateKey = TupleKey(stateType.name, accountId.asString, userName.value).encodeKey;
|
||||||
return await _stateCacheClient.deleteItem(stateKey);
|
return await _stateCacheClient.deleteItem(stateKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeStateHiveCacheBox() => _stateCacheClient.closeBox();
|
|
||||||
}
|
}
|
||||||
@@ -76,13 +76,11 @@ class NewEmailCacheManager {
|
|||||||
EmailId emailId
|
EmailId emailId
|
||||||
) async {
|
) async {
|
||||||
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
||||||
final detailedEmailCache = await _cacheClient.getItem(keyCache, needToReopen: true);
|
final detailedEmailCache = await _cacheClient.getItem(keyCache);
|
||||||
if (detailedEmailCache != null) {
|
if (detailedEmailCache != null) {
|
||||||
return detailedEmailCache;
|
return detailedEmailCache;
|
||||||
} else {
|
} else {
|
||||||
throw NotFoundStoredNewEmailException();
|
throw NotFoundStoredNewEmailException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> closeNewEmailHiveCacheBox() => _cacheClient.closeBox();
|
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ class OpenedEmailCacheManager {
|
|||||||
EmailId emailId
|
EmailId emailId
|
||||||
) async {
|
) async {
|
||||||
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
||||||
final detailedEmailCache = await _cacheClient.getItem(keyCache, needToReopen: true);
|
final detailedEmailCache = await _cacheClient.getItem(keyCache);
|
||||||
if (detailedEmailCache != null) {
|
if (detailedEmailCache != null) {
|
||||||
return detailedEmailCache;
|
return detailedEmailCache;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class FCMCacheManager {
|
|||||||
|
|
||||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) async {
|
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) async {
|
||||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
||||||
final stateValue = await _fcmCacheClient.getItem(stateKeyCache, needToReopen: true);
|
final stateValue = await _fcmCacheClient.getItem(stateKeyCache);
|
||||||
if (stateValue != null) {
|
if (stateValue != null) {
|
||||||
return jmap.State(stateValue);
|
return jmap.State(stateValue);
|
||||||
} else {
|
} else {
|
||||||
@@ -52,7 +52,7 @@ class FCMCacheManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<FirebaseRegistrationCache> getStoredFirebaseRegistration() async {
|
Future<FirebaseRegistrationCache> getStoredFirebaseRegistration() async {
|
||||||
final firebaseRegistration = await _firebaseRegistrationCacheClient.getItem(FirebaseRegistrationCache.keyCacheValue, needToReopen: true);
|
final firebaseRegistration = await _firebaseRegistrationCacheClient.getItem(FirebaseRegistrationCache.keyCacheValue);
|
||||||
if (firebaseRegistration == null) {
|
if (firebaseRegistration == null) {
|
||||||
throw NotFoundFirebaseRegistrationCacheException();
|
throw NotFoundFirebaseRegistrationCacheException();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -17,14 +17,10 @@ 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/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/domain/usecases/get_session_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/home/presentation/home_bindings.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/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_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/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/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/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/bindings/fcm_interactor_bindings.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_token_controller.dart';
|
import 'package:tmail_ui_user/features/push_notification/presentation/controller/fcm_token_controller.dart';
|
||||||
@@ -43,11 +39,6 @@ class FcmMessageController extends PushBaseController {
|
|||||||
AuthorizationInterceptors? _authorizationInterceptors;
|
AuthorizationInterceptors? _authorizationInterceptors;
|
||||||
GetSessionInteractor? _getSessionInteractor;
|
GetSessionInteractor? _getSessionInteractor;
|
||||||
|
|
||||||
AccountCacheManager? _accountCacheManager;
|
|
||||||
TokenOidcCacheManager? _tokenOidcCacheManager;
|
|
||||||
StateCacheManager? _stateCacheManager;
|
|
||||||
AuthenticationInfoCacheManager? _authenticationInfoCacheManager;
|
|
||||||
|
|
||||||
FcmMessageController._internal();
|
FcmMessageController._internal();
|
||||||
|
|
||||||
static final FcmMessageController _instance = FcmMessageController._internal();
|
static final FcmMessageController _instance = FcmMessageController._internal();
|
||||||
@@ -96,17 +87,6 @@ class FcmMessageController extends PushBaseController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
_getInteractorBindings();
|
_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() {
|
void _getInteractorBindings() {
|
||||||
@@ -114,10 +94,6 @@ class FcmMessageController extends PushBaseController {
|
|||||||
_dynamicUrlInterceptors = getBinding<DynamicUrlInterceptors>();
|
_dynamicUrlInterceptors = getBinding<DynamicUrlInterceptors>();
|
||||||
_authorizationInterceptors = getBinding<AuthorizationInterceptors>();
|
_authorizationInterceptors = getBinding<AuthorizationInterceptors>();
|
||||||
_getSessionInteractor = getBinding<GetSessionInteractor>();
|
_getSessionInteractor = getBinding<GetSessionInteractor>();
|
||||||
_accountCacheManager = getBinding<AccountCacheManager>();
|
|
||||||
_tokenOidcCacheManager = getBinding<TokenOidcCacheManager>();
|
|
||||||
_stateCacheManager = getBinding<StateCacheManager>();
|
|
||||||
_authenticationInfoCacheManager = getBinding<AuthenticationInfoCacheManager>();
|
|
||||||
|
|
||||||
FcmTokenController.instance.initialBindingInteractor();
|
FcmTokenController.instance.initialBindingInteractor();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,12 +56,16 @@ extension EmailCacheExtension on EmailCache {
|
|||||||
|
|
||||||
bool expireTimeCaching(EmailCleanupRule cleanupRule) {
|
bool expireTimeCaching(EmailCleanupRule cleanupRule) {
|
||||||
final currentTime = DateTime.now();
|
final currentTime = DateTime.now();
|
||||||
|
log('EmailCacheExtension::expireTimeCaching():currentTime: $currentTime | receivedAt: $receivedAt');
|
||||||
if (receivedAt != null) {
|
if (receivedAt != null) {
|
||||||
final countDay = currentTime.daysBetween(receivedAt!.toLocal());
|
final countDay = currentTime.daysBetween(receivedAt!.toLocal());
|
||||||
|
log('EmailCacheExtension::expireTimeCaching():countDay: $countDay | cleanupRule.cachingEmailPeriod.countDay: ${cleanupRule.cachingEmailPeriod.countDay}');
|
||||||
if (countDay >= cleanupRule.cachingEmailPeriod.countDay) {
|
if (countDay >= cleanupRule.cachingEmailPeriod.countDay) {
|
||||||
|
log('EmailCacheExtension::expireTimeCaching():true');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log('EmailCacheExtension::expireTimeCaching():false');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ class EmailCacheManager {
|
|||||||
|
|
||||||
Future<EmailCache> getStoredEmail(AccountId accountId, UserName userName, EmailId emailId) async {
|
Future<EmailCache> getStoredEmail(AccountId accountId, UserName userName, EmailId emailId) async {
|
||||||
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
final keyCache = TupleKey(emailId.asString, accountId.asString, userName.value).encodeKey;
|
||||||
final emailCache = await _emailCacheClient.getItem(keyCache, needToReopen: true);
|
final emailCache = await _emailCacheClient.getItem(keyCache);
|
||||||
if (emailCache != null) {
|
if (emailCache != null) {
|
||||||
return emailCache;
|
return emailCache;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class MemoryAccountCacheClient implements AccountCacheClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<AccountCache?> getItem(String key, {bool needToReopen = false}) {
|
Future<AccountCache?> getItem(String key) {
|
||||||
return Future.value(_cache[key]);
|
return Future.value(_cache[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user