diff --git a/src/createRoom.ts b/src/createRoom.ts index fd2fd30764..4f79cb9c64 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -119,7 +119,10 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro const createOpts: ICreateRoomOpts = opts.createOpts || {}; createOpts.preset = createOpts.preset || defaultPreset; createOpts.visibility = createOpts.visibility || Visibility.Private; - if (opts.dmUserId && createOpts.invite === undefined) { + + // We allow UX of DMing ourselves as a form of creating a personal room but the server throws + // an error when a user tries to invite themselves so we filter it out + if (opts.dmUserId && opts.dmUserId !== client.getUserId() && createOpts.invite === undefined) { switch (getAddressType(opts.dmUserId)) { case "mx-user-id": createOpts.invite = [opts.dmUserId]; diff --git a/test/createRoom-test.ts b/test/createRoom-test.ts index 0cdc5dd7f9..a3d413e982 100644 --- a/test/createRoom-test.ts +++ b/test/createRoom-test.ts @@ -142,6 +142,15 @@ describe("createRoom", () => { }), ); }); + + it("should strip self-invite", async () => { + await createRoom(client, { dmUserId: client.getSafeUserId() }); + expect(client.createRoom).toHaveBeenCalledWith( + expect.not.objectContaining({ + invite: expect.any(Array), + }), + ); + }); }); describe("canEncryptToAllUsers", () => {