fix: mxid validation

This commit is contained in:
Christian Pauly 2021-01-18 08:43:29 +01:00
parent 81e706aaf5
commit 25da65f366
2 changed files with 9 additions and 8 deletions

View File

@ -99,11 +99,10 @@ class _InvitationSelectionState extends State<InvitationSelection> {
}
setState(() {
foundProfiles = List<Profile>.from(response.results);
if ('@$text'.isValidMatrixId &&
foundProfiles.indexWhere((profile) => '@$text' == profile.userId) ==
-1) {
if (text.isValidMatrixId &&
foundProfiles.indexWhere((profile) => text == profile.userId) == -1) {
setState(() => foundProfiles = [
Profile.fromJson({'user_id': '@$text'}),
Profile.fromJson({'user_id': text}),
]);
}
final participants = room

View File

@ -51,11 +51,14 @@ class _NewPrivateChatState extends State<NewPrivateChat> {
}
}
void searchUserWithCoolDown(BuildContext context, String text) async {
void searchUserWithCoolDown(BuildContext context) async {
if (controller.text.startsWith('@')) {
controller.text = controller.text.substring(1);
}
coolDown?.cancel();
coolDown = Timer(
Duration(seconds: 1),
() => searchUser(context, text),
() => searchUser(context, controller.text),
);
}
@ -99,8 +102,7 @@ class _NewPrivateChatState extends State<NewPrivateChat> {
controller: controller,
autofocus: true,
autocorrect: false,
onChanged: (String text) =>
searchUserWithCoolDown(context, text),
onChanged: (String text) => searchUserWithCoolDown(context),
textInputAction: TextInputAction.go,
onFieldSubmitted: (s) => submitAction(context),
validator: (value) {