forked from cadence/out-of-your-element
Don't overwrite space parent of self-service rooms
This commit is contained in:
parent
50a047249b
commit
639912fee3
1 changed files with 21 additions and 4 deletions
|
@ -54,6 +54,7 @@ function convertNameAndTopic(channel, guild, customName) {
|
||||||
let channelPrefix =
|
let channelPrefix =
|
||||||
( parentChannel?.type === DiscordTypes.ChannelType.GuildForum ? ""
|
( parentChannel?.type === DiscordTypes.ChannelType.GuildForum ? ""
|
||||||
: channel.type === DiscordTypes.ChannelType.PublicThread ? "[⛓️] "
|
: channel.type === DiscordTypes.ChannelType.PublicThread ? "[⛓️] "
|
||||||
|
: channel.type === DiscordTypes.ChannelType.AnnouncementThread ? "[⛓️] "
|
||||||
: channel.type === DiscordTypes.ChannelType.PrivateThread ? "[🔒⛓️] "
|
: channel.type === DiscordTypes.ChannelType.PrivateThread ? "[🔒⛓️] "
|
||||||
: channel.type === DiscordTypes.ChannelType.GuildVoice ? "[🔊] "
|
: channel.type === DiscordTypes.ChannelType.GuildVoice ? "[🔊] "
|
||||||
: "")
|
: "")
|
||||||
|
@ -176,8 +177,16 @@ async function channelToKState(channel, guild, di) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't overwrite room topic if the topic has been customised
|
||||||
if (hasCustomTopic) delete channelKState["m.room.topic/"]
|
if (hasCustomTopic) delete channelKState["m.room.topic/"]
|
||||||
|
|
||||||
|
// Don't add a space parent if it's self service
|
||||||
|
// (The person setting up self-service has already put it in their preferred space to be able to get this far.)
|
||||||
|
const autocreate = select("guild_active", "autocreate", {guild_id: guild.id}).pluck().get()
|
||||||
|
if (autocreate === 0 && ![DiscordTypes.ChannelType.PrivateThread, DiscordTypes.ChannelType.PublicThread, DiscordTypes.ChannelType.AnnouncementThread].includes(channel.type)) {
|
||||||
|
delete channelKState[`m.space.parent/${parentSpaceID}`]
|
||||||
|
}
|
||||||
|
|
||||||
return {spaceID: parentSpaceID, privacyLevel, channelKState}
|
return {spaceID: parentSpaceID, privacyLevel, channelKState}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,8 +231,8 @@ async function createRoom(channel, guild, spaceID, kstate, privacyLevel) {
|
||||||
return roomID
|
return roomID
|
||||||
})
|
})
|
||||||
|
|
||||||
// Put the newly created child into the space, no need to await this
|
// Put the newly created child into the space
|
||||||
_syncSpaceMember(channel, spaceID, roomID)
|
await _syncSpaceMember(channel, spaceID, roomID, guild.id)
|
||||||
|
|
||||||
return roomID
|
return roomID
|
||||||
}
|
}
|
||||||
|
@ -392,7 +401,7 @@ async function _syncRoom(channelID, shouldActuallySync) {
|
||||||
db.prepare("UPDATE channel_room SET name = ? WHERE room_id = ?").run(channel.name, roomID)
|
db.prepare("UPDATE channel_room SET name = ? WHERE room_id = ?").run(channel.name, roomID)
|
||||||
|
|
||||||
// sync room as space member
|
// sync room as space member
|
||||||
const spaceApply = _syncSpaceMember(channel, spaceID, roomID)
|
const spaceApply = _syncSpaceMember(channel, spaceID, roomID, guild.id)
|
||||||
await Promise.all([roomApply, spaceApply])
|
await Promise.all([roomApply, spaceApply])
|
||||||
|
|
||||||
return roomID
|
return roomID
|
||||||
|
@ -504,9 +513,17 @@ async function unbridgeDeletedChannel(channel, guildID) {
|
||||||
* @param {DiscordTypes.APIGuildTextChannel} channel
|
* @param {DiscordTypes.APIGuildTextChannel} channel
|
||||||
* @param {string} spaceID
|
* @param {string} spaceID
|
||||||
* @param {string} roomID
|
* @param {string} roomID
|
||||||
|
* @param {string} guild_id
|
||||||
* @returns {Promise<string[]>}
|
* @returns {Promise<string[]>}
|
||||||
*/
|
*/
|
||||||
async function _syncSpaceMember(channel, spaceID, roomID) {
|
async function _syncSpaceMember(channel, spaceID, roomID, guild_id) {
|
||||||
|
// If space is self-service then only permit changes to space parenting for threads
|
||||||
|
// (The person setting up self-service has already put it in their preferred space to be able to get this far.)
|
||||||
|
const autocreate = select("guild_active", "autocreate", {guild_id}).pluck().get()
|
||||||
|
if (autocreate === 0 && ![DiscordTypes.ChannelType.PrivateThread, DiscordTypes.ChannelType.PublicThread, DiscordTypes.ChannelType.AnnouncementThread].includes(channel.type)) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
const spaceKState = await ks.roomToKState(spaceID)
|
const spaceKState = await ks.roomToKState(spaceID)
|
||||||
let spaceEventContent = {}
|
let spaceEventContent = {}
|
||||||
if (
|
if (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue