Skip to content

Commit 5ee8e61

Browse files
Search for users on paste (matrix-org#11304)
Signed-off-by: Peter Scheu <peter.scheu@aceart.de>
1 parent 771d7e9 commit 5ee8e61

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/components/views/dialogs/InviteDialog.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,17 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
870870
return;
871871
}
872872

873+
const text = e.clipboardData.getData("text");
874+
const potentialAddresses = this.parseFilter(text);
875+
// one search term which is not a mxid or email address
876+
if (potentialAddresses.length === 1 && !potentialAddresses[0].includes("@")) {
877+
return;
878+
}
879+
873880
// Prevent the text being pasted into the input
874881
e.preventDefault();
875882

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

892-
const potentialAddresses = this.parseFilter(text);
893-
894898
for (const address of potentialAddresses) {
895899
const member = possibleMembers.find((m) => m.userId === address);
896900
if (member) {

test/components/views/dialogs/InviteDialog-test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const aliceEmail = "foobar@email.com";
8686
const bobId = "@bob:example.org";
8787
const bobEmail = "bobbob@example.com"; // bob@example.com is already used as an example in the invite dialog
8888
const carolId = "@carol:example.com";
89+
const bobbob = "bobbob";
8990

9091
const aliceProfileInfo: IProfileInfo = {
9192
user_id: aliceId,
@@ -290,6 +291,19 @@ describe("InviteDialog", () => {
290291
await screen.findByText(aliceEmail);
291292
expect(input).toHaveValue("");
292293
});
294+
it("should support pasting one username that is not a mx id or email", async () => {
295+
mockClient.getIdentityServerUrl.mockReturnValue("https://identity-server");
296+
mockClient.lookupThreePid.mockResolvedValue({});
297+
298+
render(<InviteDialog kind={InviteKind.Invite} roomId={roomId} onFinished={jest.fn()} />);
299+
300+
const input = screen.getByTestId("invite-dialog-input");
301+
input.focus();
302+
await userEvent.paste(`${bobbob}`);
303+
304+
await screen.findAllByText(bobId);
305+
expect(input).toHaveValue(`${bobbob}`);
306+
});
293307

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

0 commit comments

Comments
 (0)