From aedd30ab4a0080083475d436af9a9ec813661b4c Mon Sep 17 00:00:00 2001 From: Guzio Date: Thu, 19 Feb 2026 17:48:32 +0000 Subject: [PATCH 1/2] Update "m.relates_to" type definition @ types.d.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * To better reflect reality ("m.in_reply_to" will not always be present - it's not (always?) found on "rel_type":"m.replace" relation-events) * To support "rel_type":"m.replace" relation-events (added "m.replace" option to existing key "rel_type" and a new "is_falling_back" key) AFFECTED TYPES: M_Room_Message, M_Room_Message_File, M_Room_Message_Encrypted_File BREAKS: Nothing, as .d.ts files don't affect buisness logic. In terms of lint errors: Marking "m.in_reply_to" as optional is indeed technically a "breaking change" (TypeScript may complain about „is probably undefined” in places where it didn't before), but from early "testing" (ie. looking at VSCode's errors tab), it doesn't seem like anything broke, as no file that imports any of those 3 types (Or their Outer_ counterparts) has „lit up” with errors (unless I missed something). There was one type error found in m2d/converters/event-to-message.js, at line 1009, but that seemed unrelated to types.d.ts - nevertheless, that error was also corrected in this commit, by adding proper type annotations somewhere else in the affected file. --- src/m2d/converters/event-to-message.js | 2 ++ src/types.d.ts | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/m2d/converters/event-to-message.js b/src/m2d/converters/event-to-message.js index 2add279..7eee659 100644 --- a/src/m2d/converters/event-to-message.js +++ b/src/m2d/converters/event-to-message.js @@ -471,6 +471,7 @@ async function checkWrittenMentions(content, senderMxid, roomID, guild, di) { // @ts-ignore - typescript doesn't know about indices yet content: content.slice(0, writtenMentionMatch.indices[1][0]-1) + `@everyone` + content.slice(writtenMentionMatch.indices[1][1]), ensureJoined: [], + /**@type {DiscordTypes.AllowedMentionsTypes[]}*/ // @ts-ignore - TypeScript is for whatever reason conviced that "everyone" cannot be assigned to AllowedMentionsTypes, but if you „Go to Definition”, you'll see that "everyone" is a valid enum value. allowedMentionsParse: ["everyone"] } } @@ -543,6 +544,7 @@ async function getL1L2ReplyLine(called = false) { async function eventToMessage(event, guild, channel, di) { let displayName = event.sender let avatarURL = undefined + /**@type {DiscordTypes.AllowedMentionsTypes[]}*/ // @ts-ignore - TypeScript is for whatever reason conviced that neither "users" no "roles" cannot be assigned to AllowedMentionsTypes, but if you „Go to Definition”, you'll see that both are valid enum values. const allowedMentionsParse = ["users", "roles"] /** @type {string[]} */ let messageIDsToEdit = [] diff --git a/src/types.d.ts b/src/types.d.ts index 6ee2eb1..e7ef318 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -190,11 +190,12 @@ export namespace Event { format?: "org.matrix.custom.html" formatted_body?: string, "m.relates_to"?: { - "m.in_reply_to": { + event_id?: string + is_falling_back?: bool + "m.in_reply_to"?: { event_id: string } - rel_type?: "m.replace" - event_id?: string + rel_type?: "m.replace"|"m.thread" } } @@ -210,11 +211,12 @@ export namespace Event { info?: any "page.codeberg.everypizza.msc4193.spoiler"?: boolean "m.relates_to"?: { - "m.in_reply_to": { + event_id?: string + is_falling_back?: bool + "m.in_reply_to"?: { event_id: string } - rel_type?: "m.replace" - event_id?: string + rel_type?: "m.replace"|"m.thread" } } @@ -246,11 +248,12 @@ export namespace Event { }, info?: any "m.relates_to"?: { - "m.in_reply_to": { + event_id?: string + is_falling_back?: bool + "m.in_reply_to"?: { event_id: string } - rel_type?: "m.replace" - event_id?: string + rel_type?: "m.replace"|"m.thread" } } From 8676a736204b8cdf8831aad4ca32f7ebf2f7a8be Mon Sep 17 00:00:00 2001 From: Guzio Date: Thu, 19 Feb 2026 17:53:56 +0000 Subject: [PATCH 2/2] Testing BEGINS! --- src/m2d/event-dispatcher.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/m2d/event-dispatcher.js b/src/m2d/event-dispatcher.js index 2091f7d..4385f71 100644 --- a/src/m2d/event-dispatcher.js +++ b/src/m2d/event-dispatcher.js @@ -211,6 +211,9 @@ async event => { if (utils.eventSenderIsFromDiscord(event.sender)) return const messageResponses = await sendEvent.sendEvent(event) if (!messageResponses.length) return + if (event.content["m.relates_to"]?.rel_type === "m.thread"){ + console.log("thread event spotted") + } if (event.type === "m.room.message" && event.content.msgtype === "m.text") { // @ts-ignore await matrixCommandHandler.execute(event)