From 7035e5fd432ed2a3a3d165404e9155ba5614ec16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joann=20M=C3=B5ndresku?= Date: Tue, 25 May 2021 13:15:51 +0300 Subject: [PATCH 1/3] Inline replies Discord->Matrix --- src/bot.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/bot.ts b/src/bot.ts index 0ca0b768..508c6851 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1107,6 +1107,20 @@ export class DiscordBot { formatted_body: result.formattedBody, msgtype: result.msgtype, }; + if (msg.reference) { + const storeEvent = await this.store.Get(DbEvent, {discord_id: msg.reference?.messageID}) + if (storeEvent && storeEvent.Result) + { + while(storeEvent.Next()) + { + sendContent["m.relates_to"] = { + "m.in_reply_to": { + event_id: storeEvent.MatrixId.split(";")[0] + } + }; + } + } + } if (editEventId) { sendContent.body = `* ${result.body}`; sendContent.formatted_body = `* ${result.formattedBody}`; From 86388901fa44d5d0f9d3dec8727c18cc00d613e7 Mon Sep 17 00:00:00 2001 From: mangofeet Date: Thu, 16 Feb 2023 09:15:47 -0700 Subject: [PATCH 2/3] merge m.relates_to for replies --- src/bot.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 508c6851..d6b0cc81 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1107,13 +1107,14 @@ export class DiscordBot { formatted_body: result.formattedBody, msgtype: result.msgtype, }; + let relatesTo = null; if (msg.reference) { const storeEvent = await this.store.Get(DbEvent, {discord_id: msg.reference?.messageID}) if (storeEvent && storeEvent.Result) { while(storeEvent.Next()) { - sendContent["m.relates_to"] = { + relatesTo = { "m.in_reply_to": { event_id: storeEvent.MatrixId.split(";")[0] } @@ -1130,12 +1131,13 @@ export class DiscordBot { formatted_body: result.formattedBody, msgtype: result.msgtype, }; - sendContent["m.relates_to"] = { - event_id: editEventId, - rel_type: "m.replace", - }; + if (relatesTo === null) relatesTo = {} + relatesTo.event_id = editEventId; + relatesTo.rel_type = "m.replace"; } - const trySend = async () => intent.sendEvent(room, sendContent); + if (relatesTo !== null) sendContent["m.relates_to"] = relatesTo; + + const trySend = async () => intent.sendEvent(room, sendContent); const afterSend = async (eventId) => { this.lastEventIds[room] = eventId; const evt = new DbEvent(); From 8299c626188e676723a708e49635d2c4afa26ffa Mon Sep 17 00:00:00 2001 From: mangofeet Date: Thu, 16 Feb 2023 09:20:33 -0700 Subject: [PATCH 3/3] fix typescript thing --- src/bot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index d6b0cc81..962d01ba 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1107,7 +1107,7 @@ export class DiscordBot { formatted_body: result.formattedBody, msgtype: result.msgtype, }; - let relatesTo = null; + let relatesTo: any = null; if (msg.reference) { const storeEvent = await this.store.Get(DbEvent, {discord_id: msg.reference?.messageID}) if (storeEvent && storeEvent.Result)