Autocreate space if autocreating the room
This commit is contained in:
parent
e00ce22aad
commit
4f040e40d6
4 changed files with 7 additions and 9 deletions
|
@ -61,8 +61,6 @@ So there will be 3 states of whether a guild is self-service or not. At first, i
|
||||||
|
|
||||||
Pressing buttons on web or using the /invite command on a guild will insert a row into guild_active, allowing it to be bridged.
|
Pressing buttons on web or using the /invite command on a guild will insert a row into guild_active, allowing it to be bridged.
|
||||||
|
|
||||||
One more thing. Before v3, when a Matrix room was autocreated it would autocreate the space as well, if it needed to. But now, since nothing will be created until the user takes an action, the guild will always be created directly in response to a request. So room creation can now trust that the guild exists already.
|
|
||||||
|
|
||||||
So here's all the technical changes needed to support self-service in v3:
|
So here's all the technical changes needed to support self-service in v3:
|
||||||
|
|
||||||
- New guild_active table showing whether, and how, a guild is bridged.
|
- New guild_active table showing whether, and how, a guild is bridged.
|
||||||
|
@ -70,5 +68,4 @@ So here's all the technical changes needed to support self-service in v3:
|
||||||
- When bot is added through "easy mode" web button, REPLACE INTO state 1 and ensureSpace.
|
- When bot is added through "easy mode" web button, REPLACE INTO state 1 and ensureSpace.
|
||||||
- When bot is added through "self-service" web button, REPLACE INTO state 0.
|
- When bot is added through "self-service" web button, REPLACE INTO state 0.
|
||||||
- Event dispatcher will only ensureRoom if the guild_active state is 1.
|
- Event dispatcher will only ensureRoom if the guild_active state is 1.
|
||||||
- createRoom can trust that the space exists because we check that in a calling function.
|
|
||||||
- createRoom will only create other dependencies if the guild is autocreate.
|
- createRoom will only create other dependencies if the guild is autocreate.
|
||||||
|
|
|
@ -15,6 +15,8 @@ const api = sync.require("../../matrix/api")
|
||||||
const ks = sync.require("../../matrix/kstate")
|
const ks = sync.require("../../matrix/kstate")
|
||||||
/** @type {import("../../discord/utils")} */
|
/** @type {import("../../discord/utils")} */
|
||||||
const utils = sync.require("../../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:
|
* There are 3 levels of room privacy:
|
||||||
|
@ -93,11 +95,9 @@ function convertNameAndTopic(channel, guild, customName) {
|
||||||
async function channelToKState(channel, guild, di) {
|
async function channelToKState(channel, guild, di) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const parentChannel = discord.channels.get(channel.parent_id)
|
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. */
|
/** 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. */
|
/** 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
|
let parentSpaceID = guildSpaceID
|
||||||
if (parentChannel?.type === DiscordTypes.ChannelType.GuildForum) {
|
if (parentChannel?.type === DiscordTypes.ChannelType.GuildForum) {
|
||||||
|
@ -117,7 +117,8 @@ async function channelToKState(channel, guild, di) {
|
||||||
avatarEventContent.url = {$url: file.guildIcon(guild)}
|
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]
|
let history_visibility = PRIVACY_ENUMS.ROOM_HISTORY_VISIBILITY[privacyLevel]
|
||||||
if (channel["thread_metadata"]) history_visibility = "world_readable"
|
if (channel["thread_metadata"]) history_visibility = "world_readable"
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ async function _syncSpace(guild, shouldActuallySync) {
|
||||||
|
|
||||||
if (!row) {
|
if (!row) {
|
||||||
const autocreate = select("guild_active", "autocreate", {guild_id: guild.id}).pluck().get()
|
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 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
|
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",
|
external_url: "https://bridge.example.org/download/discordcdn/1099031887500034088/1112476845502365786/voice-message.ogg",
|
||||||
filename: "voice-message.ogg",
|
filename: "voice-message.ogg",
|
||||||
info: {
|
info: {
|
||||||
duration: 3960.0000381469727,
|
duration: 3960,
|
||||||
mimetype: "audio/ogg",
|
mimetype: "audio/ogg",
|
||||||
size: 10584,
|
size: 10584,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue