Skip to content

Commit

Permalink
TW-1982: Fix can't create direct chat when search in contact tab
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev authored and hoangdat committed Sep 4, 2024
1 parent ef051c4 commit 309578a
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions lib/presentation/mixins/contacts_view_controller_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
);
}
Expand Down Expand Up @@ -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,
),
),
);
}
Expand Down Expand Up @@ -338,6 +350,25 @@ mixin class ContactsViewControllerMixin {
);
}

Either<Failure, Success> _handleSearchExternalContact(
String keyword, {
required Either<Failure, Success> otherResult,
}) {
if (keyword.isValidMatrixId && keyword.startsWith("@")) {
return Right(
PresentationExternalContactSuccess(
contact: PresentationContact(
matrixId: keyword,
displayName: keyword.substring(1),
type: ContactType.external,
),
),
);
} else {
return otherResult;
}
}

Future<void> _refreshRecentContacts({
required Client client,
required MatrixLocalizations matrixLocalizations,
Expand Down

0 comments on commit 309578a

Please sign in to comment.