forcing space sync will unbridge deleted channels
This commit is contained in:
parent
0237d45c60
commit
0acf59bf48
2 changed files with 12 additions and 4 deletions
|
@ -303,9 +303,13 @@ async function _unbridgeRoom(channelID) {
|
||||||
/** @ts-ignore @type {DiscordTypes.APIGuildChannel} */
|
/** @ts-ignore @type {DiscordTypes.APIGuildChannel} */
|
||||||
const channel = discord.channels.get(channelID)
|
const channel = discord.channels.get(channelID)
|
||||||
assert.ok(channel)
|
assert.ok(channel)
|
||||||
|
return unbridgeDeletedChannel(channel.id, channel.guild_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unbridgeDeletedChannel(channelID, guildID) {
|
||||||
const roomID = db.prepare("SELECT room_id from channel_room WHERE channel_id = ?").pluck().get(channelID)
|
const roomID = db.prepare("SELECT room_id from channel_room WHERE channel_id = ?").pluck().get(channelID)
|
||||||
assert.ok(roomID)
|
assert.ok(roomID)
|
||||||
const spaceID = db.prepare("SELECT space_id FROM guild_space WHERE guild_id = ?").pluck().get(channel.guild_id)
|
const spaceID = db.prepare("SELECT space_id FROM guild_space WHERE guild_id = ?").pluck().get(guildID)
|
||||||
assert.ok(spaceID)
|
assert.ok(spaceID)
|
||||||
|
|
||||||
// remove room from being a space member
|
// remove room from being a space member
|
||||||
|
@ -313,7 +317,7 @@ async function _unbridgeRoom(channelID) {
|
||||||
await api.sendState(spaceID, "m.space.child", roomID, {})
|
await api.sendState(spaceID, "m.space.child", roomID, {})
|
||||||
|
|
||||||
// remove declaration that the room is bridged
|
// remove declaration that the room is bridged
|
||||||
await api.sendState(roomID, "uk.half-shot.bridge", `moe.cadence.ooye://discord/${channel.guild_id}/${channel.id}`, {})
|
await api.sendState(roomID, "uk.half-shot.bridge", `moe.cadence.ooye://discord/${guildID}/${channelID}`, {})
|
||||||
|
|
||||||
// send a notification in the room
|
// send a notification in the room
|
||||||
await api.sendEvent(roomID, "m.room.message", {
|
await api.sendEvent(roomID, "m.room.message", {
|
||||||
|
@ -329,7 +333,6 @@ async function _unbridgeRoom(channelID) {
|
||||||
assert.equal(changes, 1)
|
assert.equal(changes, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async because it gets all space state from the homeserver, then if necessary sends one state event back.
|
* Async because it gets all space state from the homeserver, then if necessary sends one state event back.
|
||||||
* @param {DiscordTypes.APIGuildTextChannel} channel
|
* @param {DiscordTypes.APIGuildTextChannel} channel
|
||||||
|
@ -377,3 +380,4 @@ module.exports.applyKStateDiffToRoom = applyKStateDiffToRoom
|
||||||
module.exports.postApplyPowerLevels = postApplyPowerLevels
|
module.exports.postApplyPowerLevels = postApplyPowerLevels
|
||||||
module.exports._convertNameAndTopic = convertNameAndTopic
|
module.exports._convertNameAndTopic = convertNameAndTopic
|
||||||
module.exports._unbridgeRoom = _unbridgeRoom
|
module.exports._unbridgeRoom = _unbridgeRoom
|
||||||
|
module.exports.unbridgeDeletedChannel = unbridgeDeletedChannel
|
||||||
|
|
|
@ -145,7 +145,11 @@ async function syncSpaceFully(guildID) {
|
||||||
for (const roomID of childRooms) {
|
for (const roomID of childRooms) {
|
||||||
const channelID = db.prepare("SELECT channel_id FROM channel_room WHERE room_id = ?").pluck().get(roomID)
|
const channelID = db.prepare("SELECT channel_id FROM channel_room WHERE room_id = ?").pluck().get(roomID)
|
||||||
if (!channelID) continue
|
if (!channelID) continue
|
||||||
|
if (discord.channels.has(channelID)) {
|
||||||
await createRoom.syncRoom(channelID)
|
await createRoom.syncRoom(channelID)
|
||||||
|
} else {
|
||||||
|
await createRoom.unbridgeDeletedChannel(channelID, guildID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return spaceID
|
return spaceID
|
||||||
|
|
Loading…
Reference in a new issue