Search for users on paste (#11304)

Signed-off-by: Peter Scheu <peter.scheu@aceart.de>
This commit is contained in:
Peter Scheu 2023-08-04 09:19:56 +02:00 committed by GitHub
parent 771d7e95e7
commit 5ee8e61bf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -870,11 +870,17 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
return; 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 // Prevent the text being pasted into the input
e.preventDefault(); e.preventDefault();
// Process it as a list of addresses to add instead // Process it as a list of addresses to add instead
const text = e.clipboardData.getData("text");
const possibleMembers = [ const possibleMembers = [
// If we can avoid hitting the profile endpoint, we should. // If we can avoid hitting the profile endpoint, we should.
...this.state.recents, ...this.state.recents,
@ -889,8 +895,6 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
// Will be displayed as filter text to provide feedback. // Will be displayed as filter text to provide feedback.
const unableToAddMore: string[] = []; const unableToAddMore: string[] = [];
const potentialAddresses = this.parseFilter(text);
for (const address of potentialAddresses) { for (const address of potentialAddresses) {
const member = possibleMembers.find((m) => m.userId === address); const member = possibleMembers.find((m) => m.userId === address);
if (member) { if (member) {

View file

@ -86,6 +86,7 @@ const aliceEmail = "foobar@email.com";
const bobId = "@bob:example.org"; const bobId = "@bob:example.org";
const bobEmail = "bobbob@example.com"; // bob@example.com is already used as an example in the invite dialog const bobEmail = "bobbob@example.com"; // bob@example.com is already used as an example in the invite dialog
const carolId = "@carol:example.com"; const carolId = "@carol:example.com";
const bobbob = "bobbob";
const aliceProfileInfo: IProfileInfo = { const aliceProfileInfo: IProfileInfo = {
user_id: aliceId, user_id: aliceId,
@ -290,6 +291,19 @@ describe("InviteDialog", () => {
await screen.findByText(aliceEmail); await screen.findByText(aliceEmail);
expect(input).toHaveValue(""); 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 () => { it("should allow to invite multiple emails to a room", async () => {
render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />); render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);