From 85b9e49800c0addf0a75cae7752479e9e27bbf8d Mon Sep 17 00:00:00 2001 From: DatDang Date: Fri, 20 Dec 2024 10:47:39 +0700 Subject: [PATCH] TF-3332 Prevent refresh when switching mailbox --- .../thread/data/repository/thread_repository_impl.dart | 3 ++- lib/features/thread/domain/repository/thread_repository.dart | 1 + .../domain/usecases/get_emails_in_mailbox_interactor.dart | 4 +++- lib/features/thread/presentation/thread_controller.dart | 5 +++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/features/thread/data/repository/thread_repository_impl.dart b/lib/features/thread/data/repository/thread_repository_impl.dart index 3541a07f6..7334f919c 100644 --- a/lib/features/thread/data/repository/thread_repository_impl.dart +++ b/lib/features/thread/data/repository/thread_repository_impl.dart @@ -45,6 +45,7 @@ class ThreadRepositoryImpl extends ThreadRepository { EmailFilter? emailFilter, Properties? propertiesCreated, Properties? propertiesUpdated, + bool getLatestChanges = true, } ) async* { log('ThreadRepositoryImpl::getAllEmail(): filter = ${emailFilter?.mailboxId}'); @@ -92,7 +93,7 @@ class ThreadRepositoryImpl extends ThreadRepository { await _updateEmailCache(accountId, session.username, newCreated: networkEmailResponse.emailList); } - if (localEmailResponse.hasState()) { + if (localEmailResponse.hasState() && getLatestChanges) { log('ThreadRepositoryImpl::getAllEmail(): filter = ${emailFilter?.mailboxId} local has state: ${localEmailResponse.state}'); await _synchronizeCacheWithChanges( session, diff --git a/lib/features/thread/domain/repository/thread_repository.dart b/lib/features/thread/domain/repository/thread_repository.dart index 87e6ea37b..e794b893c 100644 --- a/lib/features/thread/domain/repository/thread_repository.dart +++ b/lib/features/thread/domain/repository/thread_repository.dart @@ -25,6 +25,7 @@ abstract class ThreadRepository { EmailFilter? emailFilter, Properties? propertiesCreated, Properties? propertiesUpdated, + bool getLatestChanges = true, } ); diff --git a/lib/features/thread/domain/usecases/get_emails_in_mailbox_interactor.dart b/lib/features/thread/domain/usecases/get_emails_in_mailbox_interactor.dart index 7bb5fa1e7..0eccaae50 100644 --- a/lib/features/thread/domain/usecases/get_emails_in_mailbox_interactor.dart +++ b/lib/features/thread/domain/usecases/get_emails_in_mailbox_interactor.dart @@ -26,6 +26,7 @@ class GetEmailsInMailboxInteractor { EmailFilter? emailFilter, Properties? propertiesCreated, Properties? propertiesUpdated, + bool getLatestChanges = true, } ) async* { try { @@ -39,7 +40,8 @@ class GetEmailsInMailboxInteractor { sort: sort, emailFilter: emailFilter, propertiesCreated: propertiesCreated, - propertiesUpdated: propertiesUpdated) + propertiesUpdated: propertiesUpdated, + getLatestChanges: getLatestChanges) .map((emailResponse) => _toGetEmailState( emailResponse: emailResponse, currentMailboxId: emailFilter?.mailboxId diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index fd0e31026..36d944d58 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -254,7 +254,7 @@ class ThreadController extends BaseController with EmailActionController { _currentMemoryMailboxId = mailbox.id; consumeState(Stream.value(Right(GetAllEmailLoading()))); _resetToOriginalValue(); - _getAllEmailAction(); + _getAllEmailAction(getLatestChanges: false); } else if (mailbox == null) { // disable current mailbox when search active _currentMemoryMailboxId = null; _resetToOriginalValue(); @@ -446,7 +446,7 @@ class ThreadController extends BaseController with EmailActionController { } } - void _getAllEmailAction() { + void _getAllEmailAction({bool getLatestChanges = true}) { log('ThreadController::_getAllEmailAction:'); if (_session != null &&_accountId != null) { consumeState(_getEmailsInMailboxInteractor.execute( @@ -461,6 +461,7 @@ class ThreadController extends BaseController with EmailActionController { ), propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(_session!, _accountId!), propertiesUpdated: ThreadConstants.propertiesUpdatedDefault, + getLatestChanges: getLatestChanges, )); } else { consumeState(Stream.value(Left(GetAllEmailFailure(NotFoundSessionException()))));