Skip to content

Commit

Permalink
chore: Follow up new chat: Add mxid if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
krille-chan committed Nov 21, 2023
1 parent 83ce07c commit e4e399b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 16 additions & 3 deletions lib/pages/new_private_chat/new_private_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NewPrivateChatController extends State<NewPrivateChat> {
final TextEditingController controller = TextEditingController();
final FocusNode textFieldFocus = FocusNode();

Future<SearchUserDirectoryResponse>? searchResponse;
Future<List<Profile>>? searchResponse;

Timer? _searchCoolDown;

Expand All @@ -46,12 +46,25 @@ class NewPrivateChatController extends State<NewPrivateChat> {
_searchCoolDown?.cancel();
_searchCoolDown = Timer(_coolDown, () {
setState(() {
searchResponse =
Matrix.of(context).client.searchUserDirectory(searchTerm);
searchResponse = _searchUser(searchTerm);
});
});
}

Future<List<Profile>> _searchUser(String searchTerm) async {
final result =
await Matrix.of(context).client.searchUserDirectory(searchTerm);
final profiles = result.results;

if (searchTerm.isValidMatrixId &&
searchTerm.sigil == '@' &&
!profiles.any((profile) => profile.userId == searchTerm)) {
profiles.add(Profile(userId: searchTerm));
}

return profiles;
}

void inviteAction() => FluffyShare.shareInviteLink(context);

void openScannerAction() async {
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/new_private_chat/new_private_chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class NewPrivateChatView extends StatelessWidget {
child: CircularProgressIndicator.adaptive(),
);
}
if (result.results.isEmpty) {
if (result.isEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand All @@ -226,9 +226,9 @@ class NewPrivateChatView extends StatelessWidget {
);
}
return ListView.builder(
itemCount: result.results.length,
itemCount: result.length,
itemBuilder: (context, i) {
final contact = result.results[i];
final contact = result[i];
final displayname = contact.displayName ??
contact.userId.localpart ??
contact.userId;
Expand Down

0 comments on commit e4e399b

Please sign in to comment.