change syncSpace input parameters to fix the test
This commit is contained in:
		
							parent
							
								
									cd195f92e0
								
							
						
					
					
						commit
						40922ff479
					
				
					 4 changed files with 23 additions and 19 deletions
				
			
		| 
						 | 
					@ -68,7 +68,7 @@ function convertNameAndTopic(channel, guild, customName) {
 | 
				
			||||||
 * @param {DiscordTypes.APIGuild} guild
 | 
					 * @param {DiscordTypes.APIGuild} guild
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
async function channelToKState(channel, guild) {
 | 
					async function channelToKState(channel, guild) {
 | 
				
			||||||
	const spaceID = await createSpace.ensureSpace(guild.id)
 | 
						const spaceID = await createSpace.ensureSpace(guild)
 | 
				
			||||||
	assert.ok(typeof spaceID === "string")
 | 
						assert.ok(typeof spaceID === "string")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const row = select("channel_room", ["nick", "custom_avatar"], "WHERE channel_id = ?").get(channel.id)
 | 
						const row = select("channel_room", ["nick", "custom_avatar"], "WHERE channel_id = ?").get(channel.id)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -74,30 +74,28 @@ async function guildToKState(guild) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @param {string} guildID
 | 
					 * @param {DiscordTypes.APIGuild} guild
 | 
				
			||||||
 * @param {boolean} shouldActuallySync false if just need to ensure nspace exists (which is a quick database check),
 | 
					 * @param {boolean} shouldActuallySync false if just need to ensure nspace exists (which is a quick database check),
 | 
				
			||||||
 *                                     true if also want to efficiently sync space name, space avatar, and child room avatars
 | 
					 *                                     true if also want to efficiently sync space name, space avatar, and child room avatars
 | 
				
			||||||
 * @returns {Promise<string>} room ID
 | 
					 * @returns {Promise<string>} room ID
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
async function _syncSpace(guildID, shouldActuallySync) {
 | 
					async function _syncSpace(guild, shouldActuallySync) {
 | 
				
			||||||
	/** @ts-ignore @type {DiscordTypes.APIGuild} */
 | 
					 | 
				
			||||||
	const guild = discord.guilds.get(guildID)
 | 
					 | 
				
			||||||
	assert.ok(guild)
 | 
						assert.ok(guild)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (inflightSpaceCreate.has(guildID)) {
 | 
						if (inflightSpaceCreate.has(guild.id)) {
 | 
				
			||||||
		await inflightSpaceCreate.get(guildID) // just waiting, and then doing a new db query afterwards, is the simplest way of doing it
 | 
							await inflightSpaceCreate.get(guild.id) // just waiting, and then doing a new db query afterwards, is the simplest way of doing it
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const spaceID = select("guild_space", "space_id", "WHERE guild_id = ?").pluck().get(guildID)
 | 
						const spaceID = select("guild_space", "space_id", "WHERE guild_id = ?").pluck().get(guild.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!spaceID) {
 | 
						if (!spaceID) {
 | 
				
			||||||
		const creation = (async () => {
 | 
							const creation = (async () => {
 | 
				
			||||||
			const guildKState = await guildToKState(guild)
 | 
								const guildKState = await guildToKState(guild)
 | 
				
			||||||
			const spaceID = await createSpace(guild, guildKState)
 | 
								const spaceID = await createSpace(guild, guildKState)
 | 
				
			||||||
			inflightSpaceCreate.delete(guildID)
 | 
								inflightSpaceCreate.delete(guild.id)
 | 
				
			||||||
			return spaceID
 | 
								return spaceID
 | 
				
			||||||
		})()
 | 
							})()
 | 
				
			||||||
		inflightSpaceCreate.set(guildID, creation)
 | 
							inflightSpaceCreate.set(guild.id, creation)
 | 
				
			||||||
		return creation // Naturally, the newly created space is already up to date, so we can always skip syncing here.
 | 
							return creation // Naturally, the newly created space is already up to date, so we can always skip syncing here.
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -136,14 +134,20 @@ async function _syncSpace(guildID, shouldActuallySync) {
 | 
				
			||||||
	return spaceID
 | 
						return spaceID
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Ensures the space exists. If it doesn't, creates the space with an accurate initial state. */
 | 
					/**
 | 
				
			||||||
function ensureSpace(guildID) {
 | 
					 * Ensures the space exists. If it doesn't, creates the space with an accurate initial state.
 | 
				
			||||||
	return _syncSpace(guildID, false)
 | 
					 * @param {DiscordTypes.APIGuild} guild
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function ensureSpace(guild) {
 | 
				
			||||||
 | 
						return _syncSpace(guild, false)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Actually syncs. Efficiently updates the space name, space avatar, and child room avatars. */
 | 
					/**
 | 
				
			||||||
function syncSpace(guildID) {
 | 
					 * Actually syncs. Efficiently updates the space name, space avatar, and child room avatars.
 | 
				
			||||||
	return _syncSpace(guildID, true)
 | 
					 * @param {DiscordTypes.APIGuild} guild
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function syncSpace(guild) {
 | 
				
			||||||
 | 
						return _syncSpace(guild, true)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -140,7 +140,7 @@ module.exports = {
 | 
				
			||||||
	async onGuildUpdate(client, guild) {
 | 
						async onGuildUpdate(client, guild) {
 | 
				
			||||||
		const spaceID = select("guild_space", "space_id", "WHERE guild_id = ?").pluck().get(guild.id)
 | 
							const spaceID = select("guild_space", "space_id", "WHERE guild_id = ?").pluck().get(guild.id)
 | 
				
			||||||
		if (!spaceID) return
 | 
							if (!spaceID) return
 | 
				
			||||||
		await createSpace.syncSpace(guild.id)
 | 
							await createSpace.syncSpace(guild)
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,7 +66,7 @@ async function migrateGuild(guild) {
 | 
				
			||||||
	console.log(`START MIGRATION of ${guild.name} (${guild.id})`)
 | 
						console.log(`START MIGRATION of ${guild.name} (${guild.id})`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Step 1: Create a new space for the guild (createSpace)
 | 
						// Step 1: Create a new space for the guild (createSpace)
 | 
				
			||||||
	const spaceID = await createSpace.syncSpace(guild.id)
 | 
						const spaceID = await createSpace.syncSpace(guild)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let oldRooms = oldDB.prepare("SELECT matrix_id, discord_guild, discord_channel FROM room_entries INNER JOIN remote_room_data ON remote_id = room_id WHERE discord_guild = ?").all(guild.id)
 | 
						let oldRooms = oldDB.prepare("SELECT matrix_id, discord_guild, discord_channel FROM room_entries INNER JOIN remote_room_data ON remote_id = room_id WHERE discord_guild = ?").all(guild.id)
 | 
				
			||||||
	const migrated = db.prepare("SELECT discord_channel FROM migration WHERE migrated = 1").pluck().all()
 | 
						const migrated = db.prepare("SELECT discord_channel FROM migration WHERE migrated = 1").pluck().all()
 | 
				
			||||||
| 
						 | 
					@ -132,6 +132,6 @@ async function migrateGuild(guild) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Step 5: Call syncSpace to make sure everything is up to date
 | 
						// Step 5: Call syncSpace to make sure everything is up to date
 | 
				
			||||||
	await createSpace.syncSpace(guild.id)
 | 
						await createSpace.syncSpace(guild)
 | 
				
			||||||
	console.log(`Finished migrating ${guild.name} to Out Of Your Element`)
 | 
						console.log(`Finished migrating ${guild.name} to Out Of Your Element`)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue