TF-1708 Improvement search mailbox by display name at locale
(cherry picked from commit f3efbe715c06b87ce3006dc936be26dd272a643c)
This commit is contained in:
@@ -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/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/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_categories_expand_mode.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>[];
|
||||
|
||||
Future buildTree(
|
||||
Future<void> buildTree(
|
||||
List<PresentationMailbox> allMailbox,
|
||||
{MailboxId? mailboxIdSelected}
|
||||
) async {
|
||||
@@ -85,7 +86,7 @@ abstract class BaseMailboxController extends BaseController {
|
||||
allMailboxes = tupleTree.value4;
|
||||
}
|
||||
|
||||
Future refreshTree(List<PresentationMailbox> allMailbox) async {
|
||||
Future<void> refreshTree(List<PresentationMailbox> allMailbox) async {
|
||||
allMailboxes = allMailbox;
|
||||
final tupleTree = await _treeBuilder.generateMailboxTreeInUIAfterRefreshChanges(
|
||||
allMailbox,
|
||||
@@ -100,6 +101,14 @@ abstract class BaseMailboxController extends BaseController {
|
||||
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) {
|
||||
final newExpandMode = selectedMailboxNode.expandMode == ExpandMode.COLLAPSE
|
||||
? 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/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/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_categories.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart';
|
||||
@@ -104,18 +105,24 @@ class DestinationPickerController extends BaseMailboxController {
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
void handleSuccessViewState(Success success) async {
|
||||
super.handleSuccessViewState(success);
|
||||
if (success is GetAllMailboxSuccess) {
|
||||
if (success is GetAllMailboxSuccess) {
|
||||
if (mailboxAction.value == MailboxActions.move && mailboxIdSelected != null) {
|
||||
buildTree(
|
||||
await buildTree(
|
||||
success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes,
|
||||
mailboxIdSelected: mailboxIdSelected);
|
||||
} else {
|
||||
buildTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes);
|
||||
await buildTree(success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes);
|
||||
}
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
} 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) {
|
||||
_searchMailboxSuccess(success);
|
||||
} else if (success is CreateNewMailboxSuccess) {
|
||||
@@ -271,13 +278,17 @@ class DestinationPickerController extends BaseMailboxController {
|
||||
listMailboxSearched.clear();
|
||||
}
|
||||
|
||||
void searchMailbox(String value) {
|
||||
void searchMailbox(BuildContext context, String value) {
|
||||
searchQuery.value = SearchQuery(value);
|
||||
final searchableMailboxList = mailboxAction.value == MailboxActions.moveEmail
|
||||
? allMailboxes
|
||||
: 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) {
|
||||
|
||||
@@ -559,8 +559,8 @@ class DestinationPickerView extends GetWidget<DestinationPickerController>
|
||||
fit: BoxFit.fill),
|
||||
hintText: AppLocalizations.of(context).hint_search_mailboxes,
|
||||
onClearTextSearchAction: controller.clearSearchText,
|
||||
onTextChangeSearchAction: controller.searchMailbox,
|
||||
onSearchTextAction: controller.searchMailbox,
|
||||
onTextChangeSearchAction: (query) => controller.searchMailbox(context, query),
|
||||
onSearchTextAction: (query) => controller.searchMailbox(context, query),
|
||||
))
|
||||
]
|
||||
)
|
||||
|
||||
@@ -12,7 +12,7 @@ class SearchMailboxInteractor {
|
||||
yield Right<Failure, Success>(LoadingSearchMailbox());
|
||||
|
||||
final resultList = mailboxes
|
||||
.where((mailbox) => mailbox.name?.name.toLowerCase().contains(searchQuery.value.toLowerCase()) == true)
|
||||
.where((mailbox) => _matchMailboxByQuery(mailbox, searchQuery))
|
||||
.toList();
|
||||
|
||||
yield Right<Failure, Success>(SearchMailboxSuccess(resultList));
|
||||
@@ -20,4 +20,13 @@ class SearchMailboxInteractor {
|
||||
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:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
@@ -8,7 +7,6 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
||||
|
||||
String getDisplayName(BuildContext context) {
|
||||
if (isDefault) {
|
||||
log("PresentationMailboxExtension::getDisplayName:Role: $role | MailboxName: $name");
|
||||
switch(role!.value.toLowerCase()) {
|
||||
case PresentationMailbox.inboxRole:
|
||||
return AppLocalizations.of(context).inboxMailboxDisplayName;
|
||||
|
||||
@@ -998,12 +998,18 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
final listMailboxDisplayed = success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes;
|
||||
await buildTree(listMailboxDisplayed);
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleRefreshChangesAllMailboxSuccess(RefreshChangesAllMailboxSuccess success) async {
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
final listMailboxDisplayed = success.mailboxList.listSubscribedMailboxesAndDefaultMailboxes;
|
||||
await refreshTree(listMailboxDisplayed);
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
}
|
||||
|
||||
void _unsubscribeMailboxAction(MailboxId mailboxId) {
|
||||
|
||||
+8
-2
@@ -65,14 +65,17 @@ class MailboxVisibilityController extends BaseMailboxController {
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
void handleSuccessViewState(Success success) async {
|
||||
super.handleSuccessViewState(success);
|
||||
if (success is GetAllMailboxSuccess) {
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
_handleBuildTree(success.mailboxList);
|
||||
} else if (success is RefreshChangesAllMailboxSuccess) {
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
refreshTree(success.mailboxList);
|
||||
await refreshTree(success.mailboxList);
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
} else if (success is SubscribeMailboxSuccess) {
|
||||
_subscribeMailboxSuccess(success);
|
||||
} else if (success is SubscribeMultipleMailboxAllSuccess) {
|
||||
@@ -96,6 +99,9 @@ class MailboxVisibilityController extends BaseMailboxController {
|
||||
dispatchState(Right(LoadingBuildTreeMailboxVisibility()));
|
||||
await buildTree(mailboxList);
|
||||
dispatchState(Right(BuildTreeMailboxVisibilitySuccess()));
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
}
|
||||
|
||||
void subscribeMailbox(MailboxNode mailboxNode) {
|
||||
|
||||
@@ -120,6 +120,9 @@ class RulesFilterCreatorController extends BaseMailboxController {
|
||||
if (success is GetAllMailboxSuccess) {
|
||||
await buildTree(success.mailboxList);
|
||||
_setUpMailboxSelected();
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
} else if (success is GetAllRulesSuccess) {
|
||||
log('RulesFilterCreatorController::handleSuccessViewState():GetAllRulesSuccess: ${success.rules}');
|
||||
if (success.rules?.isNotEmpty == true) {
|
||||
|
||||
@@ -119,10 +119,16 @@ class SearchMailboxController extends BaseMailboxController with MailboxActionHa
|
||||
super.handleSuccessViewState(success);
|
||||
if (success is GetAllMailboxSuccess) {
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
buildTree(success.mailboxList);
|
||||
await buildTree(success.mailboxList);
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
} else if (success is RefreshChangesAllMailboxSuccess) {
|
||||
currentMailboxState = success.currentMailboxState;
|
||||
await refreshTree(success.mailboxList);
|
||||
if (currentContext != null) {
|
||||
await syncAllMailboxWithDisplayName(currentContext!);
|
||||
}
|
||||
searchMailboxAction();
|
||||
} else if (success is SearchMailboxSuccess) {
|
||||
_handleSearchMailboxSuccess(success);
|
||||
|
||||
@@ -20,26 +20,49 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
||||
mailboxPath: mailboxPath,
|
||||
state: state,
|
||||
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) {
|
||||
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: newMailboxState,
|
||||
namespace: namespace,
|
||||
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: newMailboxState,
|
||||
namespace: namespace,
|
||||
displayName: displayName,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,21 +85,22 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
||||
|
||||
PresentationMailbox toggleSelectPresentationMailbox() {
|
||||
return PresentationMailbox(
|
||||
id,
|
||||
name: name,
|
||||
parentId: parentId,
|
||||
role: role,
|
||||
sortOrder: sortOrder,
|
||||
totalEmails: totalEmails,
|
||||
unreadEmails: unreadEmails,
|
||||
totalThreads: totalThreads,
|
||||
unreadThreads: unreadThreads,
|
||||
myRights: myRights,
|
||||
isSubscribed: isSubscribed,
|
||||
mailboxPath: mailboxPath,
|
||||
selectMode: selectMode == SelectMode.INACTIVE ? SelectMode.ACTIVE : SelectMode.INACTIVE,
|
||||
state: state,
|
||||
namespace: namespace,
|
||||
id,
|
||||
name: name,
|
||||
parentId: parentId,
|
||||
role: role,
|
||||
sortOrder: sortOrder,
|
||||
totalEmails: totalEmails,
|
||||
unreadEmails: unreadEmails,
|
||||
totalThreads: totalThreads,
|
||||
unreadThreads: unreadThreads,
|
||||
myRights: myRights,
|
||||
isSubscribed: isSubscribed,
|
||||
mailboxPath: mailboxPath,
|
||||
selectMode: selectMode == SelectMode.INACTIVE ? SelectMode.ACTIVE : SelectMode.INACTIVE,
|
||||
state: state,
|
||||
namespace: namespace,
|
||||
displayName: displayName,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -97,6 +121,7 @@ extension PresentationMailboxExtension on PresentationMailbox {
|
||||
selectMode: selectMode,
|
||||
state: state,
|
||||
namespace: namespace,
|
||||
displayName: displayName,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ class PresentationMailbox with EquatableMixin {
|
||||
final String? mailboxPath;
|
||||
final MailboxState? state;
|
||||
final Namespace? namespace;
|
||||
final String? displayName;
|
||||
|
||||
PresentationMailbox(
|
||||
this.id,
|
||||
@@ -63,6 +64,7 @@ class PresentationMailbox with EquatableMixin {
|
||||
this.mailboxPath,
|
||||
this.state = MailboxState.activated,
|
||||
this.namespace,
|
||||
this.displayName,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user