2023-08-21 05:25:51 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
const assert = require("assert")
|
|
|
|
|
|
|
|
const passthrough = require("../../passthrough")
|
2023-09-18 10:51:59 +00:00
|
|
|
const {discord, sync, db, select} = passthrough
|
2023-08-21 11:31:40 +00:00
|
|
|
/** @type {import("../converters/thread-to-announcement")} */
|
|
|
|
const threadToAnnouncement = sync.require("../converters/thread-to-announcement")
|
2023-08-21 05:25:51 +00:00
|
|
|
/** @type {import("../../matrix/api")} */
|
|
|
|
const api = sync.require("../../matrix/api")
|
2024-01-20 10:45:47 +00:00
|
|
|
/** @type {import("./register-user")} */
|
|
|
|
const registerUser = sync.require("./register-user")
|
2023-08-21 05:25:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} parentRoomID
|
|
|
|
* @param {string} threadRoomID
|
|
|
|
* @param {import("discord-api-types/v10").APIThreadChannel} thread
|
|
|
|
*/
|
|
|
|
async function announceThread(parentRoomID, threadRoomID, thread) {
|
2024-01-20 10:45:47 +00:00
|
|
|
assert(thread.owner_id)
|
|
|
|
// @ts-ignore
|
|
|
|
const creatorMxid = await registerUser.ensureSimJoined({id: thread.owner_id}, parentRoomID)
|
|
|
|
const content = await threadToAnnouncement.threadToAnnouncement(parentRoomID, threadRoomID, creatorMxid, thread, {api})
|
2023-08-21 11:31:40 +00:00
|
|
|
await api.sendEvent(parentRoomID, "m.room.message", content, creatorMxid)
|
2023-08-21 05:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.announceThread = announceThread
|