Better message when remote emojis unavailable

This commit is contained in:
Cadence Ember 2025-10-31 16:22:32 +13:00
parent d4f4664c25
commit 255e166e8c
2 changed files with 9 additions and 1 deletions

View file

@ -7,6 +7,8 @@ const {sync} = require("../../passthrough")
const emojiSheetConverter = sync.require("../converters/emoji-sheet")
/** @type {import("../../matrix/api")} */
const api = sync.require("../../matrix/api")
/** @type {import("../../matrix/mreq")} */
const mreq = sync.require("../../matrix/mreq")
/**
* Downloads the emoji from the web and converts to uncompressed PNG data.
@ -19,6 +21,10 @@ async function getAndConvertEmoji(mxc) {
// If we were using connection pooling, we would be forced to download the entire GIF.
// So we set no agent to ensure we are not connection pooling.
const res = await api.getMedia(mxc, {signal: abortController.signal})
if (res.status !== 200) {
const root = await res.json()
throw new mreq.MatrixServerError(root, {mxc})
}
const readable = stream.Readable.fromWeb(res.body)
return emojiSheetConverter.convertImageStream(readable, () => {
abortController.abort()

View file

@ -11,6 +11,7 @@ const entities = require("entities")
const passthrough = require("../../passthrough")
const {sync, db, discord, select, from} = passthrough
const {reg} = require("../../matrix/read-registration")
/** @type {import("../converters/utils")} */
const mxUtils = sync.require("../converters/utils")
/** @type {import("../../discord/utils")} */
@ -238,7 +239,8 @@ function convertEmoji(mxcUrl, nameForGuess, allowSpriteSheetIndicator, allowLink
if (!found) row = null
}
// Or, if we don't have an emoji right now, we search for the name instead.
if (!row && nameForGuess) {
const isLocalMxc = mxcUrl?.match(/^mxc:\/\/([^/]+)/)?.[1] === reg.ooye.server_name
if (!row && nameForGuess && isLocalMxc) {
const nameForGuessLower = nameForGuess.toLowerCase()
for (const guild of discord.guilds.values()) {
/** @type {{name: string, id: string, animated: number}[]} */