From a6efcd2f36949fc7c8aba9d514427eb036dd32da Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Wed, 25 Feb 2026 17:27:59 -0500 Subject: [PATCH] Matrix-js: dedupe monitor types and stabilize verification test --- .../src/matrix/monitor/events.test.ts | 8 ++++--- .../matrix-js/src/matrix/monitor/mentions.ts | 12 ++-------- .../matrix-js/src/matrix/monitor/threads.ts | 22 ++----------------- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/extensions/matrix-js/src/matrix/monitor/events.test.ts b/extensions/matrix-js/src/matrix/monitor/events.test.ts index cbfc3311187..cc9c8290b94 100644 --- a/extensions/matrix-js/src/matrix/monitor/events.test.ts +++ b/extensions/matrix-js/src/matrix/monitor/events.test.ts @@ -115,7 +115,7 @@ describe("registerMatrixMonitorEvents verification routing", () => { }); it("posts SAS emoji/decimal details when verification summaries expose them", async () => { - const { sendMessage, roomEventListener } = createHarness({ + const { sendMessage, roomEventListener, listVerifications } = createHarness({ verifications: [ { id: "verification-1", @@ -155,7 +155,7 @@ describe("registerMatrixMonitorEvents verification routing", () => { }); it("does not emit duplicate SAS notices for the same verification payload", async () => { - const { sendMessage, roomEventListener } = createHarness({ + const { sendMessage, roomEventListener, listVerifications } = createHarness({ verifications: [ { id: "verification-3", @@ -196,7 +196,9 @@ describe("registerMatrixMonitorEvents verification routing", () => { "m.relates_to": { event_id: "$req3" }, }, }); - await new Promise((resolve) => setTimeout(resolve, 20)); + await vi.waitFor(() => { + expect(listVerifications).toHaveBeenCalledTimes(2); + }); const sasBodies = sendMessage.mock.calls .map((call) => String(((call as unknown[])[1] as { body?: string } | undefined)?.body ?? "")) diff --git a/extensions/matrix-js/src/matrix/monitor/mentions.ts b/extensions/matrix-js/src/matrix/monitor/mentions.ts index 7d3a52c9baa..aa67386221a 100644 --- a/extensions/matrix-js/src/matrix/monitor/mentions.ts +++ b/extensions/matrix-js/src/matrix/monitor/mentions.ts @@ -1,13 +1,5 @@ import { getMatrixRuntime } from "../../runtime.js"; - -type MessageContentWithMentions = { - formatted_body?: string; - "m.mentions"?: { - user_ids?: string[]; - room?: boolean; - }; - [key: string]: unknown; -}; +import type { RoomMessageEventContent } from "./types.js"; /** * Check if the formatted_body contains a matrix.to mention link for the given user ID. @@ -33,7 +25,7 @@ function checkFormattedBodyMention(formattedBody: string | undefined, userId: st } export function resolveMentions(params: { - content: MessageContentWithMentions; + content: RoomMessageEventContent; userId?: string | null; text?: string; mentionRegexes: RegExp[]; diff --git a/extensions/matrix-js/src/matrix/monitor/threads.ts b/extensions/matrix-js/src/matrix/monitor/threads.ts index c2ab69218a6..3c90e08dbfd 100644 --- a/extensions/matrix-js/src/matrix/monitor/threads.ts +++ b/extensions/matrix-js/src/matrix/monitor/threads.ts @@ -1,23 +1,5 @@ -// Type for raw Matrix event payload consumed by thread helpers. -type MatrixRawEvent = { - event_id: string; - sender: string; - type: string; - origin_server_ts: number; - content: Record; -}; - -type RoomMessageEventContent = { - "m.relates_to"?: { - rel_type?: string; - event_id?: string; - "m.in_reply_to"?: { event_id?: string }; - }; -}; - -const RelationType = { - Thread: "m.thread", -} as const; +import type { MatrixRawEvent, RoomMessageEventContent } from "./types.js"; +import { RelationType } from "./types.js"; export function resolveMatrixThreadTarget(params: { threadReplies: "off" | "inbound" | "always";