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

Commit

Permalink
Search for users on paste
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Scheu <[email protected]>
  • Loading branch information
peterscheu-aceart committed Aug 3, 2023
1 parent 44f51fd commit 34e85dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/views/dialogs/InviteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,17 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
return;
}

const text = e.clipboardData.getData("text");
const potentialAddresses = this.parseFilter(text);
// one search term which is not a mxid or email address
if (potentialAddresses.length === 1 && !potentialAddresses[0].includes("@")) {
return;
}

// Prevent the text being pasted into the input
e.preventDefault();

// Process it as a list of addresses to add instead
const text = e.clipboardData.getData("text");
const possibleMembers = [
// If we can avoid hitting the profile endpoint, we should.
...this.state.recents,
Expand All @@ -889,8 +895,6 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
// Will be displayed as filter text to provide feedback.
const unableToAddMore: string[] = [];

const potentialAddresses = this.parseFilter(text);

for (const address of potentialAddresses) {
const member = possibleMembers.find((m) => m.userId === address);
if (member) {
Expand Down
14 changes: 14 additions & 0 deletions test/components/views/dialogs/InviteDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const aliceEmail = "[email protected]";
const bobId = "@bob:example.org";
const bobEmail = "[email protected]"; // [email protected] is already used as an example in the invite dialog
const carolId = "@carol:example.com";
const bobbob = "bobbob";

const aliceProfileInfo: IProfileInfo = {
user_id: aliceId,
Expand Down Expand Up @@ -290,6 +291,19 @@ describe("InviteDialog", () => {
await screen.findByText(aliceEmail);
expect(input).toHaveValue("");
});
it("should support pasting one username that is not a mx id or email", async () => {
mockClient.getIdentityServerUrl.mockReturnValue("https://identity-server");
mockClient.lookupThreePid.mockResolvedValue({});

render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);

const input = screen.getByTestId("invite-dialog-input");
input.focus();
await userEvent.paste(`${bobbob}`);

await screen.findAllByText(bobId);
expect(input).toHaveValue(`${bobbob}`);
});

it("should allow to invite multiple emails to a room", async () => {
render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
Expand Down

0 comments on commit 34e85dc

Please sign in to comment.