Make sure CC icon/badge is shown

Also, always compress images, even if smaller than 640 pixels. For issue #680.
This commit is contained in:
N-Pex 2025-09-04 12:20:54 +02:00
parent 6fd59aa4c9
commit a318934376
3 changed files with 59 additions and 29 deletions

View file

@ -94,25 +94,24 @@ export class AttachmentManager {
// Need to resize?
const w = attachment.dimensions?.width ?? 0;
const h = attachment.dimensions?.height ?? 0;
if (w > 640 || h > 640) {
var aspect = w / h;
var newWidth = parseInt((w > h ? 640 : 640 * aspect).toFixed());
var newHeight = parseInt((w > h ? 640 / aspect : 640).toFixed());
const img = await imageResize(file, {
format: "webp",
width: newWidth,
height: newHeight,
outputType: "blob",
});
attachment.scaledFile = new File([img as BlobPart], file.name, {
type: "image/webp",
lastModified: Date.now(),
});
attachment.scaledDimensions = {
width: newWidth,
height: newHeight,
};
}
const sizeDown = (w > 640 || h > 640);
var aspect = w / h;
var newWidth = sizeDown ? parseInt((w > h ? 640 : 640 * aspect).toFixed()) : w;
var newHeight = sizeDown ? parseInt((w > h ? 640 / aspect : 640).toFixed()) : h;
const compressedImg = await imageResize(file, {
format: "webp",
width: newWidth,
height: newHeight,
outputType: "blob",
});
attachment.scaledFile = new File([compressedImg as BlobPart], file.name, {
type: "image/webp",
lastModified: Date.now(),
});
attachment.scaledDimensions = {
width: newWidth,
height: newHeight,
};
} catch (error) {
console.error("Failed to get image dimensions: " + error);
}
@ -478,7 +477,10 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
const removeAttachment = (attachment: Attachment) => {
if (sendingStatus.value == "initial") {
attachments.value = attachments.value.filter((a) => a !== attachment);
const index = attachments.value.indexOf(attachment);
if (index > -1) {
attachments.value.splice(index, 1);
}
}
};