forked from cadence/out-of-your-element
Autocreate space if autocreating the room
This commit is contained in:
parent
e00ce22aad
commit
4f040e40d6
4 changed files with 7 additions and 9 deletions
|
@ -15,6 +15,8 @@ const api = sync.require("../../matrix/api")
|
|||
const ks = sync.require("../../matrix/kstate")
|
||||
/** @type {import("../../discord/utils")} */
|
||||
const utils = sync.require("../../discord/utils")
|
||||
/** @type {import("./create-space")} */
|
||||
const createSpace = sync.require("./create-space")
|
||||
|
||||
/**
|
||||
* There are 3 levels of room privacy:
|
||||
|
@ -93,11 +95,9 @@ function convertNameAndTopic(channel, guild, customName) {
|
|||
async function channelToKState(channel, guild, di) {
|
||||
// @ts-ignore
|
||||
const parentChannel = discord.channels.get(channel.parent_id)
|
||||
const guildRow = select("guild_space", ["space_id", "privacy_level"], {guild_id: guild.id}).get()
|
||||
assert(guildRow)
|
||||
|
||||
/** Used for membership/permission checks. */
|
||||
let guildSpaceID = guildRow.space_id
|
||||
const guildSpaceID = await createSpace.ensureSpace(guild)
|
||||
/** Used as the literal parent on Matrix, for categorisation. Will be the same as `guildSpaceID` unless it's a forum channel's thread, in which case a different space is used to group those threads. */
|
||||
let parentSpaceID = guildSpaceID
|
||||
if (parentChannel?.type === DiscordTypes.ChannelType.GuildForum) {
|
||||
|
@ -117,7 +117,8 @@ async function channelToKState(channel, guild, di) {
|
|||
avatarEventContent.url = {$url: file.guildIcon(guild)}
|
||||
}
|
||||
|
||||
const privacyLevel = guildRow.privacy_level
|
||||
const privacyLevel = select("guild_space", "privacy_level", {guild_id: guild.id}).pluck().get()
|
||||
assert(privacyLevel != null) // already ensured the space exists
|
||||
let history_visibility = PRIVACY_ENUMS.ROOM_HISTORY_VISIBILITY[privacyLevel]
|
||||
if (channel["thread_metadata"]) history_visibility = "world_readable"
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ async function _syncSpace(guild, shouldActuallySync) {
|
|||
|
||||
if (!row) {
|
||||
const autocreate = select("guild_active", "autocreate", {guild_id: guild.id}).pluck().get()
|
||||
assert.equal(autocreate, 1, `refusing to implicitly create guild ${guild.id}. set the guild_active data first before calling ensureSpace/syncSpace.`)
|
||||
assert.equal(autocreate, 1, `refusing to implicitly create a space for guild ${guild.id}. set the guild_active data first before calling ensureSpace/syncSpace.`)
|
||||
|
||||
const creation = (async () => {
|
||||
const guildKState = await guildToKState(guild, createRoom.DEFAULT_PRIVACY_LEVEL) // New spaces will have to use the default privacy level; we obviously can't look up the existing entry
|
||||
|
|
|
@ -575,7 +575,7 @@ test("message2event: voice message", async t => {
|
|||
external_url: "https://bridge.example.org/download/discordcdn/1099031887500034088/1112476845502365786/voice-message.ogg",
|
||||
filename: "voice-message.ogg",
|
||||
info: {
|
||||
duration: 3960.0000381469727,
|
||||
duration: 3960,
|
||||
mimetype: "audio/ogg",
|
||||
size: 10584,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue