diff --git a/docs/adr/0070-sync-strategy-disappearing-emails.md b/docs/adr/0070-sync-strategy-disappearing-emails.md index ee9aca2fe..7c314a24e 100644 --- a/docs/adr/0070-sync-strategy-disappearing-emails.md +++ b/docs/adr/0070-sync-strategy-disappearing-emails.md @@ -20,7 +20,7 @@ The issue typically manifests in the following sequence, as reported in [Issue # * **Crucially:** The email *can* be found using the Search function (proving data existence). -4. **Resolution:** The user is forced to **Logout and Login**, which magically restores the email to the list. +4. **Resolution:** The user is forced to **log out and log in**, which magically restores the email to the list. ### Root Cause Analysis @@ -104,4 +104,4 @@ FORCE_EMAIL_QUERY=false ## References -* **Github Issue:** [linagora/tmail-flutter#4274](https://github.com/linagora/tmail-flutter/issues/4274) \ No newline at end of file +* **GitHub Issue:** [linagora/tmail-flutter#4274](https://github.com/linagora/tmail-flutter/issues/4274) \ No newline at end of file diff --git a/lib/features/base/base_controller.dart b/lib/features/base/base_controller.dart index ef1675f45..79ca8cefe 100644 --- a/lib/features/base/base_controller.dart +++ b/lib/features/base/base_controller.dart @@ -506,7 +506,7 @@ abstract class BaseController extends GetxController if (_isFcmEnabled) { await _handleDeleteFCMRegistration(); } - clearAllData(); + await clearAllData(); } Future _handleDeleteFCMRegistration() async { diff --git a/lib/features/caching/caching_manager.dart b/lib/features/caching/caching_manager.dart index a48382762..7e06bd05d 100644 --- a/lib/features/caching/caching_manager.dart +++ b/lib/features/caching/caching_manager.dart @@ -70,7 +70,7 @@ class CachingManager { await Future.wait([ clearMailDataCached(), clearAccountDataCached(), - ], eagerError: true); + ]); } catch (e) { logWarning('CachingManager::clearAll: Cannot clear all cache: $e'); } diff --git a/lib/features/login/presentation/login_controller.dart b/lib/features/login/presentation/login_controller.dart index 73f35c549..79d7afb2d 100644 --- a/lib/features/login/presentation/login_controller.dart +++ b/lib/features/login/presentation/login_controller.dart @@ -254,7 +254,11 @@ class LoginController extends ReloadableController { SmartDialog.dismiss(); if (PlatformInfo.isWeb) { - await cachingManager.clearAllEmailAndStateCache(); + try { + await cachingManager.clearAllEmailAndStateCache(); + } catch (e) { + logWarning('$runtimeType::handleReloaded: Failed to clear cache: $e'); + } } 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 4f3658a8c..289711b6c 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -611,14 +611,16 @@ class MailboxDashBoardController extends ReloadableController @override Future onBeforeUnloadBrowserListener(html.Event event) async { log('MailboxDashBoardController::onBeforeUnloadBrowserListener:event = ${event.runtimeType} | hasComposer = ${twakeAppManager.hasComposer} | isExecutingBeforeReconnect = ${twakeAppManager.isExecutingBeforeReconnect}'); - if (PlatformInfo.isWeb) { - await cachingManager.clearAllEmailAndStateCache(); + final shouldPrevent = event is html.BeforeUnloadEvent && + twakeAppManager.hasComposer && + !twakeAppManager.isExecutingBeforeReconnect; + + if (shouldPrevent) { + event.preventDefault(); } - if (event is html.BeforeUnloadEvent && - twakeAppManager.hasComposer && - !twakeAppManager.isExecutingBeforeReconnect) { - event.preventDefault(); + if (PlatformInfo.isWeb) { + await cachingManager.clearAllEmailAndStateCache(); } } diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index 070a42be8..60daa4d5b 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -355,7 +355,7 @@ class ThreadController extends BaseController with EmailActionController { if (action is RefreshChangeEmailAction) { _refreshEmailChanges(newState: action.newState); } else if (action is RefreshAllEmailAction) { - refreshAllEmail(forceEmailQuery: true); + refreshAllEmail(shouldClearCache: PlatformInfo.isWeb); mailboxDashBoardController.clearEmailUIAction(); } }); @@ -604,8 +604,8 @@ class ThreadController extends BaseController with EmailActionController { } } - Future refreshAllEmail({bool forceEmailQuery = false}) async { - if (forceEmailQuery) { + Future refreshAllEmail({bool shouldClearCache = false}) async { + if (shouldClearCache) { await cachingManager.clearAllEmailAndStateCache(); } @@ -622,7 +622,7 @@ class ThreadController extends BaseController with EmailActionController { if (searchController.isSearchEmailRunning) { _searchEmail(limit: limitEmailFetched); } else { - getAllEmailAction(forceEmailQuery: forceEmailQuery); + getAllEmailAction(); } }