TF-1243 Fix move to after advance search result list went blank
This commit is contained in:
@@ -329,7 +329,12 @@ class MailboxController extends BaseMailboxController {
|
||||
void _initialMailboxVariableStorage({bool isRefreshChange = false}) {
|
||||
_setMapMailbox();
|
||||
_setOutboxMailbox();
|
||||
_selectMailboxDefault(isRefreshChange: isRefreshChange);
|
||||
|
||||
if (isRefreshChange) {
|
||||
_selectSelectedMailboxDefault();
|
||||
} else {
|
||||
_handleDataFromNavigationRouter();
|
||||
}
|
||||
}
|
||||
|
||||
void _setMapMailbox() {
|
||||
@@ -363,62 +368,63 @@ class MailboxController extends BaseMailboxController {
|
||||
}
|
||||
}
|
||||
|
||||
void _selectMailboxDefault({bool isRefreshChange = false}) {
|
||||
final mapDefaultMailbox = {
|
||||
for (var mailboxNode in defaultMailboxTree.value.root.childrenItems ?? List<MailboxNode>.empty())
|
||||
mailboxNode.item.role!: mailboxNode.item
|
||||
};
|
||||
void _selectSelectedMailboxDefault() {
|
||||
final isSearchEmailRunning = mailboxDashBoardController.searchController.isSearchEmailRunning;
|
||||
if (isSearchEmailRunning) {
|
||||
log('MailboxController::_selectMailboxDefault(): isSearchEmailRunning is $isSearchEmailRunning');
|
||||
return;
|
||||
}
|
||||
final mailboxSelected = _getCurrentSelectedMailbox();
|
||||
mailboxDashBoardController.setSelectedMailbox(mailboxSelected);
|
||||
}
|
||||
|
||||
PresentationMailbox? _getCurrentSelectedMailbox() {
|
||||
final mailboxCurrent = mailboxDashBoardController.selectedMailbox.value;
|
||||
final mapMailboxById = mailboxDashBoardController.mapMailboxById;
|
||||
final isSearchEmailRunning = mailboxDashBoardController.searchController.isSearchEmailRunning;
|
||||
|
||||
PresentationMailbox? mailboxSelected;
|
||||
final mapDefaultPresentationMailboxByRole = defaultMailboxTree.value.mapPresentationMailboxByRole;
|
||||
|
||||
if (mailboxCurrent != null) {
|
||||
if (mailboxCurrent.hasRole()) {
|
||||
mailboxSelected = mapDefaultMailbox.containsKey(mailboxCurrent.role)
|
||||
? mapDefaultMailbox[mailboxCurrent.role]
|
||||
return mapDefaultPresentationMailboxByRole.containsKey(mailboxCurrent.role)
|
||||
? mapDefaultPresentationMailboxByRole[mailboxCurrent.role]
|
||||
: mailboxCurrent;
|
||||
} else {
|
||||
mailboxSelected = mapMailboxById.containsKey(mailboxCurrent.id)
|
||||
return mapMailboxById.containsKey(mailboxCurrent.id)
|
||||
? mapMailboxById[mailboxCurrent.id]
|
||||
: mailboxCurrent;
|
||||
}
|
||||
} else {
|
||||
if (!isSearchEmailRunning) {
|
||||
if (mapDefaultMailbox.containsKey(PresentationMailbox.roleInbox)) {
|
||||
mailboxSelected = mapDefaultMailbox[PresentationMailbox.roleInbox];
|
||||
} else {
|
||||
if (allMailboxes.isNotEmpty) {
|
||||
mailboxSelected = allMailboxes.first;
|
||||
}
|
||||
}
|
||||
} else if (!isSearchEmailRunning) {
|
||||
if (mapDefaultPresentationMailboxByRole.containsKey(PresentationMailbox.roleInbox)) {
|
||||
return mapDefaultPresentationMailboxByRole[PresentationMailbox.roleInbox];
|
||||
} else if (allMailboxes.isNotEmpty) {
|
||||
return allMailboxes.first;
|
||||
}
|
||||
}
|
||||
|
||||
if (isRefreshChange) {
|
||||
mailboxDashBoardController.setSelectedMailbox(mailboxSelected);
|
||||
} else {
|
||||
if (isHasDataFromRoute) {
|
||||
log('MailboxController::_selectMailboxDefault(): isHasDataFromRoute is true:navigationRouter: $navigationRouter');
|
||||
if (mailboxIdFromNavigationRouter != null) {
|
||||
_selectMailboxFromRouter();
|
||||
} else if (emailIdFromNavigationRouter != null) {
|
||||
mailboxDashBoardController.dispatchAction(SelectEmailByIdAction(navigationRouter!));
|
||||
_clearNavigationRouter();
|
||||
} else if (searchQueryFromNavigationRouter != null) {
|
||||
mailboxDashBoardController.dispatchAction(SearchEmailByQueryAction(navigationRouter!));
|
||||
_clearNavigationRouter();
|
||||
} else {
|
||||
_clearNavigationRouter();
|
||||
mailboxDashBoardController.setSelectedMailbox(mailboxSelected);
|
||||
_updateSelectedMailboxRouteOnBrowser();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void _handleDataFromNavigationRouter() {
|
||||
log('MailboxController::_handleDataFromNavigationRouter():navigationRouter: $navigationRouter');
|
||||
|
||||
if (isHasDataFromRoute) {
|
||||
if (mailboxIdFromNavigationRouter != null) {
|
||||
_selectMailboxFromRouter();
|
||||
} else if (emailIdFromNavigationRouter != null) {
|
||||
mailboxDashBoardController.dispatchAction(SelectEmailByIdAction(navigationRouter!));
|
||||
_clearNavigationRouter();
|
||||
} else if (searchQueryFromNavigationRouter != null && searchQueryFromNavigationRouter?.value.isNotEmpty == true) {
|
||||
mailboxDashBoardController.dispatchAction(SearchEmailByQueryAction(navigationRouter!));
|
||||
_clearNavigationRouter();
|
||||
} else {
|
||||
log('MailboxController::_selectMailboxDefault(): isHasDataFromRoute is false');
|
||||
mailboxDashBoardController.setSelectedMailbox(mailboxSelected);
|
||||
_clearNavigationRouter();
|
||||
_selectSelectedMailboxDefault();
|
||||
_updateSelectedMailboxRouteOnBrowser();
|
||||
}
|
||||
} else {
|
||||
_selectSelectedMailboxDefault();
|
||||
_updateSelectedMailboxRouteOnBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:collection';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/mailbox/expand_mode.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:model/mailbox/select_mode.dart';
|
||||
|
||||
import 'mailbox_node.dart';
|
||||
@@ -99,6 +100,22 @@ class MailboxTree with EquatableMixin {
|
||||
return path;
|
||||
}
|
||||
|
||||
Map<Role, PresentationMailbox> get mapPresentationMailboxByRole {
|
||||
if (root.childrenItems?.isEmpty == true) {
|
||||
return {};
|
||||
} else {
|
||||
final listPresentationMailboxHasRole = root.childrenItems!
|
||||
.where((node) => node.item.role != null)
|
||||
.map((node) => node.item)
|
||||
.toList();
|
||||
|
||||
return {
|
||||
for (var mailbox in listPresentationMailboxHasRole)
|
||||
mailbox.role!: mailbox
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [root];
|
||||
}
|
||||
@@ -623,7 +623,7 @@ class ThreadController extends BaseController with EmailActionController {
|
||||
}
|
||||
|
||||
void _searchEmail({UnsignedInt? limit, EmailFilterCondition? filterCondition}) {
|
||||
if (_accountId != null && searchQuery != null) {
|
||||
if (_accountId != null) {
|
||||
searchController.activateSimpleSearch();
|
||||
|
||||
filterCondition = EmailFilterCondition(
|
||||
|
||||
Reference in New Issue
Block a user