From 309578a3c59361e8f85104b948eed7745cfd4415 Mon Sep 17 00:00:00 2001 From: "quanghnguyen@linagora.com" Date: Fri, 30 Aug 2024 16:52:30 +0700 Subject: [PATCH] TW-1982: Fix can't create direct chat when search in contact tab --- .../contacts_view_controller_mixin.dart | 55 +++++++++++++++---- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/lib/presentation/mixins/contacts_view_controller_mixin.dart b/lib/presentation/mixins/contacts_view_controller_mixin.dart index 75b6390cee..c5528fadea 100644 --- a/lib/presentation/mixins/contacts_view_controller_mixin.dart +++ b/lib/presentation/mixins/contacts_view_controller_mixin.dart @@ -236,17 +236,23 @@ mixin class ContactsViewControllerMixin { contactsManager.getContactsNotifier().value.fold( (failure) { if (failure is GetContactsFailure) { - return Left( - GetPresentationContactsFailure( - keyword: keyword, + return _handleSearchExternalContact( + keyword, + otherResult: Left( + GetPresentationContactsFailure( + keyword: keyword, + ), ), ); } if (failure is GetContactsIsEmpty) { - return Left( - GetPresentationContactsEmpty( - keyword: keyword, + return _handleSearchExternalContact( + keyword, + otherResult: Left( + GetPresentationContactsEmpty( + keyword: keyword, + ), ), ); } @@ -296,17 +302,23 @@ mixin class ContactsViewControllerMixin { contactsManager.getPhonebookContactsNotifier().value.fold( (failure) { if (failure is GetPhonebookContactsFailure) { - return Left( - GetPresentationContactsFailure( - keyword: keyword, + return _handleSearchExternalContact( + keyword, + otherResult: Left( + GetPresentationContactsFailure( + keyword: keyword, + ), ), ); } if (failure is GetPhonebookContactsIsEmpty) { - return Left( - GetPresentationContactsEmpty( - keyword: keyword, + return _handleSearchExternalContact( + keyword, + otherResult: Left( + GetPresentationContactsEmpty( + keyword: keyword, + ), ), ); } @@ -338,6 +350,25 @@ mixin class ContactsViewControllerMixin { ); } + Either _handleSearchExternalContact( + String keyword, { + required Either otherResult, + }) { + if (keyword.isValidMatrixId && keyword.startsWith("@")) { + return Right( + PresentationExternalContactSuccess( + contact: PresentationContact( + matrixId: keyword, + displayName: keyword.substring(1), + type: ContactType.external, + ), + ), + ); + } else { + return otherResult; + } + } + Future _refreshRecentContacts({ required Client client, required MatrixLocalizations matrixLocalizations,