1
0
Fork 0

Fix reflecting generated embeds

This commit is contained in:
Cadence Ember 2024-03-19 21:58:48 +13:00
parent c615ea1e61
commit bce3d0f2c9

View file

@ -90,6 +90,7 @@ async function sendEvent(event) {
})) }))
let eventPart = 0 // 0 is primary, 1 is supporting let eventPart = 0 // 0 is primary, 1 is supporting
const pendingEdits = []
/** @type {DiscordTypes.APIMessage[]} */ /** @type {DiscordTypes.APIMessage[]} */
const messageResponses = [] const messageResponses = []
@ -121,13 +122,16 @@ async function sendEvent(event) {
*/ */
const sentEmbedsCount = message.embeds?.length || 0 const sentEmbedsCount = message.embeds?.length || 0
if (messageResponse.embeds.length > sentEmbedsCount) { if (messageResponse.embeds.length > sentEmbedsCount) {
// @ts-ignore this is a valid message edit payload // not awaiting here because requests to Matrix shouldn't block requests to Discord
editMessage.editMessage({ // not awaiting because requests to Matrix shouldn't block requests to Discord pendingEdits.push(() =>
id: messageResponse.channel_id, // @ts-ignore this is a valid message edit payload
channel_id: messageResponse.channel_id, editMessage.editMessage({
guild_id: guild.id, id: messageResponse.id,
embeds: messageResponse.embeds channel_id: messageResponse.channel_id,
}, guild, null) guild_id: guild.id,
embeds: messageResponse.embeds
}, guild, null)
)
} }
} }
@ -135,6 +139,8 @@ async function sendEvent(event) {
registerUser.ensureSimJoined(user, event.room_id) registerUser.ensureSimJoined(user, event.room_id)
} }
await Promise.all(pendingEdits.map(f => f())) // `await` will propagate any errors during editing
return messageResponses return messageResponses
} }