mirror of
https://github.com/krille-chan/fluffychat
synced 2024-09-17 08:55:12 +00:00
chore: Follow up new chat: Add mxid if not found
This commit is contained in:
parent
83ce07c574
commit
e4e399b69b
2 changed files with 19 additions and 6 deletions
|
@ -27,7 +27,7 @@ class NewPrivateChatController extends State<NewPrivateChat> {
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
final FocusNode textFieldFocus = FocusNode();
|
final FocusNode textFieldFocus = FocusNode();
|
||||||
|
|
||||||
Future<SearchUserDirectoryResponse>? searchResponse;
|
Future<List<Profile>>? searchResponse;
|
||||||
|
|
||||||
Timer? _searchCoolDown;
|
Timer? _searchCoolDown;
|
||||||
|
|
||||||
|
@ -46,12 +46,25 @@ class NewPrivateChatController extends State<NewPrivateChat> {
|
||||||
_searchCoolDown?.cancel();
|
_searchCoolDown?.cancel();
|
||||||
_searchCoolDown = Timer(_coolDown, () {
|
_searchCoolDown = Timer(_coolDown, () {
|
||||||
setState(() {
|
setState(() {
|
||||||
searchResponse =
|
searchResponse = _searchUser(searchTerm);
|
||||||
Matrix.of(context).client.searchUserDirectory(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 inviteAction() => FluffyShare.shareInviteLink(context);
|
||||||
|
|
||||||
void openScannerAction() async {
|
void openScannerAction() async {
|
||||||
|
|
|
@ -205,7 +205,7 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
child: CircularProgressIndicator.adaptive(),
|
child: CircularProgressIndicator.adaptive(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (result.results.isEmpty) {
|
if (result.isEmpty) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
|
@ -226,9 +226,9 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: result.results.length,
|
itemCount: result.length,
|
||||||
itemBuilder: (context, i) {
|
itemBuilder: (context, i) {
|
||||||
final contact = result.results[i];
|
final contact = result[i];
|
||||||
final displayname = contact.displayName ??
|
final displayname = contact.displayName ??
|
||||||
contact.userId.localpart ??
|
contact.userId.localpart ??
|
||||||
contact.userId;
|
contact.userId;
|
||||||
|
|
Loading…
Reference in a new issue