feat/add-unlink-space-button #63
2 changed files with 15 additions and 6 deletions
|
|
@ -459,12 +459,12 @@ async function unbridgeDeletedChannel(channel, guildID) {
|
||||||
const webhook = select("webhook", ["webhook_id", "webhook_token"], {channel_id: channel.id}).get()
|
const webhook = select("webhook", ["webhook_id", "webhook_token"], {channel_id: channel.id}).get()
|
||||||
if (webhook) {
|
if (webhook) {
|
||||||
await discord.snow.webhook.deleteWebhook(webhook.webhook_id, webhook.webhook_token)
|
await discord.snow.webhook.deleteWebhook(webhook.webhook_id, webhook.webhook_token)
|
||||||
await db.prepare("DELETE FROM webhook WHERE channel_id = ?").run(channel.id)
|
db.prepare("DELETE FROM webhook WHERE channel_id = ?").run(channel.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete room from database
|
// delete room from database
|
||||||
await db.prepare("DELETE FROM member_cache WHERE room_id = ?").run(roomID)
|
db.prepare("DELETE FROM member_cache WHERE room_id = ?").run(roomID)
|
||||||
await db.prepare("DELETE FROM channel_room WHERE room_id = ? AND channel_id = ?").run(roomID, channel.id) // cascades to most other tables, like messages
|
db.prepare("DELETE FROM channel_room WHERE room_id = ? AND channel_id = ?").run(roomID, channel.id) // cascades to most other tables, like messages
|
||||||
|
|
||||||
if (!botInRoom) return
|
if (!botInRoom) return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,15 @@ as.router.post("/api/unlink-space", defineEventHandler(async event => {
|
||||||
|
|
||||||
for (const channel of linkedChannels) {
|
for (const channel of linkedChannels) {
|
||||||
await doRoomUnlink(event, channel.channel_id, guild_id)
|
await doRoomUnlink(event, channel.channel_id, guild_id)
|
||||||
|
|
||||||
|
// FIXME: probably fix the underlying issue instead:
|
||||||
|
// If not waiting for ~1s, then the room is half unbridged:
|
||||||
|
// the resources in the room is not properly cleaned up, meaning that the sim users
|
||||||
|
// and the bridge user are not power demoted nor leave the room
|
||||||
|
// The entry from the channel_room table is not deleted
|
||||||
|
// After that, writing in the discord channel does nothing,
|
||||||
|
// and writing in the matrix channel spawns an error for not finding guild_id
|
||||||
|
await new Promise(r => setTimeout(r, 5000));
|
||||||
}
|
}
|
||||||
|
|
||||||
const remainingLinkedChannels = select("channel_room", ["channel_id", "room_id", "name", "nick"], {guild_id: guild_id}).all()
|
const remainingLinkedChannels = select("channel_room", ["channel_id", "room_id", "name", "nick"], {guild_id: guild_id}).all()
|
||||||
|
|
@ -288,10 +297,10 @@ as.router.post("/api/unlink-space", defineEventHandler(async event => {
|
||||||
await api.setUserPower(spaceID, me, 0)
|
await api.setUserPower(spaceID, me, 0)
|
||||||
await api.leaveRoom(spaceID)
|
await api.leaveRoom(spaceID)
|
||||||
|
|
||||||
await db.prepare("DELETE FROM guild_space WHERE guild_id=? AND space_id=?").run(guild_id, spaceID)
|
db.prepare("DELETE FROM guild_space WHERE guild_id=? AND space_id=?").run(guild_id, spaceID)
|
||||||
await db.prepare("DELETE FROM guild_active WHERE guild_id=?").run(guild_id)
|
db.prepare("DELETE FROM guild_active WHERE guild_id=?").run(guild_id)
|
||||||
await snow.user.leaveGuild(guild_id)
|
await snow.user.leaveGuild(guild_id)
|
||||||
await db.prepare("DELETE FROM invite WHERE room_id=?").run(spaceID)
|
db.prepare("DELETE FROM invite WHERE room_id=?").run(spaceID)
|
||||||
|
|
||||||
setResponseHeader(event, "HX-Redirect", "/")
|
setResponseHeader(event, "HX-Redirect", "/")
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue