feat(message): prioritize thumbnail loading with fallback to original image

When viewing messages, thumbnails are loaded first, if loading fails,
the original image is loaded as a fallback.
This commit is contained in:
纳西妲 · Nahida 2025-08-17 13:40:41 +08:00
parent abd713d693
commit 0a659e174c
3 changed files with 38 additions and 6 deletions

View file

@ -184,13 +184,32 @@ export function RenderMessageContent({
}
if (msgType === MsgType.Image) {
const content: IImageContent = getContent();
const width = content?.info?.w;
const height = content?.info?.h;
let thumbnail: {
imgWidth: number,
imgHeight: number,
resizeMethod: string
} | undefined;
if (width && height) {
const scale = (width > height ? width : height) / 800;
if (width > 800 || height > 800 && scale > 1) {
thumbnail = {
imgWidth: width / scale,
imgHeight: height / scale,
resizeMethod: "scale",
}
}
}
return (
<>
<MImage
content={getContent()}
content={content}
renderImageContent={(props) => (
<ImageContent
{...props}
{...thumbnail}
autoPlay={mediaAutoLoad}
renderImage={(p) => <Image {...p} loading="lazy" />}
renderViewer={(p) => <ImageViewer {...p} />}