Error msg for bad invites in non-federated room
This commit is contained in:
parent
1f76ceb1e3
commit
0fa16400df
2
TODO.md
2
TODO.md
|
@ -1,7 +1,5 @@
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- when inviting members, prevent if user id is on another server and room
|
|
||||||
doesn't allow that
|
|
||||||
- "exception during sync" aren't caught
|
- "exception during sync" aren't caught
|
||||||
|
|
||||||
## Media
|
## Media
|
||||||
|
|
|
@ -81,6 +81,11 @@ class InvalidUserInContext(Exception):
|
||||||
user_id: str = field()
|
user_id: str = field()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class UserFromOtherServerDisallowed(Exception):
|
||||||
|
user_id: str = field()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class UneededThumbnail(Exception):
|
class UneededThumbnail(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -22,16 +22,17 @@ from urllib.parse import urlparse
|
||||||
from uuid import UUID, uuid4
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
import cairosvg
|
import cairosvg
|
||||||
|
from PIL import Image as PILImage
|
||||||
|
from pymediainfo import MediaInfo
|
||||||
|
|
||||||
import nio
|
import nio
|
||||||
from nio.crypto import AsyncDataT as UploadData
|
from nio.crypto import AsyncDataT as UploadData
|
||||||
from nio.crypto import async_generator_from_data
|
from nio.crypto import async_generator_from_data
|
||||||
from PIL import Image as PILImage
|
|
||||||
from pymediainfo import MediaInfo
|
|
||||||
|
|
||||||
from . import __app_name__, __display_name__, utils
|
from . import __app_name__, __display_name__, utils
|
||||||
from .errors import (
|
from .errors import (
|
||||||
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixError,
|
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixError,
|
||||||
MatrixNotFound, UneededThumbnail,
|
MatrixNotFound, UneededThumbnail, UserFromOtherServerDisallowed,
|
||||||
)
|
)
|
||||||
from .html_markdown import HTML_PROCESSOR as HTML
|
from .html_markdown import HTML_PROCESSOR as HTML
|
||||||
from .media_cache import Media, Thumbnail
|
from .media_cache import Media, Thumbnail
|
||||||
|
@ -759,16 +760,26 @@ class MatrixClient(nio.AsyncClient):
|
||||||
if uid not in self.all_rooms[room_id].users
|
if uid not in self.all_rooms[room_id].users
|
||||||
)
|
)
|
||||||
|
|
||||||
async def invite(user):
|
async def invite(user_id: str):
|
||||||
if not self.user_id_regex.match(user):
|
if not self.user_id_regex.match(user_id):
|
||||||
return InvalidUserId(user)
|
return InvalidUserId(user_id)
|
||||||
|
|
||||||
|
if not self.rooms[room_id].federate:
|
||||||
|
_, user_server = user_id.split(":", maxsplit=1)
|
||||||
|
_, room_server = room_id.split(":", maxsplit=1)
|
||||||
|
|
||||||
|
user_server = re.sub(r":443$", "", user_server)
|
||||||
|
room_server = re.sub(r":443$", "", room_server)
|
||||||
|
|
||||||
|
if user_server != room_server:
|
||||||
|
return UserFromOtherServerDisallowed(user_id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.get_profile(user)
|
await self.get_profile(user_id)
|
||||||
except MatrixNotFound as err:
|
except MatrixNotFound as err:
|
||||||
return err
|
return err
|
||||||
|
|
||||||
return await self.room_invite(room_id, user)
|
return await self.room_invite(room_id, user_id)
|
||||||
|
|
||||||
coros = [invite(uid) for uid in user_ids]
|
coros = [invite(uid) for uid in user_ids]
|
||||||
successes = []
|
successes = []
|
||||||
|
|
|
@ -97,6 +97,10 @@ BoxPopup {
|
||||||
qsTr("%1 is not a valid user ID, expected format is " +
|
qsTr("%1 is not a valid user ID, expected format is " +
|
||||||
"@username:homeserver").arg(user) :
|
"@username:homeserver").arg(user) :
|
||||||
|
|
||||||
|
type === "UserFromOtherServerDisallowed" ?
|
||||||
|
qsTr("This room rejects users from other matrix " +
|
||||||
|
"servers, can't invite %1").arg(user) :
|
||||||
|
|
||||||
type === "UserNotFound" ?
|
type === "UserNotFound" ?
|
||||||
qsTr("%1 not found, please verify the entered user ID")
|
qsTr("%1 not found, please verify the entered user ID")
|
||||||
.arg(user) :
|
.arg(user) :
|
||||||
|
|
Loading…
Reference in New Issue
Block a user