Skip to content

Commit 33dc828

Browse files
committed
MSC4140: remove parent delay IDs
Drop support for sending delayed events that are sent upon the scheduled sending of another delayed event. This feature has been absent from the delayed event MSC for some time now, and is not known to have been implemented in any server. Depends on matrix-org/matrix-widget-api#162
1 parent 8073f27 commit 33dc828

File tree

4 files changed

+72
-210
lines changed

4 files changed

+72
-210
lines changed

spec/unit/embedded.spec.ts

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class MockWidgetApi extends EventEmitter {
7373
public requestCapabilityToSendToDevice = vi.fn().mockResolvedValue(undefined);
7474
public requestCapabilityToReceiveToDevice = vi.fn().mockResolvedValue(undefined);
7575
public sendRoomEvent = vi.fn(
76-
async (eventType: string, content: unknown, roomId?: string, delay?: number, parentDelayId?: string) =>
77-
delay === undefined && parentDelayId === undefined
76+
async (eventType: string, content: unknown, roomId?: string, delay?: number) =>
77+
delay === undefined
7878
? { event_id: `$${Math.random()}` }
7979
: { delay_id: `id-${Math.random()}` },
8080
);
@@ -85,9 +85,8 @@ class MockWidgetApi extends EventEmitter {
8585
content: unknown,
8686
roomId?: string,
8787
delay?: number,
88-
parentDelayId?: string,
8988
) =>
90-
delay === undefined && parentDelayId === undefined
89+
delay === undefined
9190
? { event_id: `$${Math.random()}` }
9291
: { delay_id: `id-${Math.random()}` },
9392
);
@@ -178,7 +177,6 @@ describe("RoomWidgetClient", () => {
178177
"!1:example.org",
179178
undefined,
180179
undefined,
181-
undefined,
182180
);
183181
});
184182

@@ -434,28 +432,6 @@ describe("RoomWidgetClient", () => {
434432
"!1:example.org",
435433
2000,
436434
undefined,
437-
undefined,
438-
);
439-
});
440-
441-
it("sends child action delayed message events", async () => {
442-
await makeClient({ sendDelayedEvents: true, sendEvent: ["org.matrix.rageshake_request"] });
443-
expect(widgetApi.requestCapability).toHaveBeenCalledWith(MatrixCapabilities.MSC4157SendDelayedEvent);
444-
const parentDelayId = `id-${Math.random()}`;
445-
await client._unstable_sendDelayedEvent(
446-
"!1:example.org",
447-
{ parent_delay_id: parentDelayId },
448-
null,
449-
"org.matrix.rageshake_request",
450-
{ request_id: 123 },
451-
);
452-
expect(widgetApi.sendRoomEvent).toHaveBeenCalledWith(
453-
"org.matrix.rageshake_request",
454-
{ request_id: 123 },
455-
"!1:example.org",
456-
undefined,
457-
parentDelayId,
458-
undefined,
459435
);
460436
});
461437

@@ -478,31 +454,6 @@ describe("RoomWidgetClient", () => {
478454
{ hello: "world" },
479455
"!1:example.org",
480456
2000,
481-
undefined,
482-
);
483-
});
484-
485-
it("sends child action delayed state events", async () => {
486-
await makeClient({
487-
sendDelayedEvents: true,
488-
sendState: [{ eventType: "org.example.foo", stateKey: "bar" }],
489-
});
490-
expect(widgetApi.requestCapability).toHaveBeenCalledWith(MatrixCapabilities.MSC4157SendDelayedEvent);
491-
const parentDelayId = `fg-${Math.random()}`;
492-
await client._unstable_sendDelayedStateEvent(
493-
"!1:example.org",
494-
{ parent_delay_id: parentDelayId },
495-
"org.example.foo",
496-
{ hello: "world" },
497-
"bar",
498-
);
499-
expect(widgetApi.sendStateEvent).toHaveBeenCalledWith(
500-
"org.example.foo",
501-
"bar",
502-
{ hello: "world" },
503-
"!1:example.org",
504-
undefined,
505-
parentDelayId,
506457
);
507458
});
508459

@@ -910,7 +861,6 @@ describe("RoomWidgetClient", () => {
910861
{ msc4354_sticky_key: "test" },
911862
"!1:example.org",
912863
undefined,
913-
undefined,
914864
2000,
915865
);
916866
});

spec/unit/matrix-client.spec.ts

