diff --git a/src/python/errors.py b/src/python/errors.py index d83e540c..37c28f9e 100644 --- a/src/python/errors.py +++ b/src/python/errors.py @@ -52,6 +52,11 @@ class UserNotFound(Exception): user_id: str = field() +@dataclass +class InvalidUserId(Exception): + user_id: str = field() + + @dataclass class InvalidUserInContext(Exception): user_id: str = field() diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index 2a5f7297..8613cacf 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -24,8 +24,8 @@ from nio.crypto import async_generator_from_data from . import __about__, utils from .errors import ( - BadMimeType, InvalidUserInContext, MatrixError, UneededThumbnail, - UserNotFound, + BadMimeType, InvalidUserId, InvalidUserInContext, MatrixError, + UneededThumbnail, UserNotFound, ) from .html_filter import HTML_FILTER from .models.items import ( @@ -479,6 +479,9 @@ class MatrixClient(nio.AsyncClient): if invite == self.user_id: raise InvalidUserInContext(invite) + if not re.match(r"^@.+:.+", invite): + raise InvalidUserId(invite) + if isinstance(await self.get_profile(invite), nio.ProfileGetError): raise UserNotFound(invite) diff --git a/src/qml/Pages/AddChat/FindSomeone.qml b/src/qml/Pages/AddChat/FindSomeone.qml index 0b0074fa..469ed38e 100644 --- a/src/qml/Pages/AddChat/FindSomeone.qml +++ b/src/qml/Pages/AddChat/FindSomeone.qml @@ -35,6 +35,10 @@ HBox { if (type === "InvalidUserInContext") txt = qsTr("You can't invite yourself!") + if (type === "InvalidUserId") + txt = qsTr("Invalid user ID, expected format is " + + "@username:homeserver") + if (type === "UserNotFound") txt = qsTr("This user does not exist") @@ -61,7 +65,7 @@ HBox { HTextField { id: userField - placeholderText: qsTr("User ID (e.g. @john:matrix.org)") + placeholderText: qsTr("User ID (e.g. @bob:matrix.org)") error: Boolean(errorMessage.text) Layout.fillWidth: true