From 76efa9281eb702f885e7a0377d5e0995806e63df Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Thu, 8 Jan 2026 14:13:21 -0500 Subject: [PATCH 1/4] MSC4140: add dedicated endpoint for delayed events Use a new, dedicated endpoint for scheduling delayed events. This should deprecate the `delay` query parameter on the `/send` and `/state` endpoints. --- spec/unit/matrix-client.spec.ts | 402 ++++++++++++++++++++++++++------ src/client.ts | 67 +++++- 2 files changed, 384 insertions(+), 85 deletions(-) diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index de1e6575b10..fc707962c62 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -770,7 +770,7 @@ describe("MatrixClient", function () { const body = "This is the body"; const content = { body, msgtype: MsgType.Text } satisfies RoomMessageEventContent; const timeoutDelayOpts = { delay: 2000 }; - const realTimeoutDelayOpts = { "org.matrix.msc4140.delay": 2000 }; + const timeoutDelayQueryOpts = { "org.matrix.msc4140.delay": 2000 }; beforeEach(() => { unstableFeatures["org.matrix.msc4140"] = true; @@ -808,17 +808,38 @@ describe("MatrixClient", function () { await expect(client._unstable_sendScheduledDelayedEvent("anyDelayId")).rejects.toThrow(errorMessage); }); - it("works with null threadId", async () => { + it.each([false, true])("works with null threadId (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { httpLookups = []; const timeoutDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: realTimeoutDelayOpts, - data: { delay_id: "id1" }, - expectBody: content, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody: content, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content, + }, + }); + } const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( roomId, @@ -830,13 +851,34 @@ describe("MatrixClient", function () { ); const actionDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody: content, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody: content, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content, + }, + }); + } await client._unstable_sendDelayedEvent( roomId, @@ -848,7 +890,7 @@ describe("MatrixClient", function () { ); }); - it("works with non-null threadId", async () => { + it.each([false, true])("works with non-null threadId (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { httpLookups = []; const threadId = "$threadId:server"; const expectBody = { @@ -861,13 +903,34 @@ describe("MatrixClient", function () { }; const timeoutDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: realTimeoutDelayOpts, - data: { delay_id: "id1" }, - expectBody, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content: expectBody, + }, + }); + } const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( roomId, @@ -879,13 +942,34 @@ describe("MatrixClient", function () { ); const actionDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content: expectBody, + }, + }); + } await client._unstable_sendDelayedEvent( roomId, @@ -897,7 +981,7 @@ describe("MatrixClient", function () { ); }); - it("should add thread relation if threadId is passed and the relation is missing", async () => { + it.each([false, true])("should add thread relation if threadId is passed and the relation is missing (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { httpLookups = []; const threadId = "$threadId:server"; const expectBody = { @@ -919,13 +1003,34 @@ describe("MatrixClient", function () { room.createThread(threadId, rootEvent, [rootEvent], false); const timeoutDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: realTimeoutDelayOpts, - data: { delay_id: "id1" }, - expectBody, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content: expectBody, + }, + }); + } const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( roomId, @@ -937,13 +1042,34 @@ describe("MatrixClient", function () { ); const actionDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content: expectBody, + }, + }); + } await client._unstable_sendDelayedEvent( roomId, @@ -955,7 +1081,7 @@ describe("MatrixClient", function () { ); }); - it("should add thread relation if threadId is passed and the relation is missing with reply", async () => { + it.each([false, true])("should add thread relation if threadId is passed and the relation is missing with reply (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { httpLookups = []; const threadId = "$threadId:server"; @@ -987,13 +1113,34 @@ describe("MatrixClient", function () { room.createThread(threadId, rootEvent, [rootEvent], false); const timeoutDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: realTimeoutDelayOpts, - data: { delay_id: "id1" }, - expectBody, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content: expectBody, + }, + }); + } const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( roomId, @@ -1005,13 +1152,34 @@ describe("MatrixClient", function () { ); const actionDelayTxnId = client.makeTxnId(); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content: expectBody, + }, + }); + } await client._unstable_sendDelayedEvent( roomId, @@ -1023,17 +1191,39 @@ describe("MatrixClient", function () { ); }); - it("can send a delayed state event", async () => { + it.each([false, true])("can send a delayed state event (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { httpLookups = []; const content = { topic: "The year 2000" }; - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, - expectQueryParams: realTimeoutDelayOpts, - data: { delay_id: "id1" }, - expectBody: content, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody: content, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + state_key: "", + content, + } + }); + } const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedStateEvent( roomId, @@ -1042,13 +1232,35 @@ describe("MatrixClient", function () { { ...content }, ); - httpLookups.push({ - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody: content, - }); + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody: content, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + state_key: "", + content, + } + }); + } await client._unstable_sendDelayedStateEvent( roomId, @@ -1056,6 +1268,44 @@ describe("MatrixClient", function () { EventType.RoomTopic, { ...content }, ); + + if (!useDedicatedEndpoint) { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/org.example.state`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/state/org.example.state/xyz`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id3" }, + expectBody: content, + }); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/org.example.state`, + data: { delay_id: "id3" }, + expectBody: { + ...timeoutDelayOpts, + state_key: "xyz", + content, + } + }); + } + + await client._unstable_sendDelayedStateEvent( + roomId, + timeoutDelayOpts, + "org.example.state" as any, + { ...content }, + "xyz", + ); }); describe("lookups", () => { diff --git a/src/client.ts b/src/client.ts index e6756f9ac18..fc4e23b73b3 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3057,7 +3057,7 @@ export class MatrixClient extends TypedEventEmitter; - private sendEventHttpRequest( + private async sendEventHttpRequest( event: MatrixEvent, queryOrDelayOpts?: SendDelayedEventRequestOpts | QueryDict, queryDict?: QueryDict, @@ -3075,6 +3075,37 @@ export class MatrixClient extends TypedEventEmitter( + Method.Put, + utils.encodeUri("/rooms/$roomId/delayed_event/$eventType/$txnId", pathParams), + undefined, + { + ...delayOpts, + ...queryOpts, + ...(event.isState() && { state_key: event.getStateKey()! }), + content, + }, + { + prefix: `${ClientPrefix.Unstable}/${UNSTABLE_MSC4140_DELAYED_EVENTS}`, + }, + ); + } catch (e) { + // For backwards compatibility with implementations of MSC4140 that + // do not support a dedicated endpoint for adding delayed events + if (!(e instanceof MatrixError && e.errcode === "M_UNRECOGNIZED")) { + throw e; + } + } + } + let path: string; if (event.isState()) { @@ -3093,10 +3124,6 @@ export class MatrixClient extends TypedEventEmitter( Method.Put, @@ -3559,11 +3586,33 @@ export class MatrixClient extends TypedEventEmitter Date: Thu, 8 Jan 2026 14:14:20 -0500 Subject: [PATCH 2/4] Slight optimization of state key usage --- src/client.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index fc4e23b73b3..3f78c6fdd44 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3071,7 +3071,6 @@ export class MatrixClient extends TypedEventEmitter 0) { pathTemplate = "/rooms/$roomId/state/$eventType/$stateKey"; } - path = utils.encodeUri(pathTemplate, pathParams); + path = utils.encodeUri(pathTemplate, { + $stateKey: event.getStateKey()!, + ...pathParams, + }); } else if (event.isRedaction() && event.event.redacts) { const pathTemplate = `/rooms/$roomId/redact/$redactsEventId/$txnId`; path = utils.encodeUri(pathTemplate, { @@ -3584,7 +3586,6 @@ export class MatrixClient extends TypedEventEmitter Date: Fri, 9 Jan 2026 09:07:33 -0500 Subject: [PATCH 3/4] Use `return await` consistently In methods that were updated to await a promise, don't later directly return a promise without awaiting it. --- src/client.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/client.ts b/src/client.ts index 3f78c6fdd44..de19676bcfe 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3127,17 +3127,16 @@ export class MatrixClient extends TypedEventEmitter( + return await this.http.authedRequest( Method.Put, path, { ...getUnstableDelayQueryOpts(delayOpts), ...queryOpts }, content, ); } else { - return this.http.authedRequest(Method.Put, path, queryOpts, content).then((res) => { - this.logger.debug(`Event sent to ${event.getRoomId()} with event id ${res.event_id}`); - return res; - }); + const res = await this.http.authedRequest(Method.Put, path, queryOpts, content); + this.logger.debug(`Event sent to ${event.getRoomId()} with event id ${res.event_id}`); + return res; } } @@ -3608,7 +3607,7 @@ export class MatrixClient extends TypedEventEmitter Date: Fri, 9 Jan 2026 09:14:29 -0500 Subject: [PATCH 4/4] Lint test file --- spec/unit/matrix-client.spec.ts | 982 +++++++++++++++++--------------- 1 file changed, 515 insertions(+), 467 deletions(-) diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index fc707962c62..702300294cf 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -808,505 +808,553 @@ describe("MatrixClient", function () { await expect(client._unstable_sendScheduledDelayedEvent("anyDelayId")).rejects.toThrow(errorMessage); }); - it.each([false, true])("works with null threadId (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { - httpLookups = []; - - const timeoutDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: timeoutDelayQueryOpts, - data: { delay_id: "id1" }, - expectBody: content, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - data: { delay_id: "id1" }, - expectBody: { - ...timeoutDelayOpts, - content, - }, - }); - } - - const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( - roomId, - timeoutDelayOpts, - null, - EventType.RoomMessage, - { ...content }, - timeoutDelayTxnId, - ); + it.each([false, true])( + "works with null threadId (with dedicated endpoint: %s)", + async (useDedicatedEndpoint: boolean) => { + httpLookups = []; + + const timeoutDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody: content, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content, + }, + }); + } - const actionDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody: content, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - data: { delay_id: "id2" }, - expectBody: { - parent_delay_id: timeoutDelayId, - content, - }, - }); - } + const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( + roomId, + timeoutDelayOpts, + null, + EventType.RoomMessage, + { ...content }, + timeoutDelayTxnId, + ); - await client._unstable_sendDelayedEvent( - roomId, - { parent_delay_id: timeoutDelayId }, - null, - EventType.RoomMessage, - { ...content }, - actionDelayTxnId, - ); - }); + const actionDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody: content, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content, + }, + }); + } - it.each([false, true])("works with non-null threadId (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { - httpLookups = []; - const threadId = "$threadId:server"; - const expectBody = { - ...content, - "m.relates_to": { - event_id: threadId, - is_falling_back: true, - rel_type: "m.thread", - }, - }; + await client._unstable_sendDelayedEvent( + roomId, + { parent_delay_id: timeoutDelayId }, + null, + EventType.RoomMessage, + { ...content }, + actionDelayTxnId, + ); + }, + ); - const timeoutDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: timeoutDelayQueryOpts, - data: { delay_id: "id1" }, - expectBody, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - data: { delay_id: "id1" }, - expectBody: { - ...timeoutDelayOpts, - content: expectBody, + it.each([false, true])( + "works with non-null threadId (with dedicated endpoint: %s)", + async (useDedicatedEndpoint: boolean) => { + httpLookups = []; + const threadId = "$threadId:server"; + const expectBody = { + ...content, + "m.relates_to": { + event_id: threadId, + is_falling_back: true, + rel_type: "m.thread", }, - }); - } + }; - const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( - roomId, - timeoutDelayOpts, - threadId, - EventType.RoomMessage, - { ...content }, - timeoutDelayTxnId, - ); + const timeoutDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content: expectBody, + }, + }); + } - const actionDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - data: { delay_id: "id2" }, - expectBody: { - parent_delay_id: timeoutDelayId, - content: expectBody, - }, - }); - } + const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( + roomId, + timeoutDelayOpts, + threadId, + EventType.RoomMessage, + { ...content }, + timeoutDelayTxnId, + ); - await client._unstable_sendDelayedEvent( - roomId, - { parent_delay_id: timeoutDelayId }, - threadId, - EventType.RoomMessage, - { ...content }, - actionDelayTxnId, - ); - }); + const actionDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content: expectBody, + }, + }); + } - it.each([false, true])("should add thread relation if threadId is passed and the relation is missing (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { - httpLookups = []; - const threadId = "$threadId:server"; - const expectBody = { - ...content, - "m.relates_to": { - "m.in_reply_to": { - event_id: threadId, - }, - "event_id": threadId, - "is_falling_back": true, - "rel_type": "m.thread", - }, - }; + await client._unstable_sendDelayedEvent( + roomId, + { parent_delay_id: timeoutDelayId }, + threadId, + EventType.RoomMessage, + { ...content }, + actionDelayTxnId, + ); + }, + ); - const room = new Room(roomId, client, userId); - mocked(store.getRoom).mockReturnValue(room); + it.each([false, true])( + "should add thread relation if threadId is passed and the relation is missing (with dedicated endpoint: %s)", + async (useDedicatedEndpoint: boolean) => { + httpLookups = []; + const threadId = "$threadId:server"; + const expectBody = { + ...content, + "m.relates_to": { + "m.in_reply_to": { + event_id: threadId, + }, + "event_id": threadId, + "is_falling_back": true, + "rel_type": "m.thread", + }, + }; - const rootEvent = new MatrixEvent({ event_id: threadId }); - room.createThread(threadId, rootEvent, [rootEvent], false); + const room = new Room(roomId, client, userId); + mocked(store.getRoom).mockReturnValue(room); - const timeoutDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: timeoutDelayQueryOpts, - data: { delay_id: "id1" }, - expectBody, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - data: { delay_id: "id1" }, - expectBody: { - ...timeoutDelayOpts, - content: expectBody, - }, - }); - } + const rootEvent = new MatrixEvent({ event_id: threadId }); + room.createThread(threadId, rootEvent, [rootEvent], false); - const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( - roomId, - timeoutDelayOpts, - threadId, - EventType.RoomMessage, - { ...content }, - timeoutDelayTxnId, - ); + const timeoutDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content: expectBody, + }, + }); + } - const actionDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - data: { delay_id: "id2" }, - expectBody: { - parent_delay_id: timeoutDelayId, - content: expectBody, - }, - }); - } + const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( + roomId, + timeoutDelayOpts, + threadId, + EventType.RoomMessage, + { ...content }, + timeoutDelayTxnId, + ); - await client._unstable_sendDelayedEvent( - roomId, - { parent_delay_id: timeoutDelayId }, - threadId, - EventType.RoomMessage, - { ...content }, - actionDelayTxnId, - ); - }); + const actionDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content: expectBody, + }, + }); + } - it.each([false, true])("should add thread relation if threadId is passed and the relation is missing with reply (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { - httpLookups = []; - const threadId = "$threadId:server"; + await client._unstable_sendDelayedEvent( + roomId, + { parent_delay_id: timeoutDelayId }, + threadId, + EventType.RoomMessage, + { ...content }, + actionDelayTxnId, + ); + }, + ); - const content = { - body, - "msgtype": MsgType.Text, - "m.relates_to": { - "m.in_reply_to": { - event_id: "$other:event", + it.each([false, true])( + "should add thread relation if threadId is passed and the relation is missing with reply (with dedicated endpoint: %s)", + async (useDedicatedEndpoint: boolean) => { + httpLookups = []; + const threadId = "$threadId:server"; + + const content = { + body, + "msgtype": MsgType.Text, + "m.relates_to": { + "m.in_reply_to": { + event_id: "$other:event", + }, }, - }, - } satisfies RoomMessageEventContent; - const expectBody = { - ...content, - "m.relates_to": { - "m.in_reply_to": { - event_id: "$other:event", + } satisfies RoomMessageEventContent; + const expectBody = { + ...content, + "m.relates_to": { + "m.in_reply_to": { + event_id: "$other:event", + }, + "event_id": threadId, + "is_falling_back": false, + "rel_type": "m.thread", }, - "event_id": threadId, - "is_falling_back": false, - "rel_type": "m.thread", - }, - }; + }; - const room = new Room(roomId, client, userId); - mocked(store.getRoom).mockReturnValue(room); + const room = new Room(roomId, client, userId); + mocked(store.getRoom).mockReturnValue(room); - const rootEvent = new MatrixEvent({ event_id: threadId }); - room.createThread(threadId, rootEvent, [rootEvent], false); + const rootEvent = new MatrixEvent({ event_id: threadId }); + room.createThread(threadId, rootEvent, [rootEvent], false); - const timeoutDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, - expectQueryParams: timeoutDelayQueryOpts, - data: { delay_id: "id1" }, - expectBody, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, - data: { delay_id: "id1" }, - expectBody: { - ...timeoutDelayOpts, - content: expectBody, - }, - }); - } + const timeoutDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${timeoutDelayTxnId}`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + content: expectBody, + }, + }); + } - const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( - roomId, - timeoutDelayOpts, - threadId, - EventType.RoomMessage, - { ...content }, - timeoutDelayTxnId, - ); + const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent( + roomId, + timeoutDelayOpts, + threadId, + EventType.RoomMessage, + { ...content }, + timeoutDelayTxnId, + ); - const actionDelayTxnId = client.makeTxnId(); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, - data: { delay_id: "id2" }, - expectBody: { - parent_delay_id: timeoutDelayId, - content: expectBody, - }, - }); - } + const actionDelayTxnId = client.makeTxnId(); + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.message/${actionDelayTxnId}`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + content: expectBody, + }, + }); + } - await client._unstable_sendDelayedEvent( - roomId, - { parent_delay_id: timeoutDelayId }, - threadId, - EventType.RoomMessage, - { ...content }, - actionDelayTxnId, - ); - }); + await client._unstable_sendDelayedEvent( + roomId, + { parent_delay_id: timeoutDelayId }, + threadId, + EventType.RoomMessage, + { ...content }, + actionDelayTxnId, + ); + }, + ); - it.each([false, true])("can send a delayed state event (with dedicated endpoint: %s)", async (useDedicatedEndpoint: boolean) => { - httpLookups = []; - const content = { topic: "The year 2000" }; + it.each([false, true])( + "can send a delayed state event (with dedicated endpoint: %s)", + async (useDedicatedEndpoint: boolean) => { + httpLookups = []; + const content = { topic: "The year 2000" }; - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, - expectQueryParams: timeoutDelayQueryOpts, - data: { delay_id: "id1" }, - expectBody: content, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, - data: { delay_id: "id1" }, - expectBody: { - ...timeoutDelayOpts, - state_key: "", - content, - } - }); - } + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id1" }, + expectBody: content, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + data: { delay_id: "id1" }, + expectBody: { + ...timeoutDelayOpts, + state_key: "", + content, + }, + }); + } - const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedStateEvent( - roomId, - timeoutDelayOpts, - EventType.RoomTopic, - { ...content }, - ); + const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedStateEvent( + roomId, + timeoutDelayOpts, + EventType.RoomTopic, + { ...content }, + ); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, - expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, - data: { delay_id: "id2" }, - expectBody: content, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, - data: { delay_id: "id2" }, - expectBody: { - parent_delay_id: timeoutDelayId, - state_key: "", - content, - } - }); - } + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`, + expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId }, + data: { delay_id: "id2" }, + expectBody: content, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/m.room.topic`, + data: { delay_id: "id2" }, + expectBody: { + parent_delay_id: timeoutDelayId, + state_key: "", + content, + }, + }); + } - await client._unstable_sendDelayedStateEvent( - roomId, - { parent_delay_id: timeoutDelayId }, - EventType.RoomTopic, - { ...content }, - ); + await client._unstable_sendDelayedStateEvent( + roomId, + { parent_delay_id: timeoutDelayId }, + EventType.RoomTopic, + { ...content }, + ); - if (!useDedicatedEndpoint) { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/org.example.state`, - error: { - httpStatus: 404, - errcode: "M_UNRECOGNIZED", - }, - }, { - method: "PUT", - path: `/rooms/${encodeURIComponent(roomId)}/state/org.example.state/xyz`, - expectQueryParams: timeoutDelayQueryOpts, - data: { delay_id: "id3" }, - expectBody: content, - }); - } else { - httpLookups.push({ - method: "PUT", - prefix: unstableMSC4140Prefix, - path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/org.example.state`, - data: { delay_id: "id3" }, - expectBody: { - ...timeoutDelayOpts, - state_key: "xyz", - content, - } - }); - } + if (!useDedicatedEndpoint) { + httpLookups.push( + { + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/org.example.state`, + error: { + httpStatus: 404, + errcode: "M_UNRECOGNIZED", + }, + }, + { + method: "PUT", + path: `/rooms/${encodeURIComponent(roomId)}/state/org.example.state/xyz`, + expectQueryParams: timeoutDelayQueryOpts, + data: { delay_id: "id3" }, + expectBody: content, + }, + ); + } else { + httpLookups.push({ + method: "PUT", + prefix: unstableMSC4140Prefix, + path: `/rooms/${encodeURIComponent(roomId)}/delayed_event/org.example.state`, + data: { delay_id: "id3" }, + expectBody: { + ...timeoutDelayOpts, + state_key: "xyz", + content, + }, + }); + } - await client._unstable_sendDelayedStateEvent( - roomId, - timeoutDelayOpts, - "org.example.state" as any, - { ...content }, - "xyz", - ); - }); + await client._unstable_sendDelayedStateEvent( + roomId, + timeoutDelayOpts, + "org.example.state" as any, + { ...content }, + "xyz", + ); + }, + ); describe("lookups", () => { const statuses = [undefined, "scheduled" as const, "finalised" as const];