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 Jul 28, 2023
1 parent 5636a9f commit c235472
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cypress/e2e/invite/invite-dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,16 @@ describe("Invite dialog", function () {
// Assert that the message is displayed at the bottom
cy.get(".mx_EventTile_last").findByText("Hello").should("exist");
});

it("should support pasting one username that is not a mx id or email", () => {
cy.get(".mx_RoomList").within(() => {
cy.findByRole("button", { name: "Start chat" }).click();
});
cy.get(".mx_InviteDialog_other").within(() => {
cy.findByTestId("invite-dialog-input").invoke("val", "test");
cy.findByText("Failed to find the following users").should("not.exist");
cy.findByTestId("invite-dialog-input").invoke("val", "test,test,test");
cy.findByText("Failed to find the following users").should("exist");
});
});
});
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

0 comments on commit c235472

Please sign in to comment.