TF-1708 Improvement search mailbox by display name at locale

(cherry picked from commit f3efbe715c06b87ce3006dc936be26dd272a643c)
This commit is contained in:
dab246
2023-07-06 19:35:11 +07:00
committed by Dat Vu
parent e94f1959f1
commit 36f13051bd
11 changed files with 122 additions and 47 deletions
+11 -2
View File
@@ -27,6 +27,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_request.da
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/presentation_mailbox_extension.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories_expand_mode.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories_expand_mode.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
@@ -68,7 +69,7 @@ abstract class BaseMailboxController extends BaseController {
List<PresentationMailbox> allMailboxes = <PresentationMailbox>[]; List<PresentationMailbox> allMailboxes = <PresentationMailbox>[];
Future buildTree( Future<void> buildTree(
List<PresentationMailbox> allMailbox, List<PresentationMailbox> allMailbox,
{MailboxId? mailboxIdSelected} {MailboxId? mailboxIdSelected}
) async { ) async {
@@ -85,7 +86,7 @@ abstract class BaseMailboxController extends BaseController {
allMailboxes = tupleTree.value4; allMailboxes = tupleTree.value4;
} }
Future refreshTree(List<PresentationMailbox> allMailbox) async { Future<void> refreshTree(List<PresentationMailbox> allMailbox) async {
allMailboxes = allMailbox; allMailboxes = allMailbox;
final tupleTree = await _treeBuilder.generateMailboxTreeInUIAfterRefreshChanges( final tupleTree = await _treeBuilder.generateMailboxTreeInUIAfterRefreshChanges(
allMailbox, allMailbox,
@@ -100,6 +101,14 @@ abstract class BaseMailboxController extends BaseController {
teamMailboxesTree.value = tupleTree.value3; teamMailboxesTree.value = tupleTree.value3;
} }
Future<void> syncAllMailboxWithDisplayName(BuildContext context) async {
log("BaseMailboxController::syncAllMailboxWithDisplayName");
final syncedMailbox = allMailboxes
.map((mailbox) => mailbox.withDisplayName(mailbox.getDisplayName(context)))
.toList();
allMailboxes = syncedMailbox;
}
void toggleMailboxFolder(MailboxNode selectedMailboxNode, ScrollController scrollController) { void toggleMailboxFolder(MailboxNode selectedMailboxNode, ScrollController scrollController) {
final newExpandMode = selectedMailboxNode.expandMode == ExpandMode.COLLAPSE final newExpandMode = selectedMailboxNode.expandMode == ExpandMode.COLLAPSE
? ExpandMode.EXPAND ? ExpandMode.EXPAND
@@ -25,6 +25,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/usecases/create_new_mailbo
import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/domain/usecases/search_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/search_mailbox_interactor.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/extensions/presentation_mailbox_extension.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_categories.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
@@ -104,18 +105,24 @@ class DestinationPickerController extends BaseMailboxController {
} }
@override @override
void handleSuccessViewState(Success success) { void handleSuccessViewState(Success success) async {
super.handleSuccessViewState(success); super.handleSuccessViewState(success);
if (success is GetAllMailboxSuccess) { if (success is GetAllMailboxSuccess) {
if (mailboxAction.value == MailboxActions.move && mailboxIdSelected != null) { if (mailboxAction.value == MailboxActions.move && mailboxIdSelected != null) {
buildTree( await buildTree(
success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes, success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes,
mailboxIdSelected: mailboxIdSelected); mailboxIdSelected: mailboxIdSelected);
} else { } else {
buildTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes); await buildTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes);
}
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
} }
} else if (success is RefreshChangesAllMailboxSuccess) { } else if (success is RefreshChangesAllMailboxSuccess) {
refreshTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes); await refreshTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes);
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
} else if (success is SearchMailboxSuccess) { } else if (success is SearchMailboxSuccess) {
_searchMailboxSuccess(success); _searchMailboxSuccess(success);
} else if (success is CreateNewMailboxSuccess) { } else if (success is CreateNewMailboxSuccess) {
@@ -271,13 +278,17 @@ class DestinationPickerController extends BaseMailboxController {
listMailboxSearched.clear(); listMailboxSearched.clear();
} }
void searchMailbox(String value) { void searchMailbox(BuildContext context, String value) {
searchQuery.value = SearchQuery(value); searchQuery.value = SearchQuery(value);
final searchableMailboxList = mailboxAction.value == MailboxActions.moveEmail final searchableMailboxList = mailboxAction.value == MailboxActions.moveEmail
? allMailboxes ? allMailboxes
: allMailboxes.listPersonalMailboxes; : allMailboxes.listPersonalMailboxes;
_searchMailboxAction(searchableMailboxList, searchQuery.value); final mailboxListWithDisplayName = searchableMailboxList
.map((mailbox) => mailbox.withDisplayName(mailbox.getDisplayName(context)))
.toList();
_searchMailboxAction(mailboxListWithDisplayName, searchQuery.value);
} }
void _searchMailboxAction(List<PresentationMailbox> allMailboxes, SearchQuery searchQuery) { void _searchMailboxAction(List<PresentationMailbox> allMailboxes, SearchQuery searchQuery) {
@@ -559,8 +559,8 @@ class DestinationPickerView extends GetWidget<DestinationPickerController>
fit: BoxFit.fill), fit: BoxFit.fill),
hintText: AppLocalizations.of(context).hint_search_mailboxes, hintText: AppLocalizations.of(context).hint_search_mailboxes,
onClearTextSearchAction: controller.clearSearchText, onClearTextSearchAction: controller.clearSearchText,
onTextChangeSearchAction: controller.searchMailbox, onTextChangeSearchAction: (query) => controller.searchMailbox(context, query),
onSearchTextAction: controller.searchMailbox, onSearchTextAction: (query) => controller.searchMailbox(context, query),
)) ))
] ]
) )
@@ -12,7 +12,7 @@ class SearchMailboxInteractor {
yield Right<Failure, Success>(LoadingSearchMailbox()); yield Right<Failure, Success>(LoadingSearchMailbox());
final resultList = mailboxes final resultList = mailboxes
.where((mailbox) => mailbox.name?.name.toLowerCase().contains(searchQuery.value.toLowerCase()) == true) .where((mailbox) => _matchMailboxByQuery(mailbox, searchQuery))
.toList(); .toList();
yield Right<Failure, Success>(SearchMailboxSuccess(resultList)); yield Right<Failure, Success>(SearchMailboxSuccess(resultList));
@@ -20,4 +20,13 @@ class SearchMailboxInteractor {
yield Left<Failure, Success>(SearchMailboxFailure(exception)); yield Left<Failure, Success>(SearchMailboxFailure(exception));
} }
} }
bool _matchMailboxByQuery(PresentationMailbox mailbox, SearchQuery searchQuery) {
if (mailbox.displayName == null) {
return false;
} else {
return mailbox.displayName!.toLowerCase().contains(searchQuery.value.toLowerCase()) ||
searchQuery.value.toLowerCase().contains(mailbox.displayName!.toLowerCase());
}
}
} }
@@ -1,5 +1,4 @@
import 'package:core/utils/app_logger.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:model/mailbox/presentation_mailbox.dart'; import 'package:model/mailbox/presentation_mailbox.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
@@ -8,7 +7,6 @@ extension PresentationMailboxExtension on PresentationMailbox {
String getDisplayName(BuildContext context) { String getDisplayName(BuildContext context) {
if (isDefault) { if (isDefault) {
log("PresentationMailboxExtension::getDisplayName:Role: $role | MailboxName: $name");
switch(role!.value.toLowerCase()) { switch(role!.value.toLowerCase()) {
case PresentationMailbox.inboxRole: case PresentationMailbox.inboxRole:
return AppLocalizations.of(context).inboxMailboxDisplayName; return AppLocalizations.of(context).inboxMailboxDisplayName;
@@ -998,12 +998,18 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
currentMailboxState = success.currentMailboxState; currentMailboxState = success.currentMailboxState;
final listMailboxDisplayed = success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes; final listMailboxDisplayed = success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes;
await buildTree(listMailboxDisplayed); await buildTree(listMailboxDisplayed);
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
} }
void _handleRefreshChangesAllMailboxSuccess(RefreshChangesAllMailboxSuccess success) async { void _handleRefreshChangesAllMailboxSuccess(RefreshChangesAllMailboxSuccess success) async {
currentMailboxState = success.currentMailboxState; currentMailboxState = success.currentMailboxState;
final listMailboxDisplayed = success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes; final listMailboxDisplayed = success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes;
await refreshTree(listMailboxDisplayed); await refreshTree(listMailboxDisplayed);
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
} }
void _unsubscribeMailboxAction(MailboxId mailboxId) { void _unsubscribeMailboxAction(MailboxId mailboxId) {
@@ -65,14 +65,17 @@ class MailboxVisibilityController extends BaseMailboxController {
} }
@override @override
void handleSuccessViewState(Success success) { void handleSuccessViewState(Success success) async {
super.handleSuccessViewState(success); super.handleSuccessViewState(success);
if (success is GetAllMailboxSuccess) { if (success is GetAllMailboxSuccess) {
currentMailboxState = success.currentMailboxState; currentMailboxState = success.currentMailboxState;
_handleBuildTree(success.mailboxList); _handleBuildTree(success.mailboxList);
} else if (success is RefreshChangesAllMailboxSuccess) { } else if (success is RefreshChangesAllMailboxSuccess) {
currentMailboxState = success.currentMailboxState; currentMailboxState = success.currentMailboxState;
refreshTree(success.mailboxList); await refreshTree(success.mailboxList);
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
} else if (success is SubscribeMailboxSuccess) { } else if (success is SubscribeMailboxSuccess) {
_subscribeMailboxSuccess(success); _subscribeMailboxSuccess(success);
} else if (success is SubscribeMultipleMailboxAllSuccess) { } else if (success is SubscribeMultipleMailboxAllSuccess) {
@@ -96,6 +99,9 @@ class MailboxVisibilityController extends BaseMailboxController {
dispatchState(Right(LoadingBuildTreeMailboxVisibility())); dispatchState(Right(LoadingBuildTreeMailboxVisibility()));
await buildTree(mailboxList); await buildTree(mailboxList);
dispatchState(Right(BuildTreeMailboxVisibilitySuccess())); dispatchState(Right(BuildTreeMailboxVisibilitySuccess()));
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
} }
void subscribeMailbox(MailboxNode mailboxNode) { void subscribeMailbox(MailboxNode mailboxNode) {
@@ -120,6 +120,9 @@ class RulesFilterCreatorController extends BaseMailboxController {
if (success is GetAllMailboxSuccess) { if (success is GetAllMailboxSuccess) {
await buildTree(success.mailboxList); await buildTree(success.mailboxList);
_setUpMailboxSelected(); _setUpMailboxSelected();
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
} else if (success is GetAllRulesSuccess) { } else if (success is GetAllRulesSuccess) {
log('RulesFilterCreatorController::handleSuccessViewState():GetAllRulesSuccess: ${success.rules}'); log('RulesFilterCreatorController::handleSuccessViewState():GetAllRulesSuccess: ${success.rules}');
if (success.rules?.isNotEmpty == true) { if (success.rules?.isNotEmpty == true) {
@@ -119,10 +119,16 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
super.handleSuccessViewState(success); super.handleSuccessViewState(success);
if (success is GetAllMailboxSuccess) { if (success is GetAllMailboxSuccess) {
currentMailboxState = success.currentMailboxState; currentMailboxState = success.currentMailboxState;
buildTree(success.mailboxList); await buildTree(success.mailboxList);
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
} else if (success is RefreshChangesAllMailboxSuccess) { } else if (success is RefreshChangesAllMailboxSuccess) {
currentMailboxState = success.currentMailboxState; currentMailboxState = success.currentMailboxState;
await refreshTree(success.mailboxList); await refreshTree(success.mailboxList);
if (currentContext != null) {
await syncAllMailboxWithDisplayName(currentContext!);
}
searchMailboxAction(); searchMailboxAction();
} else if (success is SearchMailboxSuccess) { } else if (success is SearchMailboxSuccess) {
_handleSearchMailboxSuccess(success); _handleSearchMailboxSuccess(success);
@@ -20,26 +20,49 @@ extension PresentationMailboxExtension on PresentationMailbox {
mailboxPath: mailboxPath, mailboxPath: mailboxPath,
state: state, state: state,
namespace: namespace, namespace: namespace,
displayName: displayName,
);
}
PresentationMailbox withDisplayName(String? displayName) {
return PresentationMailbox(
id,
name: name,
parentId: parentId,
role: role,
sortOrder: sortOrder,
totalEmails: totalEmails,
unreadEmails: unreadEmails,
totalThreads: totalThreads,
unreadThreads: unreadThreads,
myRights: myRights,
isSubscribed: isSubscribed,
selectMode: selectMode,
mailboxPath: mailboxPath,
state: state,
namespace: namespace,
displayName: displayName,
); );
} }
PresentationMailbox withMailboxSate(MailboxState newMailboxState) { PresentationMailbox withMailboxSate(MailboxState newMailboxState) {
return PresentationMailbox( return PresentationMailbox(
id, id,
name: name, name: name,
parentId: parentId, parentId: parentId,
role: role, role: role,
sortOrder: sortOrder, sortOrder: sortOrder,
totalEmails: totalEmails, totalEmails: totalEmails,
unreadEmails: unreadEmails, unreadEmails: unreadEmails,
totalThreads: totalThreads, totalThreads: totalThreads,
unreadThreads: unreadThreads, unreadThreads: unreadThreads,
myRights: myRights, myRights: myRights,
isSubscribed: isSubscribed, isSubscribed: isSubscribed,
selectMode: selectMode, selectMode: selectMode,
mailboxPath: mailboxPath, mailboxPath: mailboxPath,
state: newMailboxState, state: newMailboxState,
namespace: namespace, namespace: namespace,
displayName: displayName,
); );
} }
@@ -62,21 +85,22 @@ extension PresentationMailboxExtension on PresentationMailbox {
PresentationMailbox toggleSelectPresentationMailbox() { PresentationMailbox toggleSelectPresentationMailbox() {
return PresentationMailbox( return PresentationMailbox(
id, id,
name: name, name: name,
parentId: parentId, parentId: parentId,
role: role, role: role,
sortOrder: sortOrder, sortOrder: sortOrder,
totalEmails: totalEmails, totalEmails: totalEmails,
unreadEmails: unreadEmails, unreadEmails: unreadEmails,
totalThreads: totalThreads, totalThreads: totalThreads,
unreadThreads: unreadThreads, unreadThreads: unreadThreads,
myRights: myRights, myRights: myRights,
isSubscribed: isSubscribed, isSubscribed: isSubscribed,
mailboxPath: mailboxPath, mailboxPath: mailboxPath,
selectMode: selectMode == SelectMode.INACTIVE ? SelectMode.ACTIVE : SelectMode.INACTIVE, selectMode: selectMode == SelectMode.INACTIVE ? SelectMode.ACTIVE : SelectMode.INACTIVE,
state: state, state: state,
namespace: namespace, namespace: namespace,
displayName: displayName,
); );
} }
@@ -97,6 +121,7 @@ extension PresentationMailboxExtension on PresentationMailbox {
selectMode: selectMode, selectMode: selectMode,
state: state, state: state,
namespace: namespace, namespace: namespace,
displayName: displayName,
); );
} }
} }
@@ -45,6 +45,7 @@ class PresentationMailbox with EquatableMixin {
final String? mailboxPath; final String? mailboxPath;
final MailboxState? state; final MailboxState? state;
final Namespace? namespace; final Namespace? namespace;
final String? displayName;
PresentationMailbox( PresentationMailbox(
this.id, this.id,
@@ -63,6 +64,7 @@ class PresentationMailbox with EquatableMixin {
this.mailboxPath, this.mailboxPath,
this.state = MailboxState.activated, this.state = MailboxState.activated,
this.namespace, this.namespace,
this.displayName,
} }
); );