Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions spec/unit/embedded.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
expect(widgetApi.requestCapabilityForRoomTimeline).toHaveBeenCalledWith("!1:example.org");
expect(widgetApi.requestCapabilityToSendEvent).toHaveBeenCalledWith("org.matrix.rageshake_request");
await client.sendEvent("!1:example.org", "org.matrix.rageshake_request", { request_id: 123 });
expect(widgetApi.sendRoomEvent).toHaveBeenCalledWith(

Check failure on line 171 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › events › sends

expect(jest.fn()).toHaveBeenCalledWith(...expected) - Expected + Received "org.matrix.rageshake_request", {"request_id": 123}, "!1:example.org", + undefined, + undefined, + undefined, Number of calls: 1 at Object.toHaveBeenCalledWith (spec/unit/embedded.spec.ts:171:45) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 171 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › events › sends

expect(jest.fn()).toHaveBeenCalledWith(...expected) - Expected + Received "org.matrix.rageshake_request", {"request_id": 123}, "!1:example.org", + undefined, + undefined, + undefined, Number of calls: 1 at Object.toHaveBeenCalledWith (spec/unit/embedded.spec.ts:171:45) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
"org.matrix.rageshake_request",
{ request_id: 123 },
"!1:example.org",
Expand Down Expand Up @@ -421,7 +421,7 @@
"org.matrix.rageshake_request",
{ request_id: 123 },
);
expect(widgetApi.sendRoomEvent).toHaveBeenCalledWith(

Check failure on line 424 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

RoomWidgetClient › delayed events › when supported › sends delayed message events

expect(jest.fn()).toHaveBeenCalledWith(...expected) - Expected + Received "org.matrix.rageshake_request", {"request_id": 123}, "!1:example.org", 2000, undefined, + undefined, Number of calls: 1 at Object.toHaveBeenCalledWith (spec/unit/embedded.spec.ts:424:49) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)

Check failure on line 424 in spec/unit/embedded.spec.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

RoomWidgetClient › delayed events › when supported › sends delayed message events

expect(jest.fn()).toHaveBeenCalledWith(...expected) - Expected + Received "org.matrix.rageshake_request", {"request_id": 123}, "!1:example.org", 2000, undefined, + undefined, Number of calls: 1 at Object.toHaveBeenCalledWith (spec/unit/embedded.spec.ts:424:49) at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17) at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
"org.matrix.rageshake_request",
{ request_id: 123 },
"!1:example.org",
Expand All @@ -430,26 +430,6 @@
);
});

it("sends child action delayed message events", async () => {
await makeClient({ sendDelayedEvents: true, sendEvent: ["org.matrix.rageshake_request"] });
expect(widgetApi.requestCapability).toHaveBeenCalledWith(MatrixCapabilities.MSC4157SendDelayedEvent);
const parentDelayId = `id-${Math.random()}`;
await client._unstable_sendDelayedEvent(
"!1:example.org",
{ parent_delay_id: parentDelayId },
null,
"org.matrix.rageshake_request",
{ request_id: 123 },
);
expect(widgetApi.sendRoomEvent).toHaveBeenCalledWith(
"org.matrix.rageshake_request",
{ request_id: 123 },
"!1:example.org",
undefined,
parentDelayId,
);
});

