matrix-search

A small nodejs script which indexes a whole matrix account into meilisearch and has a pdf rendering UI
git clone git://archive.git.mtrnord.blog/MTRNord/matrix-search.git
Log | Files | Refs | README | LICENSE

commit 00aa68c2cd47e0a2e3e9409b3af7315da780121f
parent e6c26b203d0b9a65d403ef266d8adffb2c115741
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sun,  9 Jun 2024 18:24:43 +0200

Remove original events if it was edited

Diffstat:
Msrc/bot.ts | 9++++++++-
Msrc/indexer.ts | 4++++
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/bot.ts b/src/bot.ts @@ -75,7 +75,7 @@ async function backfill(client: MatrixClient, indexer: Indexer) { editedEvents.push(event.content["m.relates_to"].event_id); } } - + if (await client.crypto.isRoomEncrypted(room)) { await client.crypto.onRoomEvent(room, event); } else { @@ -106,6 +106,13 @@ async function run() { client.on("room.message", async (roomId, event) => { if (event["content"]["msgtype"] === "m.text") { console.info(`Received message in room ${roomId}`); + // TODO: Remove the original event if we have an edit + if (event.content["m.relates_to"]) { + if (event.content["m.relates_to"].rel_type === "m.replace") { + console.info(`Removing original event ${event.content["m.relates_to"].event_id}`); + await indexer.delete(event.content["m.relates_to"].event_id.replace("$", "").replace(":", "_").replace(".", "_")); + } + } const res = await indexer.insert({ id: event["event_id"].replace("$", "").replace(":", "_").replace(".", "_"), sender: event["sender"], content: cleanContent(event["content"]), room_id: roomId }); console.info(`Indexed message:`, res); diff --git a/src/indexer.ts b/src/indexer.ts @@ -61,4 +61,8 @@ export default class Indexer { return { hits: results, estimatedTotalHits: results.length }; } + + public async delete(event_id: string) { + return await this.textIndex.deleteDocument(event_id); + } } \ No newline at end of file