Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Remove unknown MXIDs from invite suggestions #11055

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src/components/views/dialogs/InviteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ import { Icon as InfoIcon } from "../../../../res/img/element-icons/info.svg";
import { Icon as EmailPillAvatarIcon } from "../../../../res/img/icon-email-pill-avatar.svg";
import { _t, _td } from "../../../languageHandler";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import {
getHostnameFromMatrixServerName,
getServerName,
makeRoomPermalink,
makeUserPermalink,
} from "../../../utils/permalinks/Permalinks";
import { makeRoomPermalink, makeUserPermalink } from "../../../utils/permalinks/Permalinks";
import DMRoomMap from "../../../utils/DMRoomMap";
import SdkConfig from "../../../SdkConfig";
import * as Email from "../../../email";
Expand Down Expand Up @@ -724,18 +719,6 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
}
} catch (e) {
logger.warn("Non-fatal error trying to make an invite for a user ID", e);

// Reuse logic from Permalinks as a basic MXID validity check
const serverName = getServerName(term);
const domain = getHostnameFromMatrixServerName(serverName);
if (domain) {
// Add a result anyways, just without a profile. We stick it at the
// top so it is most obviously presented to the user.
r.results.splice(0, 0, {
user_id: term,
display_name: term,
});
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions test/components/views/dialogs/InviteDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import InviteDialog from "../../../../src/components/views/dialogs/InviteDialog"
import { InviteKind } from "../../../../src/components/views/dialogs/InviteDialogTypes";
import {
filterConsole,
flushPromises,
getMockClientWithEventEmitter,
mkMembership,
mkMessage,
Expand Down Expand Up @@ -200,7 +201,7 @@ describe("InviteDialog", () => {
expect(screen.getByText(`Invite to ${roomId}`)).toBeInTheDocument();
});

it("should suggest valid MXIDs even if unknown", async () => {
it("should not suggest valid unknown MXIDs", async () => {
render(
<InviteDialog
kind={InviteKind.Invite}
Expand All @@ -209,8 +210,8 @@ describe("InviteDialog", () => {
initialText="@localpart:server.tld"
/>,
);

await screen.findAllByText("@localpart:server.tld"); // Using findAllByText as the MXID is used for name too
await flushPromises();
expect(screen.queryByText("@localpart:server.tld")).not.toBeInTheDocument();
});

it("should not suggest invalid MXIDs", () => {
Expand Down