diff --git a/lib/domain/model/room/room_list_extension.dart b/lib/domain/model/room/room_list_extension.dart index db1d5134b7..ce127227ca 100644 --- a/lib/domain/model/room/room_list_extension.dart +++ b/lib/domain/model/room/room_list_extension.dart @@ -3,6 +3,22 @@ import 'package:fluffychat/domain/model/search/recent_chat_model.dart'; import 'package:matrix/matrix.dart'; extension RoomListExtension on List { + bool _matchedMatrixId(RecentChatSearchModel model, String keyword) { + return model.directChatMatrixID + ?.toLowerCase() + .contains(keyword.toLowerCase()) ?? + false; + } + + bool _matchedName(RecentChatSearchModel model, String keyword) { + return model.displayName?.toLowerCase().contains(keyword.toLowerCase()) ?? + false; + } + + bool _matchedNameOrMatrixId(RecentChatSearchModel model, String keyword) { + return _matchedName(model, keyword) || _matchedMatrixId(model, keyword); + } + List searchRecentChat({ required MatrixLocalizations matrixLocalizations, required String keyword, @@ -13,11 +29,7 @@ extension RoomListExtension on List { ) .map((room) => room.toRecentChatSearchModel(matrixLocalizations)) .where( - (model) => - model.displayName != null && - model.displayName!.toLowerCase().contains( - keyword.toLowerCase(), - ), + (model) => _matchedNameOrMatrixId(model, keyword), ) .take(limit ?? length) .toList(); diff --git a/lib/pages/search/search_contacts_and_chats_controller.dart b/lib/pages/search/search_contacts_and_chats_controller.dart index 3b58fd1f41..a12e50664c 100644 --- a/lib/pages/search/search_contacts_and_chats_controller.dart +++ b/lib/pages/search/search_contacts_and_chats_controller.dart @@ -83,27 +83,8 @@ class SearchContactsAndChatsController with SearchDebouncerMixin, SearchMixin { .toList(); final tomContactPresentationSearchMatched = tomPresentationSearchContacts .expand((contact) => contact.toPresentationSearch()) - .where((contact) { - 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(); + .where((contact) => _doesMatchKeyword(contact, keyword)) + .toList(); _searchRecentChatInteractor .execute( keyword: keyword, @@ -126,6 +107,45 @@ class SearchContactsAndChatsController with SearchDebouncerMixin, SearchMixin { ); } + bool _matchedMatrixId(PresentationSearch contact, String keyword) { + return contact.directChatMatrixID + ?.toLowerCase() + .contains(keyword.toLowerCase()) ?? + false; + } + + bool _matchedName(PresentationSearch contact, String keyword) { + return contact.displayName?.toLowerCase().contains(keyword.toLowerCase()) ?? + false; + } + + bool _matchedEmail(PresentationSearch contact, String keyword) { + return contact.email?.toLowerCase().contains(keyword.toLowerCase()) ?? + false; + } + + bool _matchedContactInfo(PresentationSearch contact, String keyword) { + return _matchedName(contact, keyword) || + _matchedEmail(contact, keyword) || + _matchedMatrixId(contact, keyword); + } + + bool _doesMatchKeyword(PresentationSearch contact, String keyword) { + if (contact is! ContactPresentationSearch) { + return false; + } + + if (contact.displayName == null) { + return false; + } + + if (contact.email == null) { + return false; + } + + return _matchedContactInfo(contact, keyword); + } + void onSearchBarChanged(String keyword) { setDebouncerValue(keyword); }