TF-2925 Fix change mailbox very quick when refreshing after any mail action make the message list is not showed correctly

This commit is contained in:
dab246
2024-07-19 16:04:44 +07:00
committed by Dat H. Pham
parent 76e5b01ac6
commit 71ae708939
9 changed files with 76 additions and 34 deletions
@@ -104,7 +104,6 @@ class ThreadController extends BaseController with EmailActionController {
bool canLoadMore = false;
bool canSearchMore = false;
MailboxId? _currentMailboxId;
jmap.State? _currentEmailState;
final ScrollController listEmailController = ScrollController();
final FocusNode focusNodeKeyBoard = FocusNode();
@@ -116,6 +115,8 @@ class ThreadController extends BaseController with EmailActionController {
PresentationMailbox? get currentMailbox => mailboxDashBoardController.selectedMailbox.value;
MailboxId? get _currentMailboxId => currentMailbox?.mailboxId;
search.SearchController get searchController => mailboxDashBoardController.searchController;
SearchEmailFilter get _searchEmailFilter => searchController.searchEmailFilter.value;
@@ -142,7 +143,7 @@ class ThreadController extends BaseController with EmailActionController {
@override
void onReady() {
dispatchState(Right(LoadingState()));
consumeState(Stream.value(Right(GetAllEmailLoading())));
super.onReady();
}
@@ -234,15 +235,10 @@ class ThreadController extends BaseController with EmailActionController {
void _registerObxStreamListener() {
ever(mailboxDashBoardController.selectedMailbox, (mailbox) {
if (mailbox is PresentationMailbox) {
if (_currentMailboxId != mailbox.id) {
_currentMailboxId = mailbox.id;
_resetToOriginalValue();
_getAllEmailAction();
}
} else if (mailbox == null) { // disable current mailbox when search active
_currentMailboxId = null;
_resetToOriginalValue();
log('ThreadController::_registerObxStreamListener:ever: SELECTED_MAILBOX_ID = ${mailbox?.id.asString} | SELECTED_MAILBOX_NAME = ${mailbox?.name?.name}');
_resetToOriginalValue();
if (mailbox != null) {
_getAllEmailAction();
}
});
@@ -425,14 +421,21 @@ class ThreadController extends BaseController with EmailActionController {
}
void _resetToOriginalValue() {
dispatchState(Right(LoadingState()));
log('ThreadController::_resetToOriginalValue:');
consumeState(Stream.value(Right(GetAllEmailLoading())));
mailboxDashBoardController.emailsInCurrentMailbox.clear();
mailboxDashBoardController.listEmailSelected.clear();
mailboxDashBoardController.currentSelectMode.value = SelectMode.INACTIVE;
canLoadMore = false;
loadingMoreStatus.value = LoadingMoreStatus.idle;
cancelSelectEmail();
}
void _getAllEmailSuccess(GetAllEmailSuccess success) {
if (success.currentMailboxId != currentMailbox?.mailboxId) {
log('ThreadController::_getAllEmailSuccess: SELECTED_MAILBOX_ID = ${success.currentMailboxId?.asString} | CURRENT_MAILBOX_ID = ${currentMailbox?.mailboxId?.asString} | CURRENT_MAILBOX_NAME = ${currentMailbox?.name?.name}');
return;
}
mailboxDashBoardController.refreshingMailboxState.value = Right(success);
_currentEmailState = success.currentEmailState;
log('ThreadController::_getAllEmailSuccess():COUNT = ${success.emailList.length} | EMAIL_STATE = $_currentEmailState');
@@ -460,6 +463,11 @@ class ThreadController extends BaseController with EmailActionController {
}
void _refreshChangesAllEmailSuccess(RefreshChangesAllEmailSuccess success) {
if (success.currentMailboxId != currentMailbox?.mailboxId) {
log('ThreadController::_refreshChangesAllEmailSuccess: SELECTED_MAILBOX_ID = ${success.currentMailboxId?.asString} | CURRENT_MAILBOX_ID = ${currentMailbox?.mailboxId?.asString} | CURRENT_MAILBOX_NAME = ${currentMailbox?.name?.name}');
return;
}
_currentEmailState = success.currentEmailState;
log('ThreadController::_refreshChangesAllEmailSuccess: COUNT = ${success.emailList.length}');
final emailsBeforeChanges = mailboxDashBoardController.emailsInCurrentMailbox;