FixImagesQuality: fix always making GIF embeds in chat animate

This commit is contained in:
Vendicated 2026-01-09 21:00:01 +01:00
parent d4d3514dcc
commit 658ff5b216
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18

View file

@ -60,11 +60,12 @@ export default definePlugin({
);
},
getSrc(props: { src: string; mediaLayoutType: string; width: number; height: number; contentType: string; mosaicStyleAlt?: boolean; }, freeze?: boolean) {
getSrc(props: { src: string; width: number; height: number; contentType: string; mosaicStyleAlt?: boolean; trigger?: string; }, freeze?: boolean) {
if (!props?.src) return;
try {
const { contentType, height, mediaLayoutType, src, width, mosaicStyleAlt } = props;
const { contentType, height, src, width, mosaicStyleAlt, trigger } = props;
// Embed images do not have a content type set.
// It's difficult to differentiate between images and videos. but mosaicStyleAlt seems exclusive to images
const isImage = contentType?.startsWith("image/") ?? (typeof mosaicStyleAlt === "boolean");
@ -73,9 +74,15 @@ export default definePlugin({
const url = new URL(src);
if (!url.pathname.startsWith("/attachments/")) return;
url.searchParams.set("animated", String(!freeze));
if (freeze) {
url.searchParams.set("animated", "false");
if (!settings.store.originalImagesInChat && mediaLayoutType === "MOSAIC") {
if (url.pathname.endsWith(".gif"))
url.searchParams.set("format", "webp");
}
const isModal = !!trigger;
if (!settings.store.originalImagesInChat && !isModal) {
// make sure the image is not too large
const pixels = width * height;
const limit = 2000 * 1200;