TF-3332 Prevent refresh when switching mailbox

This commit is contained in:
DatDang
2024-12-20 10:47:39 +07:00
committed by Dat H. Pham
parent 091d52e635
commit 85b9e49800
4 changed files with 9 additions and 4 deletions
@@ -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,
@@ -25,6 +25,7 @@ abstract class ThreadRepository {
EmailFilter? emailFilter,
Properties? propertiesCreated,
Properties? propertiesUpdated,
bool getLatestChanges = true,
}
);
@@ -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
@@ -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()))));