2024-09-14 12:55:54 +00:00
|
|
|
#!/usr/bin/env node
|
2023-07-28 05:05:13 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
const sqlite = require("better-sqlite3")
|
|
|
|
const HeatSync = require("heatsync")
|
|
|
|
|
2024-09-14 12:55:54 +00:00
|
|
|
const passthrough = require("../src/passthrough")
|
2024-09-14 13:09:47 +00:00
|
|
|
const db = new sqlite("ooye.db")
|
2023-07-28 05:05:13 +00:00
|
|
|
|
|
|
|
const sync = new HeatSync({watchFS: false})
|
|
|
|
|
|
|
|
Object.assign(passthrough, {sync, db})
|
|
|
|
|
2024-09-14 12:55:54 +00:00
|
|
|
const api = require("../src/matrix/api")
|
2023-07-28 05:05:13 +00:00
|
|
|
|
|
|
|
/** @type {{event_id: string, room_id: string, event_type: string}[]} */ // @ts-ignore
|
2023-08-28 05:32:55 +00:00
|
|
|
const rows = db.prepare("SELECT event_id, room_id, event_type FROM event_message INNER JOIN message_channel USING (message_id) INNER JOIN channel_room USING (channel_id)").all()
|
2023-07-28 05:05:13 +00:00
|
|
|
|
|
|
|
const preparedUpdate = db.prepare("UPDATE event_message SET event_type = ?, event_subtype = ? WHERE event_id = ?")
|
|
|
|
|
|
|
|
;(async () => {
|
2023-08-21 09:04:41 +00:00
|
|
|
for (const row of rows) {
|
|
|
|
if (row.event_type == null) {
|
|
|
|
const event = await api.getEvent(row.room_id, row.event_id)
|
|
|
|
const type = event.type
|
|
|
|
const subtype = event.content.msgtype || null
|
|
|
|
preparedUpdate.run(type, subtype, row.event_id)
|
|
|
|
console.log(`Updated ${row.event_id} -> ${type} + ${subtype}`)
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 05:05:13 +00:00
|
|
|
})()
|