Lines changed: 61 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,9 @@ describe("MatrixClient", function () {
781781
const roomId = "!room:example.org";
782782
const body = "This is the body";
783783
const content = { body, msgtype: MsgType.Text } satisfies RoomMessageEventContent;
784-
const timeoutDelayOpts = { delay: 2000 };
785-
const realTimeoutDelayOpts = { "org.matrix.msc4140.delay": 2000 };
784+
const delayOpts = { delay: 2000 };
785+
const realDelayOpts = { "org.matrix.msc4140.delay": 2000 };
786+
const delayData = { delay_id: "did" };
786787

787788
beforeEach(() => {
788789
unstableFeatures["org.matrix.msc4140"] = true;
@@ -795,7 +796,7 @@ describe("MatrixClient", function () {
795796
await expect(
796797
client._unstable_sendDelayedEvent(
797798
roomId,
798-
timeoutDelayOpts,
799+
delayOpts,
799800
null,
800801
EventType.RoomMessage,
801802
{ ...content },
@@ -804,7 +805,7 @@ describe("MatrixClient", function () {
804805
).rejects.toThrow(errorMessage);
805806

806807
await expect(
807-
client._unstable_sendDelayedStateEvent(roomId, timeoutDelayOpts, EventType.RoomTopic, {
808+
client._unstable_sendDelayedStateEvent(roomId, delayOpts, EventType.RoomTopic, {
808809
topic: "topic",
809810
}),
810811
).rejects.toThrow(errorMessage);
@@ -822,48 +823,29 @@ describe("MatrixClient", function () {
822823

823824
// eslint-disable-next-line @vitest/expect-expect
824825
it("works with null threadId", async () => {
825-
httpLookups = [];
826-
827-
const timeoutDelayTxnId = client.makeTxnId();
828-
httpLookups.push({
829-
method: "PUT",
830-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
831-
expectQueryParams: realTimeoutDelayOpts,
832-
data: { delay_id: "id1" },
833-
expectBody: content,
834-
});
835-
836-
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
837-
roomId,
838-
timeoutDelayOpts,
839-
null,
840-
EventType.RoomMessage,
841-
{ ...content },
842-
timeoutDelayTxnId,
843-
);
844-
845-
const actionDelayTxnId = client.makeTxnId();
846-
httpLookups.push({
847-
method: "PUT",
848-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
849-
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
850-
data: { delay_id: "id2" },
851-
expectBody: content,
852-
});
826+
const txnId = client.makeTxnId();
827+
httpLookups = [
828+
{
829+
method: "PUT",
830+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`,
831+
data: delayData,
832+
expectQueryParams: realDelayOpts,
833+
expectBody: content,
834+
},
835+
];
853836

854837
await client._unstable_sendDelayedEvent(
855838
roomId,
856-
{ parent_delay_id: timeoutDelayId },
839+
delayOpts,
857840
null,
858841
EventType.RoomMessage,
859842
{ ...content },
860-
actionDelayTxnId,
843+
txnId,
861844
);
862845
});
863846

864847
// eslint-disable-next-line @vitest/expect-expect
865848
it("works with non-null threadId", async () => {
866-
httpLookups = [];
867849
const threadId = "$threadId:server";
868850
const expectBody = {
869851
...content,
@@ -874,46 +856,29 @@ describe("MatrixClient", function () {
874856
},
875857
};
876858

877-
const timeoutDelayTxnId = client.makeTxnId();
878-
httpLookups.push({
879-
method: "PUT",
880-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
881-
expectQueryParams: realTimeoutDelayOpts,
882-
data: { delay_id: "id1" },
883-
expectBody,
884-
});
885-
886-
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
887-
roomId,
888-
timeoutDelayOpts,
889-
threadId,
890-
EventType.RoomMessage,
891-
{ ...content },
892-
timeoutDelayTxnId,
893-
);
894-
895-
const actionDelayTxnId = client.makeTxnId();
896-
httpLookups.push({
897-
method: "PUT",
898-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
899-
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
900-
data: { delay_id: "id2" },
901-
expectBody,
902-
});
859+
const txnId = client.makeTxnId();
860+
httpLookups = [
861+
{
862+
method: "PUT",
863+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`,
864+
data: delayData,
865+
expectQueryParams: realDelayOpts,
866+
expectBody,
867+
},
868+
];
903869

904870
await client._unstable_sendDelayedEvent(
905871
roomId,
906-
{ parent_delay_id: timeoutDelayId },
872+
delayOpts,
907873
threadId,
908874
EventType.RoomMessage,
909875
{ ...content },
910-
actionDelayTxnId,
876+
txnId,
911877
);
912878
});
913879

914880
// eslint-disable-next-line @vitest/expect-expect
915881
it("should add thread relation if threadId is passed and the relation is missing", async () => {
916-
httpLookups = [];
917882
const threadId = "$threadId:server";
918883
const expectBody = {
919884
...content,
@@ -934,39 +899,23 @@ describe("MatrixClient", function () {
934899
room.createThread(threadId, rootEvent, [rootEvent], false);
935900

936901
const timeoutDelayTxnId = client.makeTxnId();
937-
httpLookups.push({
938-
method: "PUT",
939-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
940-
expectQueryParams: realTimeoutDelayOpts,
941-
data: { delay_id: "id1" },
942-
expectBody,
943-
});
944-
945-
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
946-
roomId,
947-
timeoutDelayOpts,
948-
threadId,
949-
EventType.RoomMessage,
950-
{ ...content },
951-
timeoutDelayTxnId,
952-
);
953-
954-
const actionDelayTxnId = client.makeTxnId();
955-
httpLookups.push({
956-
method: "PUT",
957-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
958-
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
959-
data: { delay_id: "id2" },
960-
expectBody,
961-
});
902+
httpLookups = [
903+
{
904+
method: "PUT",
905+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
906+
data: delayData,
907+
expectQueryParams: realDelayOpts,
908+
expectBody,
909+
},
910+
];
962911

963912
await client._unstable_sendDelayedEvent(
964913
roomId,
965-
{ parent_delay_id: timeoutDelayId },
914+
delayOpts,
966915
threadId,
967916
EventType.RoomMessage,
968917
{ ...content },
969-
actionDelayTxnId,
918+
timeoutDelayTxnId,
970919
);
971920
});
972921

@@ -1003,39 +952,23 @@ describe("MatrixClient", function () {
1003952
room.createThread(threadId, rootEvent, [rootEvent], false);
1004953

1005954
const timeoutDelayTxnId = client.makeTxnId();
1006-
httpLookups.push({
1007-
method: "PUT",
1008-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
1009-
expectQueryParams: realTimeoutDelayOpts,
1010-
data: { delay_id: "id1" },
1011-
expectBody,
1012-
});
1013-
1014-
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
1015-
roomId,
1016-
timeoutDelayOpts,
1017-
threadId,
1018-
EventType.RoomMessage,
1019-
{ ...content },
1020-
timeoutDelayTxnId,
1021-
);
1022-
1023-
const actionDelayTxnId = client.makeTxnId();
1024-
httpLookups.push({
1025-
method: "PUT",
1026-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
1027-
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
1028-
data: { delay_id: "id2" },
1029-
expectBody,
1030-
});
955+
httpLookups = [
956+
{
957+
method: "PUT",
958+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
959+
data: delayData,
960+
expectQueryParams: realDelayOpts,
961+
expectBody,
962+
},
963+
];
1031964

1032965
await client._unstable_sendDelayedEvent(
1033966
roomId,
1034-
{ parent_delay_id: timeoutDelayId },
967+
delayOpts,
1035968
threadId,
1036969
EventType.RoomMessage,
1037970
{ ...content },
1038-
actionDelayTxnId,
971+
timeoutDelayTxnId,
1039972
);
1040973
});
1041974

@@ -1044,32 +977,19 @@ describe("MatrixClient", function () {
1044977
httpLookups = [];
1045978
const content = { topic: "The year 2000" };
1046979

1047-
httpLookups.push({
1048-
method: "PUT",
1049-
path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`,
1050-
expectQueryParams: realTimeoutDelayOpts,
1051-
data: { delay_id: "id1" },
1052-
expectBody: content,
1053-
});
1054-
1055-
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedStateEvent(
1056-
roomId,
1057-
timeoutDelayOpts,
1058-
EventType.RoomTopic,
1059-
{ ...content },
1060-
);
1061-
1062-
httpLookups.push({
1063-
method: "PUT",
1064-
path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`,
1065-
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
1066-
data: { delay_id: "id2" },
1067-
expectBody: content,
1068-
});
980+
httpLookups = [
981+
{
982+
method: "PUT",
983+
path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`,
984+
data: delayData,
985+
expectQueryParams: realDelayOpts,
986+
expectBody: content,
987+
},
988+
];
1069989

1070990
await client._unstable_sendDelayedStateEvent(
1071991
roomId,
1072-
{ parent_delay_id: timeoutDelayId },
992+
delayOpts,
1073993
EventType.RoomTopic,
1074994
{ ...content },
1075995
);

0 commit comments

Comments
 (0)