it("sends delayed state events", async () => {
await makeClient({
sendDelayedEvents: true,
Expand All @@ -473,30 +453,6 @@
);
});

it("sends child action delayed state events", async () => {
await makeClient({
sendDelayedEvents: true,
sendState: [{ eventType: "org.example.foo", stateKey: "bar" }],
});
expect(widgetApi.requestCapability).toHaveBeenCalledWith(MatrixCapabilities.MSC4157SendDelayedEvent);
const parentDelayId = `fg-${Math.random()}`;
await client._unstable_sendDelayedStateEvent(
"!1:example.org",
{ parent_delay_id: parentDelayId },
"org.example.foo",
{ hello: "world" },
"bar",
);
expect(widgetApi.sendStateEvent).toHaveBeenCalledWith(
"org.example.foo",
"bar",
{ hello: "world" },
"!1:example.org",
undefined,
parentDelayId,
);
});

it("send delayed message events handles wrong field in response", async () => {
await makeClient({ sendDelayedEvents: true, sendEvent: ["org.matrix.rageshake_request"] });
widgetApi.sendRoomEvent.mockResolvedValueOnce({
Expand Down
103 changes: 6 additions & 97 deletions spec/unit/matrix-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,32 +825,15 @@ describe("MatrixClient", function () {
expectBody: content,
});

const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
await client._unstable_sendDelayedEvent(
roomId,
timeoutDelayOpts,
null,
EventType.RoomMessage,
{ ...content },
timeoutDelayTxnId,
);

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,
});

await client._unstable_sendDelayedEvent(
roomId,
{ parent_delay_id: timeoutDelayId },
null,
EventType.RoomMessage,
{ ...content },
actionDelayTxnId,
);
// expect not to throw
});

it("works with non-null threadId", async () => {
Expand All @@ -874,32 +857,14 @@ describe("MatrixClient", function () {
expectBody,
});

const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
await client._unstable_sendDelayedEvent(
roomId,
timeoutDelayOpts,
threadId,
EventType.RoomMessage,
{ ...content },
timeoutDelayTxnId,
);

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,
});

await client._unstable_sendDelayedEvent(
roomId,
{ parent_delay_id: timeoutDelayId },
threadId,
EventType.RoomMessage,
{ ...content },
actionDelayTxnId,
);
});

it("should add thread relation if threadId is passed and the relation is missing", async () => {
Expand Down Expand Up @@ -932,32 +897,14 @@ describe("MatrixClient", function () {
expectBody,
});

const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
await client._unstable_sendDelayedEvent(
roomId,
timeoutDelayOpts,
threadId,
EventType.RoomMessage,
{ ...content },
timeoutDelayTxnId,
);

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,
});

await client._unstable_sendDelayedEvent(
roomId,
{ parent_delay_id: timeoutDelayId },
threadId,
EventType.RoomMessage,
{ ...content },
actionDelayTxnId,
);
});

it("should add thread relation if threadId is passed and the relation is missing with reply", async () => {
Expand Down Expand Up @@ -1000,32 +947,14 @@ describe("MatrixClient", function () {
expectBody,
});

const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
await client._unstable_sendDelayedEvent(
roomId,
timeoutDelayOpts,
threadId,
EventType.RoomMessage,
{ ...content },
timeoutDelayTxnId,
);

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,
});

await client._unstable_sendDelayedEvent(
roomId,
{ parent_delay_id: timeoutDelayId },
threadId,
EventType.RoomMessage,
{ ...content },
actionDelayTxnId,
);
});

it("can send a delayed state event", async () => {
Expand All @@ -1040,27 +969,7 @@ describe("MatrixClient", function () {
expectBody: content,
});

const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedStateEvent(
roomId,
timeoutDelayOpts,
EventType.RoomTopic,
{ ...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,
});

await client._unstable_sendDelayedStateEvent(
roomId,
{ parent_delay_id: timeoutDelayId },
EventType.RoomTopic,
{ ...content },
);
await client._unstable_sendDelayedStateEvent(roomId, timeoutDelayOpts, EventType.RoomTopic, { ...content });
});

describe("lookups", () => {
Expand Down
26 changes: 11 additions & 15 deletions src/@types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,19 @@ export interface ISendEventResponse {
event_id: string;
}

export type SendDelayedEventRequestOpts = { parent_delay_id: string } | { delay: number; parent_delay_id?: string };

export function isSendDelayedEventRequestOpts(opts: object): opts is SendDelayedEventRequestOpts {
if ("parent_delay_id" in opts && typeof opts.parent_delay_id !== "string") {
// Invalid type, reject
return false;
}
if ("delay" in opts && typeof opts.delay !== "number") {
// Invalid type, reject.
return true;
}
// At least one of these fields must be specified.
return "delay" in opts || "parent_delay_id" in opts;
// sticky
export interface SendStickyEventRequestOpts {
sticky_duration_ms: number;
}
export type SendDelayedEventResponse = {

// delayed
export interface SendDelayedEventRequestOpts {
delay: number;
}

export interface SendDelayedEventResponse {
delay_id: string;
};
}

export enum UpdateDelayedEventAction {
Cancel = "cancel",
Expand Down
Loading
Loading