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(() { setState(() {
foundProfiles = List<Profile>.from(response.results); foundProfiles = List<Profile>.from(response.results);
if ('@$text'.isValidMatrixId && if (text.isValidMatrixId &&
foundProfiles.indexWhere((profile) => '@$text' == profile.userId) == foundProfiles.indexWhere((profile) => text == profile.userId) == -1) {
-1) {
setState(() => foundProfiles = [ setState(() => foundProfiles = [
Profile.fromJson({'user_id': '@$text'}), Profile.fromJson({'user_id': text}),
]); ]);
} }
final participants = room 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?.cancel();
coolDown = Timer( coolDown = Timer(
Duration(seconds: 1), Duration(seconds: 1),
() => searchUser(context, text), () => searchUser(context, controller.text),
); );
} }
@ -99,8 +102,7 @@ class _NewPrivateChatState extends State<NewPrivateChat> {
controller: controller, controller: controller,
autofocus: true, autofocus: true,
autocorrect: false, autocorrect: false,
onChanged: (String text) => onChanged: (String text) => searchUserWithCoolDown(context),
searchUserWithCoolDown(context, text),
textInputAction: TextInputAction.go, textInputAction: TextInputAction.go,
onFieldSubmitted: (s) => submitAction(context), onFieldSubmitted: (s) => submitAction(context),
validator: (value) { validator: (value) {