From b41993fcffd6c4cc649de7428c113b16c805fc92 Mon Sep 17 00:00:00 2001 From: HuyNguyen Date: Mon, 19 Feb 2024 16:52:05 +0700 Subject: [PATCH] TW-1152: Support can search by email on chat list --- .../search_contacts_and_chats_controller.dart | 20 ++++++++++++++++++- lib/pages/search/search_view.dart | 4 ++++ lib/pages/search/server_search_view.dart | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/pages/search/search_contacts_and_chats_controller.dart b/lib/pages/search/search_contacts_and_chats_controller.dart index 824298c162..cc5bfa6866 100644 --- a/lib/pages/search/search_contacts_and_chats_controller.dart +++ b/lib/pages/search/search_contacts_and_chats_controller.dart @@ -83,7 +83,25 @@ class SearchContactsAndChatsController with SearchDebouncerMixin { final recentChatPresentationSearchMatched = tomPresentationSearchContacts .expand((contact) => contact.toPresentationSearch()) .where((contact) { - return contact.displayName!.toLowerCase().contains(keyword.toLowerCase()); + if (contact is! ContactPresentationSearch) { + return false; + } + + if (contact.displayName == null) { + return false; + } + + if (contact.email == null) { + return false; + } + + final matchedName = + contact.displayName!.toLowerCase().contains(keyword.toLowerCase()); + + final matchedEmail = + contact.email!.toLowerCase().contains(keyword.toLowerCase()); + + return matchedName || matchedEmail; }).toList(); _searchRecentChatInteractor .execute( diff --git a/lib/pages/search/search_view.dart b/lib/pages/search/search_view.dart index 38224a199b..da6c33deba 100644 --- a/lib/pages/search/search_view.dart +++ b/lib/pages/search/search_view.dart @@ -76,6 +76,10 @@ class SearchView extends StatelessWidget { searchController.serverSearchController.searchResultsNotifier, builder: ((context, searchResults, child) { if (searchResults is PresentationServerSideEmptySearch) { + if (searchController.searchContactAndRecentChatController! + .recentAndContactsNotifier.value.isNotEmpty) { + return child!; + } return _SearchHeader( header: L10n.of(context)!.messages, searchController: searchController, diff --git a/lib/pages/search/server_search_view.dart b/lib/pages/search/server_search_view.dart index 753ed99c63..2eb623dffe 100644 --- a/lib/pages/search/server_search_view.dart +++ b/lib/pages/search/server_search_view.dart @@ -28,6 +28,10 @@ class ServerSearchMessagesList extends StatelessWidget { searchController.serverSearchController.searchResultsNotifier, builder: (context, serverSearchNotifier, child) { if (serverSearchNotifier is PresentationServerSideEmptySearch) { + if (searchController.searchContactAndRecentChatController! + .recentAndContactsNotifier.value.isNotEmpty) { + return const SizedBox.shrink(); + } return child!; }