2023-08-17 13:22:14 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
const passthrough = require("../../passthrough")
|
|
|
|
const { sync, db } = passthrough
|
|
|
|
/** @type {import("../../matrix/api")} */
|
|
|
|
const api = sync.require("../../matrix/api")
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {import("discord-api-types/v10").GatewayMessageDeleteDispatchData} data
|
|
|
|
*/
|
|
|
|
async function deleteMessage(data) {
|
|
|
|
/** @type {string?} */
|
2023-08-18 04:58:46 +00:00
|
|
|
const roomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").pluck().get(data.channel_id)
|
2023-08-17 13:22:14 +00:00
|
|
|
if (!roomID) return
|
|
|
|
|
|
|
|
/** @type {string[]} */
|
|
|
|
const eventsToRedact = db.prepare("SELECT event_id FROM event_message WHERE message_id = ?").pluck().all(data.id)
|
|
|
|
|
|
|
|
for (const eventID of eventsToRedact) {
|
2023-09-06 00:31:38 +00:00
|
|
|
// Unfortunately, we can't specify a sender to do the redaction as, unless we find out that info via the audit logs
|
2023-08-17 13:22:14 +00:00
|
|
|
await api.redactEvent(roomID, eventID)
|
2023-08-28 05:32:55 +00:00
|
|
|
db.prepare("DELETE FROM event_message WHERE event_id = ?").run(eventID)
|
2023-08-17 13:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.deleteMessage = deleteMessage
|