From 63cc089bdb6938b3e1b195d8d4893167b722e7b7 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sat, 1 Feb 2025 23:26:24 +1300 Subject: [PATCH] Reset room topic immediately if it is cleared --- src/m2d/event-dispatcher.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/m2d/event-dispatcher.js b/src/m2d/event-dispatcher.js index ac44a19..a747a57 100644 --- a/src/m2d/event-dispatcher.js +++ b/src/m2d/event-dispatcher.js @@ -22,6 +22,8 @@ const matrixCommandHandler = sync.require("../matrix/matrix-command-handler") const utils = sync.require("./converters/utils") /** @type {import("../matrix/api")}) */ const api = sync.require("../matrix/api") +/** @type {import("../d2m/actions/create-room")} */ +const createRoom = sync.require("../d2m/actions/create-room") const {reg} = require("../matrix/read-registration") let lastReportedEvent = 0 @@ -172,7 +174,10 @@ async event => { if (event.state_key !== "") return if (utils.eventSenderIsFromDiscord(event.sender)) return const customTopic = +!!event.content.topic - db.prepare("UPDATE channel_room SET custom_topic = ? WHERE room_id = ?").run(customTopic, event.room_id) + const row = select("channel_room", ["channel_id", "custom_topic"], {room_id: event.room_id}).get() + if (!row) return + if (customTopic !== row.custom_topic) db.prepare("UPDATE channel_room SET custom_topic = ? WHERE channel_id = ?").run(customTopic, row.channel_id) + if (!customTopic) await createRoom.syncRoom(row.channel_id) // if it's cleared we should reset it to whatever's on discord })) sync.addTemporaryListener(as, "type:m.room.pinned_events", guard("m.room.pinned_events",