category subspaces #113
1 changed files with 16 additions and 0 deletions
update parent_space_id column of a manually linked subspace's children
commit
73d1c68623
|
|
@ -184,6 +184,8 @@ as.router.post("/api/link", defineEventHandler(async event => {
|
|||
let foundVia = null
|
||||
/** @type {string | null} */
|
||||
let foundParentSpaceID = null
|
||||
/** @type {string[]} */
|
||||
let foundCategoryChildrenRoomIDs = []
|
||||
for await (const room of api.generateFullHierarchy(spaceID)) {
|
||||
// When finding a space during iteration, look at space's children state, because we need a `via` to join the room (when we find it later)
|
||||
for (const state of room.children_state) {
|
||||
|
|
@ -196,6 +198,14 @@ 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 && (!channelType && !room.room_type || channelType === "category" && room.room_type === "m.space")) {
|
||||
foundRoom = true
|
||||
|
||||
if (channelType === "category") {
|
||||
for (const state of room.children_state) {
|
||||
if (state.type === "m.space.child" && state.content.via) {
|
||||
foundCategoryChildrenRoomIDs.push(state.state_key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundRoom && foundVia) break
|
||||
|
|
@ -234,6 +244,12 @@ as.router.post("/api/link", defineEventHandler(async event => {
|
|||
// Sync room data and space child
|
||||
await createRoom.syncRoom(parsedBody.discord)
|
||||
|
||||
if (channelType === "category") {
|
||||
for (const childRoomID of foundCategoryChildrenRoomIDs) {
|
||||
db.prepare("UPDATE channel_room SET parent_space_id = ? WHERE room_id = ?").run(parsedBody.matrix, childRoomID)
|
||||
}
|
||||
}
|
||||
|
||||
// Send a notification in the room
|
||||
if (channel.type === DiscordTypes.ChannelType.GuildText) {
|
||||
await api.sendEvent(parsedBody.matrix, "m.room.message", {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue