feat/add-unlink-space-button #63

Manually merged
cadence merged 12 commits from Elliu/out-of-your-element:feat/add-unlink-space-button into main 2026-02-13 06:32:34 +00:00
2 changed files with 15 additions and 6 deletions
Showing only changes of commit bd9fd5cd3c - Show all commits

View file

@ -459,12 +459,12 @@ async function unbridgeDeletedChannel(channel, guildID) {
const webhook = select("webhook", ["webhook_id", "webhook_token"], {channel_id: channel.id}).get()
if (webhook) {
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
await 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 member_cache WHERE room_id = ?").run(roomID)
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

View file

@ -278,6 +278,15 @@ as.router.post("/api/unlink-space", defineEventHandler(async event => {
for (const channel of linkedChannels) {
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:

Also, this line causes issue when running the test.
I couldn't add the snow member like createRoom or api in the test to add the function / member definition because it wasn't defined in the type, not really sure what's the best way to fix it

Also, this line causes issue when running the test. I couldn't add the `snow` member like `createRoom` or `api` in the test to add the function / member definition because it wasn't defined in the type, not really sure what's the best way to fix it

I just pushed a commit which adds the getSnow function to that file. This will give you the real SnowTransfer if it's running properly, whereas if you're in tests, you can add substitute functions to be called instead. This is the same as how getAPI and getCreateRoom work. If you need an example of how to use this in test files, check download-discord.test.js.

I just pushed a commit which adds the `getSnow` function to that file. This will give you the real SnowTransfer if it's running properly, whereas if you're in tests, you can add substitute functions to be called instead. This is the same as how `getAPI` and `getCreateRoom` work. If you need an example of how to use this in test files, check `download-discord.test.js`.
// 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()
@ -288,10 +297,10 @@ as.router.post("/api/unlink-space", defineEventHandler(async event => {
await api.setUserPower(spaceID, me, 0)
await api.leaveRoom(spaceID)
await 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_space WHERE guild_id=? AND space_id=?").run(guild_id, spaceID)
db.prepare("DELETE FROM guild_active WHERE guild_id=?").run(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", "/")
return null