WIP: feature: threads'n'forums #74
1 changed files with 8 additions and 2 deletions
|
|
@ -173,8 +173,9 @@ as.router.post("/api/link", defineEventHandler(async event => {
|
|||
const row = from("channel_room").select("channel_id", "room_id").and("WHERE channel_id = ? OR room_id = ?").get(channel.id, parsedBody.matrix)
|
||||
if (row) throw createError({status: 400, message: "Bad Request", data: `Channel ID ${row.channel_id} or room ID ${parsedBody.matrix} are already bridged and cannot be reused`})
|
||||
|
||||
// Check room is part of the guild's space
|
||||
// Check room is an actual room (not space) and is part of the guild's space
|
||||
let foundRoom = false
|
||||
let foundSpace = false
|
||||
/** @type {string[]?} */
|
||||
let foundVia = null
|
||||
for await (const room of api.generateFullHierarchy(spaceID)) {
|
||||
|
|
@ -186,13 +187,18 @@ as.router.post("/api/link", defineEventHandler(async event => {
|
|||
}
|
||||
|
||||
// When finding a room during iteration, see if it was the requested room (to confirm that the room is in the space)
|
||||
if (room.room_id === parsedBody.matrix && !room.room_type) {
|
||||
if (room.room_id === parsedBody.matrix) {
|
||||
foundRoom = true
|
||||
}
|
||||
|
||||
if (foundRoom && foundVia) break
|
||||
|
||||
if (room.room_type && room.room_type === "m.space") {
|
||||
foundSpace = true
|
||||
}
|
||||
}
|
||||
if (!foundRoom) throw createError({status: 400, message: "Bad Request", data: "Matrix room needs to be part of the bridged space"})
|
||||
else if (!foundRoom) throw createError({status: 400, message: "Bad Request", data: "Matrix room cannot be of type m.space"})
|
||||
|
||||
// Check room exists and bridge is joined
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue