From dfaf745ce98c2f1982e6cdc05cf8e2644f3a694a Mon Sep 17 00:00:00 2001 From: dab246 Date: Thu, 30 Oct 2025 13:57:58 +0700 Subject: [PATCH] TF-1715 Auto refresh list emails in Favorite folder when message incoming or message changed --- .../presentation/mailbox_controller.dart | 3 ++ .../presentation/thread_controller.dart | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index 455159a5a..a07593537 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -278,6 +278,8 @@ class MailboxController extends BaseMailboxController if (PlatformInfo.isIOS) { _updateMailboxIdsBlockNotificationToKeychain(success.mailboxList); } + } else if (success is CreateDefaultMailboxAllSuccess) { + addFavoriteFolderToMailboxList(); } }); } @@ -599,6 +601,7 @@ class MailboxController extends BaseMailboxController if (currentContext != null) { syncAllMailboxWithDisplayName(currentContext!); } + addFavoriteFolderToMailboxList(); _setMapMailbox(); _setOutboxMailbox(); _selectSelectedMailboxDefault(); diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index d2e4f5a18..08d8b4f43 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -711,6 +711,8 @@ class ThreadController extends BaseController with EmailActionController { try { if (searchController.isSearchEmailRunning && PlatformInfo.isWeb) { await _refreshChangeSearchEmail(); + } else if (selectedMailboxId?.isFavoriteMailboxId == true) { + await _refreshChangeListEmailsInFavoriteFolder(); } else { await _refreshChangeListEmail(); } @@ -815,6 +817,40 @@ class ThreadController extends BaseController with EmailActionController { } } + Future _refreshChangeListEmailsInFavoriteFolder() async { + log('ThreadController::_refreshChangeListEmailsInFavoriteFolder:'); + + await _refreshChangeListEmailCache(); + + final viewState = await _getEmailsInMailboxInteractor + .execute( + _session!, + _accountId!, + limit: limitEmailFetched, + sort: EmailSortOrderType.mostRecent.getSortOrder().toNullable(), + emailFilter: getEmailFilterForLoadMailbox(), + propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod( + _session!, + _accountId!, + ), + propertiesUpdated: EmailUtils.getPropertiesForEmailChangeMethod( + _session!, + _accountId!, + ), + useCache: false, + ) + .last; + + final emailSuccessState = viewState + .foldSuccessWithResult(); + + if (emailSuccessState is GetAllEmailSuccess) { + _getAllEmailSuccess(emailSuccessState); + } else { + onDataFailureViewState(emailSuccessState); + } + } + void _loadMoreEmails() { log('ThreadController::_loadMoreEmails()::canLoadMore = $canLoadMore'); if (canLoadMore && _session != null && _accountId != null) {