Forget messages/events upon deletion (may fix #18)

This commit is contained in:
Cadence Ember 2024-01-10 15:48:13 +13:00
parent 84d791cd8a
commit 8e3b674d90
3 changed files with 6 additions and 1 deletions

View file

@ -13,10 +13,11 @@ async function deleteMessage(data) {
if (!roomID) return
const eventsToRedact = select("event_message", "event_id", {message_id: data.id}).pluck().all()
db.prepare("DELETE FROM message_channel WHERE message_id = ?").run(data.id)
db.prepare("DELETE FROM event_message WHERE message_id = ?").run(data.id)
for (const eventID of eventsToRedact) {
// Unfortunately, we can't specify a sender to do the redaction as, unless we find out that info via the audit logs
await api.redactEvent(roomID, eventID)
db.prepare("DELETE FROM event_message WHERE event_id = ?").run(eventID)
}
}

View file

@ -13,7 +13,9 @@ const utils = sync.require("../converters/utils")
*/
async function deleteMessage(event) {
const rows = from("event_message").join("message_channel", "message_id").select("channel_id", "message_id").where({event_id: event.redacts}).all()
db.prepare("DELETE FROM event_message WHERE event_id = ?").run(event.event_id)
for (const row of rows) {
db.prepare("DELETE FROM message_channel WHERE message_id = ?").run(row.message_id)
discord.snow.channel.deleteMessage(row.channel_id, row.message_id, event.content.reason)
}
}

View file

@ -96,6 +96,8 @@ async function sendEvent(event) {
}
for (const id of messagesToDelete) {
db.prepare("DELETE FROM message_channel WHERE message_id = ?").run(id)
db.prepare("DELETE FROM event_message WHERE message_id = ?").run(id)
await channelWebhook.deleteMessageWithWebhook(channelID, id, threadID)
}