diff --git a/core/lib/utils/sentry/sentry_manager.dart b/core/lib/utils/sentry/sentry_manager.dart index 0acdc723a..6375779dd 100644 --- a/core/lib/utils/sentry/sentry_manager.dart +++ b/core/lib/utils/sentry/sentry_manager.dart @@ -31,8 +31,8 @@ class SentryManager { if (!_isSentryAvailable) { await fallBackRunner(); } - } catch (e, st) { - logError('[SentryManager] Init failed', exception: e, stackTrace: st); + } catch (e) { + logWarning('[SentryManager] Init failed. Exception $e'); await fallBackRunner(); } } @@ -90,8 +90,8 @@ class SentryManager { try { await Sentry.configureScope((scope) => scope.setUser(user)); log('[SentryManager] User set: ${user.email}'); - } catch (e, st) { - logError('[SentryManager] Set user failed', exception: e, stackTrace: st); + } catch (e) { + logWarning('[SentryManager] Set user failed. Exception: $e'); } } @@ -101,12 +101,8 @@ class SentryManager { try { await Sentry.configureScope((scope) => scope.setUser(null)); log('[SentryManager] User cleared'); - } catch (e, st) { - logError( - '[SentryManager] Clear user failed', - exception: e, - stackTrace: st, - ); + } catch (e) { + logWarning('[SentryManager] Clear user failed. Exception: $e'); } } } diff --git a/lib/features/base/base_controller.dart b/lib/features/base/base_controller.dart index 538331cc9..92ead4895 100644 --- a/lib/features/base/base_controller.dart +++ b/lib/features/base/base_controller.dart @@ -448,7 +448,7 @@ abstract class BaseController extends GetxController return; } - await clearAllMailDataCached(); + await cachingManager.clearMailDataCached(); _isFcmEnabled = _isFcmActivated(session, accountId); if (isAuthenticatedWithOidc) { @@ -503,11 +503,10 @@ abstract class BaseController extends GetxController } Future _handleDeleteFCMAndClearData() async { - await Future.wait([ - if (_isFcmEnabled) - _handleDeleteFCMRegistration(), - clearAllData(), - ]); + if (_isFcmEnabled) { + await _handleDeleteFCMRegistration(); + } + clearAllData(); } Future _handleDeleteFCMRegistration() async { @@ -560,57 +559,24 @@ abstract class BaseController extends GetxController removeAllPageAndGoToLogin(); } - Future clearAllMailDataCached() async { - try { - await cachingManager.clearMailDataCached(); - if (PlatformInfo.isMobile) { - await cachingManager.clearAllFileInStorage(); - } - } catch (e) { - logError('BaseController::clearAllMailDataCached:Exception = $e'); - } - } - Future clearAllData() async { try { - if (isAuthenticatedWithOidc) { - await _clearOidcAuthData(); - } else { - await _clearBasicAuthData(); - } + await Future.wait([ + if (isAuthenticatedWithOidc) + deleteCredentialInteractor.execute() + else + deleteAuthorityOidcInteractor.execute(), + cachingManager.clearAll(), + languageCacheManager.removeLanguage(), + ]); + authorizationInterceptors.clear(); + authorizationIsolateInterceptors.clear(); + await cachingManager.closeHive(); } catch (e) { - logWarning('BaseController::clearAllData:Exception = $e'); + logWarning('BaseController::clearAllData: Cannot clear all data: $e'); } } - Future _clearBasicAuthData() async { - await Future.wait([ - deleteCredentialInteractor.execute(), - cachingManager.clearAll(), - languageCacheManager.removeLanguage(), - ]); - if (PlatformInfo.isMobile) { - await cachingManager.clearAllFileInStorage(); - } - authorizationInterceptors.clear(); - authorizationIsolateInterceptors.clear(); - await cachingManager.closeHive(); - } - - Future _clearOidcAuthData() async { - await Future.wait([ - deleteAuthorityOidcInteractor.execute(), - cachingManager.clearAll(), - languageCacheManager.removeLanguage(), - ]); - if (PlatformInfo.isMobile) { - await cachingManager.clearAllFileInStorage(); - } - authorizationIsolateInterceptors.clear(); - authorizationInterceptors.clear(); - await cachingManager.closeHive(); - } - int getMinInputLengthAutocomplete({ required Session session, required AccountId accountId, diff --git a/lib/features/base/upgradeable/upgrade_hive_database_steps_v13.dart b/lib/features/base/upgradeable/upgrade_hive_database_steps_v13.dart index 481b8ef40..5a0115014 100644 --- a/lib/features/base/upgradeable/upgrade_hive_database_steps_v13.dart +++ b/lib/features/base/upgradeable/upgrade_hive_database_steps_v13.dart @@ -11,7 +11,7 @@ class UpgradeHiveDatabaseStepsV13 extends UpgradeDatabaseSteps { @override Future onUpgrade(int oldVersion, int newVersion) async { if (oldVersion > 0 && oldVersion < newVersion && newVersion == 13) { - await _cachingManager.clearMailboxCache(); + await _cachingManager.clearMailboxAndStateCache(); } } } \ No newline at end of file diff --git a/lib/features/caching/caching_manager.dart b/lib/features/caching/caching_manager.dart index 9b0f5da28..a48382762 100644 --- a/lib/features/caching/caching_manager.dart +++ b/lib/features/caching/caching_manager.dart @@ -1,14 +1,9 @@ import 'package:core/utils/app_logger.dart'; import 'package:core/utils/file_utils.dart'; import 'package:core/utils/platform_info.dart'; -import 'package:fcm/model/type_name.dart'; -import 'package:jmap_dart_client/jmap/account_id.dart'; -import 'package:jmap_dart_client/jmap/core/user_name.dart'; -import 'package:model/extensions/account_id_extensions.dart'; import 'package:tmail_ui_user/features/caching/clients/hive_cache_version_client.dart'; import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart'; import 'package:tmail_ui_user/features/caching/manager/session_cache_manger.dart'; -import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart'; import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart'; import 'package:tmail_ui_user/features/cleanup/data/local/recent_login_url_cache_manager.dart'; import 'package:tmail_ui_user/features/cleanup/data/local/recent_login_username_cache_manager.dart'; @@ -20,13 +15,11 @@ import 'package:tmail_ui_user/features/login/data/local/oidc_configuration_cache import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox/data/local/state_cache_manager.dart'; -import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; import 'package:tmail_ui_user/features/offline_mode/manager/new_email_cache_manager.dart'; import 'package:tmail_ui_user/features/offline_mode/manager/opened_email_cache_manager.dart'; import 'package:tmail_ui_user/features/offline_mode/manager/sending_email_cache_manager.dart'; import 'package:tmail_ui_user/features/push_notification/data/keychain/keychain_sharing_manager.dart'; import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart'; -import 'package:tmail_ui_user/features/push_notification/presentation/extensions/type_name_extension.dart'; import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart'; class CachingManager { @@ -73,76 +66,108 @@ class CachingManager { ); Future clearAll() async { - await Future.wait([ - clearMailDataCached(), - _fcmCacheManager.clear(), - _accountCacheManager.clear(), - if (PlatformInfo.isIOS) - _keychainSharingManager.delete() - ], eagerError: true); + try { + await Future.wait([ + clearMailDataCached(), + clearAccountDataCached(), + ], eagerError: true); + } catch (e) { + logWarning('CachingManager::clearAll: Cannot clear all cache: $e'); + } } Future clearMailDataCached() async { - await Future.wait([ - _stateCacheManager.clear(), - _mailboxCacheManager.clear(), - _emailCacheManager.clear(), - if (PlatformInfo.isMobile) - ...[ - _sessionCacheManager.clear(), - _newEmailCacheManager.clear(), - _openedEmailCacheManager.clear(), - _sendingEmailCacheManager.clearAllSendingEmails(), - ], - ], eagerError: true); + try { + await Future.wait([ + _stateCacheManager.clear(), + _mailboxCacheManager.clear(), + _emailCacheManager.clear(), + _clearFCMStateCache(), + if (PlatformInfo.isMobile) + ...[ + clearDetailedEmailCache(), + _sendingEmailCacheManager.clear(), + _sessionCacheManager.clear(), + ], + if (PlatformInfo.isIOS) + _keychainSharingManager.delete(), + ], eagerError: true); + } catch (e) { + logWarning('CachingManager::clearMailDataCached: Cannot clear mail data cache: $e'); + } } - Future clearEmailAndStateCache({AccountId? accountId, UserName? userName}) { - log('CachingManager::clearEmailAndStateCache:userName=$userName'); - - final hasUserContext = accountId != null && userName != null; - - return Future.wait([ - if (hasUserContext) - ..._clearEmailAndStateWithUser(accountId, userName) - else - ..._clearEmailAndStateWithoutUser(), - - if (PlatformInfo.isMobile) - clearFCMEmailStateCache(accountId: accountId, userName: userName), - ]); + Future clearAccountDataCached() async { + try { + await Future.wait([ + _accountCacheManager.clear(), + _oidcConfigurationCacheManager.clear(), + _tokenOidcCacheManager.clear(), + _authenticationInfoCacheManager.clear(), + ], eagerError: true); + } catch (e) { + logWarning('CachingManager::clearAccountDataCached: Cannot clear account data cache: $e'); + } } - Future clearDetailedEmailCache({AccountId? accountId, UserName? userName}) { - log('CachingManager::clearDetailedEmailCache:userName=$userName'); - - final hasUserContext = accountId != null && userName != null; - - return Future.wait([ - if (hasUserContext) - ..._clearDetailedEmailWithUser(accountId, userName) - else - ..._clearDetailedEmailWithoutUser(), - ]); + Future clearAllEmailAndStateCache() async { + try { + await Future.wait([ + _emailCacheManager.clear(), + _stateCacheManager.clear(), + _clearFCMStateCache(), + if (PlatformInfo.isMobile) + clearDetailedEmailCache(), + ]); + } catch (e) { + logWarning('CachingManager::_clearEmailAndStateCache: Cannot clear email and state cache: $e'); + } } - Future clearAllEmailAndStateCache({AccountId? accountId, UserName? userName}) { - log('CachingManager::clearAllEmailAndStateCache:userName=$userName'); - - return Future.wait([ - clearEmailAndStateCache(accountId: accountId, userName: userName), - if (PlatformInfo.isMobile) - clearDetailedEmailCache(accountId: accountId, userName: userName), - ]); + Future clearDetailedEmailCache() async { + try { + await Future.wait([ + _newEmailCacheManager.clear(), + _openedEmailCacheManager.clear(), + _clearEmailContentFileInStorage(), + ]); + } catch (e) { + logWarning('CachingManager::clearDetailedEmailCache: Cannot clear detailed email cache: $e'); + } } - Future clearMailboxCache() { - return Future.wait([ - _stateCacheManager.deleteContainKey( - StateType.mailbox.getTupleKeyStoredWithoutAccount(), - ), - _mailboxCacheManager.clear(), - ], eagerError: true); + Future _clearEmailContentFileInStorage() async { + try { + await _fileUtils.removeFolder( + CachingConstants.openedEmailContentFolderName, + ); + await _fileUtils.removeFolder( + CachingConstants.newEmailsContentFolderName, + ); + } catch (e) { + logWarning( + 'CachingManager::_clearEmailContentFileInStorage: Cannot clear file in storage: $e', + ); + } + } + + Future _clearFCMStateCache() async { + try { + await _fcmCacheManager.clear(); + } catch (e) { + logWarning('CachingManager::_clearFCMStateCache: Cannot clear fcm state cache: $e'); + } + } + + Future clearMailboxAndStateCache() async { + try { + await Future.wait([ + _mailboxCacheManager.clear(), + _stateCacheManager.clear(), + ], eagerError: true); + } catch (e) { + logWarning('CachingManager::clearMailboxCache: Cannot clear mailbox cache: $e'); + } } Future storeCacheVersion(int newVersion) async { @@ -157,75 +182,6 @@ class CachingManager { Future closeHive({bool isolated = true}) => HiveCacheConfig.instance.closeHive(isolated: isolated); - Future clearAllFileInStorage() async { - await _fileUtils.removeFolder(CachingConstants.openedEmailContentFolderName); - await _fileUtils.removeFolder(CachingConstants.newEmailsContentFolderName); - } - - Future clearFCMEmailStateCache({ - AccountId? accountId, - UserName? userName, - }) async { - final hasUserContext = accountId != null && userName != null; - - if (hasUserContext) { - await _fcmCacheManager.deleteByKey( - TypeName.emailDelivery.getTupleKeyStored(accountId, userName), - ); - await _fcmCacheManager.deleteByKey( - TypeName.emailType.getTupleKeyStored(accountId, userName), - ); - } else { - await _fcmCacheManager.deleteContainKey( - TypeName.emailDelivery.getTupleKeyStoredWithoutAccount(), - ); - await _fcmCacheManager.deleteContainKey( - TypeName.emailType.getTupleKeyStoredWithoutAccount(), - ); - } - } - - List> _clearEmailAndStateWithUser( - AccountId accountId, - UserName userName, - ) { - final emailKey = TupleKey(accountId.asString, userName.value).encodeKey; - final stateKey = StateType.email.getTupleKeyStored(accountId, userName); - - return [ - _emailCacheManager.deleteContainKey(emailKey), - _stateCacheManager.deleteByKey(stateKey), - ]; - } - - List> _clearEmailAndStateWithoutUser() { - final stateKey = StateType.email.getTupleKeyStoredWithoutAccount(); - return [ - _emailCacheManager.clear(), - _stateCacheManager.deleteContainKey(stateKey), - ]; - } - - List> _clearDetailedEmailWithUser( - AccountId accountId, - UserName userName, - ) { - final emailKey = TupleKey(accountId.asString, userName.value).encodeKey; - return [ - _newEmailCacheManager.deleteContainKey(emailKey), - _openedEmailCacheManager.deleteContainKey(emailKey), - clearAllFileInStorage(), - ]; - } - - List> _clearDetailedEmailWithoutUser() { - return [ - _newEmailCacheManager.clear(), - _openedEmailCacheManager.clear(), - clearAllFileInStorage(), - ]; - } - Future clearLoginRecentData() async { await Future.wait([ _recentLoginUrlCacheManager.clear(), diff --git a/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart b/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart index 3d8454d14..5edfd5b59 100644 --- a/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart +++ b/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart @@ -131,7 +131,7 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { @override Future deleteOidcConfiguration() { return Future.sync(() async { - return await _oidcConfigurationCacheManager.deleteOidcConfiguration(); + return await _oidcConfigurationCacheManager.clear(); }).catchError(_cacheExceptionThrower.throwException); } @@ -163,7 +163,7 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { @override Future deleteTokenOIDC() { return Future.sync(() async { - return await _tokenOidcCacheManager.deleteTokenOidc(); + return await _tokenOidcCacheManager.clear(); }).catchError(_cacheExceptionThrower.throwException); } diff --git a/lib/features/login/data/local/authentication_info_cache_manager.dart b/lib/features/login/data/local/authentication_info_cache_manager.dart index 84976b162..ead87850c 100644 --- a/lib/features/login/data/local/authentication_info_cache_manager.dart +++ b/lib/features/login/data/local/authentication_info_cache_manager.dart @@ -24,8 +24,8 @@ class AuthenticationInfoCacheManager extends CacheManagerInteraction { } } - Future removeAuthenticationInfo() { - return _authenticationInfoCacheClient.deleteItem(AuthenticationInfoCache.keyCacheValue); + Future clear() { + return _authenticationInfoCacheClient.clearAllData(); } @override diff --git a/lib/features/login/data/local/oidc_configuration_cache_manager.dart b/lib/features/login/data/local/oidc_configuration_cache_manager.dart index 3238d1ffb..eb21f3801 100644 --- a/lib/features/login/data/local/oidc_configuration_cache_manager.dart +++ b/lib/features/login/data/local/oidc_configuration_cache_manager.dart @@ -43,12 +43,9 @@ class OidcConfigurationCacheManager extends CacheManagerInteraction { ); } - Future deleteOidcConfiguration() async { - log('OidcConfigurationCacheManager::deleteOidcConfiguration()'); + Future clear() async { await Future.wait([ - _oidcConfigurationCacheClient.deleteItem( - CachingConstants.oidcConfigurationCacheKeyName, - ), + _oidcConfigurationCacheClient.clearAllData(), _sharedPreferences.remove(OIDCConstant.keyAuthorityOidc), ]); } diff --git a/lib/features/login/data/local/token_oidc_cache_manager.dart b/lib/features/login/data/local/token_oidc_cache_manager.dart index 0060bd750..7828e4d09 100644 --- a/lib/features/login/data/local/token_oidc_cache_manager.dart +++ b/lib/features/login/data/local/token_oidc_cache_manager.dart @@ -24,7 +24,7 @@ class TokenOidcCacheManager extends CacheManagerInteraction { Future persistOneTokenOidc(TokenOIDC tokenOIDC) async { log('TokenOidcCacheManager::persistOneTokenOidc(): $tokenOIDC'); - await _tokenOidcCacheClient.clearAllData(); + await clear(); log('TokenOidcCacheManager::persistOneTokenOidc(): key: ${tokenOIDC.tokenId.uuid}'); log('TokenOidcCacheManager::persistOneTokenOidc(): key\'s hash: ${tokenOIDC.tokenIdHash}'); log('TokenOidcCacheManager::persistOneTokenOidc(): token: ${tokenOIDC.token}'); @@ -32,7 +32,7 @@ class TokenOidcCacheManager extends CacheManagerInteraction { log('TokenOidcCacheManager::persistOneTokenOidc(): done'); } - Future deleteTokenOidc() async { + Future clear() async { await _tokenOidcCacheClient.clearAllData(); } diff --git a/lib/features/login/data/repository/credential_repository_impl.dart b/lib/features/login/data/repository/credential_repository_impl.dart index 283d54206..0e928801e 100644 --- a/lib/features/login/data/repository/credential_repository_impl.dart +++ b/lib/features/login/data/repository/credential_repository_impl.dart @@ -42,6 +42,6 @@ class CredentialRepositoryImpl extends CredentialRepository { @override Future removeAuthenticationInfo() { - return _authenticationInfoCacheManager.removeAuthenticationInfo(); + return _authenticationInfoCacheManager.clear(); } } \ No newline at end of file diff --git a/lib/features/login/presentation/login_controller.dart b/lib/features/login/presentation/login_controller.dart index f1997a39e..abdaf2825 100644 --- a/lib/features/login/presentation/login_controller.dart +++ b/lib/features/login/presentation/login_controller.dart @@ -14,7 +14,6 @@ import 'package:get/get.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; import 'package:jmap_dart_client/jmap/core/user_name.dart'; import 'package:model/account/password.dart'; -import 'package:model/extensions/session_extension.dart'; import 'package:model/oidc/oidc_configuration.dart'; import 'package:model/oidc/request/oidc_request.dart'; import 'package:model/oidc/response/oidc_response.dart'; @@ -255,10 +254,7 @@ class LoginController extends ReloadableController { SmartDialog.dismiss(); if (PlatformInfo.isWeb && AppConfig.isForceEmailQueryEnabled) { - await cachingManager.clearAllEmailAndStateCache( - accountId: session.safeAccountId, - userName: session.username - ); + await cachingManager.clearAllEmailAndStateCache(); } popAndPush( diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index 991461ee4..4f3658a8c 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -612,10 +612,7 @@ class MailboxDashBoardController extends ReloadableController Future onBeforeUnloadBrowserListener(html.Event event) async { log('MailboxDashBoardController::onBeforeUnloadBrowserListener:event = ${event.runtimeType} | hasComposer = ${twakeAppManager.hasComposer} | isExecutingBeforeReconnect = ${twakeAppManager.isExecutingBeforeReconnect}'); if (PlatformInfo.isWeb) { - await cachingManager.clearAllEmailAndStateCache( - accountId: accountId.value, - userName: sessionCurrent?.username, - ); + await cachingManager.clearAllEmailAndStateCache(); } if (event is html.BeforeUnloadEvent && diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart index 6201f8c06..dfa531473 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_controller.dart @@ -140,10 +140,7 @@ class ManageAccountDashBoardController extends ReloadableController @override Future onBeforeUnloadBrowserListener(html.Event event) async { if (PlatformInfo.isWeb) { - await cachingManager.clearAllEmailAndStateCache( - accountId: accountId.value, - userName: sessionCurrent?.username, - ); + await cachingManager.clearAllEmailAndStateCache(); } } diff --git a/lib/features/offline_mode/manager/sending_email_cache_manager.dart b/lib/features/offline_mode/manager/sending_email_cache_manager.dart index ed3cd0dfd..0a6885f8d 100644 --- a/lib/features/offline_mode/manager/sending_email_cache_manager.dart +++ b/lib/features/offline_mode/manager/sending_email_cache_manager.dart @@ -53,7 +53,7 @@ class SendingEmailCacheManager extends CacheManagerInteraction { return sendingEmailsCache; } - Future clearAllSendingEmails() => _hiveCacheClient.clearAllData(); + Future clear() => _hiveCacheClient.clearAllData(); Future updateSendingEmail( AccountId accountId, diff --git a/lib/features/push_notification/data/local/fcm_cache_manager.dart b/lib/features/push_notification/data/local/fcm_cache_manager.dart index 59e505a51..ea4741faf 100644 --- a/lib/features/push_notification/data/local/fcm_cache_manager.dart +++ b/lib/features/push_notification/data/local/fcm_cache_manager.dart @@ -89,11 +89,6 @@ class FCMCacheManager extends CacheManagerInteraction { ]); } - Future deleteByKey(String key) => _fcmCacheClient.deleteItem(key); - - Future deleteContainKey(String key) => - _fcmCacheClient.clearAllDataContainKey(key); - @override Future migrateHiveToIsolatedHive() async { await Future.wait([ diff --git a/lib/features/thread/data/datasource/thread_datasource.dart b/lib/features/thread/data/datasource/thread_datasource.dart index 2ce28b889..b0265ff7b 100644 --- a/lib/features/thread/data/datasource/thread_datasource.dart +++ b/lib/features/thread/data/datasource/thread_datasource.dart @@ -77,5 +77,5 @@ abstract class ThreadDataSource { Future getEmailById(Session session, AccountId accountId, EmailId emailId, {Properties? properties}); - Future clearEmailCacheAndStateCache(AccountId accountId, Session session); + Future clearEmailCacheAndStateCache(); } \ No newline at end of file diff --git a/lib/features/thread/data/datasource_impl/local_thread_datasource_impl.dart b/lib/features/thread/data/datasource_impl/local_thread_datasource_impl.dart index 309eeef1c..61f960380 100644 --- a/lib/features/thread/data/datasource_impl/local_thread_datasource_impl.dart +++ b/lib/features/thread/data/datasource_impl/local_thread_datasource_impl.dart @@ -133,12 +133,9 @@ class LocalThreadDataSourceImpl extends ThreadDataSource { } @override - Future clearEmailCacheAndStateCache(AccountId accountId, Session session) { + Future clearEmailCacheAndStateCache() { return Future.sync(() async { - return await _cachingManager.clearAllEmailAndStateCache( - accountId: accountId, - userName: session.username, - ); + return await _cachingManager.clearAllEmailAndStateCache(); }).catchError(_exceptionThrower.throwException); } } \ No newline at end of file diff --git a/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart b/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart index 1f4f155e5..ab90f24be 100644 --- a/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart +++ b/lib/features/thread/data/datasource_impl/thread_datasource_impl.dart @@ -142,7 +142,7 @@ class ThreadDataSourceImpl extends ThreadDataSource { } @override - Future clearEmailCacheAndStateCache(AccountId accountId, Session session) { + Future clearEmailCacheAndStateCache() { throw UnimplementedError(); } } \ No newline at end of file diff --git a/lib/features/thread/data/repository/thread_repository_impl.dart b/lib/features/thread/data/repository/thread_repository_impl.dart index 51eec34a1..0c72b2f90 100644 --- a/lib/features/thread/data/repository/thread_repository_impl.dart +++ b/lib/features/thread/data/repository/thread_repository_impl.dart @@ -148,37 +148,8 @@ class ThreadRepositoryImpl extends ThreadRepository { EmailFilter? emailFilter, Properties? propertiesCreated, }) async* { - final localDataSource = mapDataSource[DataSourceType.local]; - final networkDataSource = mapDataSource[DataSourceType.network]; - - if (localDataSource == null || networkDataSource == null) { - logError( - 'ThreadRepositoryImpl::forceQueryAllEmailsForWeb(): ' - 'Missing required data sources (local or network).', - ); - return; - } - - List cachedList = const []; jmap.State? cachedState; - // Load cached emails - try { - cachedList = await localDataSource.getAllEmailCache( - accountId, - session.username, - inMailboxId: emailFilter?.mailboxId, - sort: sort, - limit: limit, - filterOption: emailFilter?.filterOption, - ); - } catch (_) { - logError( - 'ThreadRepositoryImpl::forceQueryAllEmailsForWeb(): ' - 'Failed to load cached emails', - ); - } - // Load cached state try { cachedState = await stateDataSource.getState( @@ -187,29 +158,19 @@ class ThreadRepositoryImpl extends ThreadRepository { StateType.email, ); } catch (_) { - logError( + logWarning( 'ThreadRepositoryImpl::forceQueryAllEmailsForWeb(): ' 'Failed to load cached email state', ); } - final localResponse = EmailsResponse( - emailList: cachedList, - state: cachedState, - ); - log( 'ThreadRepositoryImpl::forceQueryAllEmailsForWeb(): ' - 'Local cache count = ${cachedList.length}; ' - 'State = ${cachedState?.value}', + 'State cache = ${cachedState?.value}', ); - if (localResponse.hasEmails()) { - yield localResponse; - } - // Query fresh emails from server - final serverResponse = await networkDataSource.getAllEmail( + final serverResponse = await mapDataSource[DataSourceType.network]!.getAllEmail( session, accountId, limit: limit, @@ -588,13 +549,8 @@ class ThreadRepositoryImpl extends ThreadRepository { } @override - Future clearEmailCacheAndStateCache( - AccountId accountId, - Session session, - ) => mapDataSource[DataSourceType.local]!.clearEmailCacheAndStateCache( - accountId, - session, - ); + Future clearEmailCacheAndStateCache() => + mapDataSource[DataSourceType.local]!.clearEmailCacheAndStateCache(); @override Stream loadAllEmailInFolderWithoutCache({ diff --git a/lib/features/thread/domain/repository/thread_repository.dart b/lib/features/thread/domain/repository/thread_repository.dart index 70510b087..c4f381bca 100644 --- a/lib/features/thread/domain/repository/thread_repository.dart +++ b/lib/features/thread/domain/repository/thread_repository.dart @@ -102,5 +102,5 @@ abstract class ThreadRepository { StreamController> onProgressController ); - Future clearEmailCacheAndStateCache(AccountId accountId, Session session); + Future clearEmailCacheAndStateCache(); } \ No newline at end of file diff --git a/lib/features/thread/domain/usecases/clean_and_get_emails_in_mailbox_interactor.dart b/lib/features/thread/domain/usecases/clean_and_get_emails_in_mailbox_interactor.dart index 70c40be2f..7f72d18c9 100644 --- a/lib/features/thread/domain/usecases/clean_and_get_emails_in_mailbox_interactor.dart +++ b/lib/features/thread/domain/usecases/clean_and_get_emails_in_mailbox_interactor.dart @@ -36,7 +36,7 @@ class CleanAndGetEmailsInMailboxInteractor { try { yield Right(CleanAndGetAllEmailLoading()); - await _threadRepository.clearEmailCacheAndStateCache(accountId, session); + await _threadRepository.clearEmailCacheAndStateCache(); yield* _getEmailsInMailboxInteractor.execute( session, diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index bf2be0974..070a42be8 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -480,10 +480,7 @@ class ThreadController extends BaseController with EmailActionController { void _handleErrorGetAllOrRefreshChangesEmail(Object error, StackTrace stackTrace) async { logWarning('ThreadController::_handleErrorGetAllOrRefreshChangesEmail():Error: $error'); if (error is CannotCalculateChangesMethodResponseException) { - await cachingManager.clearAllEmailAndStateCache( - accountId: _accountId, - userName: _session?.username, - ); + await cachingManager.clearAllEmailAndStateCache(); getAllEmailAction(); } else if (error is MethodLevelErrors) { if (currentOverlayContext != null && error.message != null) { @@ -609,10 +606,7 @@ class ThreadController extends BaseController with EmailActionController { Future refreshAllEmail({bool forceEmailQuery = false}) async { if (forceEmailQuery) { - await cachingManager.clearAllEmailAndStateCache( - accountId: mailboxDashBoardController.accountId.value, - userName: mailboxDashBoardController.sessionCurrent?.username, - ); + await cachingManager.clearAllEmailAndStateCache(); } if (searchController.isSearchEmailRunning) {