From 002666d2731109d18a8aabebe47f594cb63172cb Mon Sep 17 00:00:00 2001 From: N-Pex Date: Thu, 23 Oct 2025 11:35:52 +0200 Subject: [PATCH] Defaults for original/compressed media Issue #697. --- src/models/attachmentManager.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/models/attachmentManager.ts b/src/models/attachmentManager.ts index dda4fcf..6ad6f32 100644 --- a/src/models/attachmentManager.ts +++ b/src/models/attachmentManager.ts @@ -5,6 +5,7 @@ import { EventAttachmentUrlType, KeanuEvent, KeanuEventExtension, + KeanuRoom, } from "./eventAttachment"; import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; import { Counter, ModeOfOperation } from "aes-js"; @@ -48,11 +49,11 @@ export class AttachmentManager { .catch(() => {}); } - public createUpload(room: Room) { + public createUpload(room: KeanuRoom) { return createUploadBatch(this, room); } - public createAttachment(file: File, room: Room): Attachment { + public createAttachment(file: File, room: KeanuRoom): Attachment { let a: Attachment = { status: "loading", file: file, @@ -73,7 +74,7 @@ export class AttachmentManager { return ra; } - private async prepareUpload(attachment: Attachment, room: Room): Promise { + private async prepareUpload(attachment: Attachment, room: KeanuRoom): Promise { const file = attachment.file; if (file.type.startsWith("image/")) { let url = URL.createObjectURL(file); @@ -125,17 +126,26 @@ export class AttachmentManager { const isDirectRoom = (room: Room) => { // TODO - Use the is_direct accountData flag (m.direct). WE (as the client) // apprently need to set this... - if (room && room.getJoinRule() == "invite" && room.getMembers().length == 2) { + if (room && room.getJoinRule() == "invite" && room.getInvitedAndJoinedMemberCount() == 2) { return true; } return false; }; - attachment.useCompressed = - attachment.compressedFile !== undefined && - (attachment.proof === undefined || - !isDirectRoom(room) || - attachment.proof.integrity === undefined || - attachment.proof.integrity.c2pa === undefined); + const isChannel = room.displayType == "im.keanu.room_type_channel"; + const isFileDrop = room.displayType == "im.keanu.room_type_file"; + + let useOriginal = false; + if (isChannel) { + useOriginal = false; + } else if (isFileDrop) { + useOriginal = true; + } else { + if (isDirectRoom(room) && attachment.proof?.integrity?.c2pa !== undefined) { + useOriginal = true; + } + } + + attachment.useCompressed = attachment.compressedFile !== undefined && !useOriginal; } catch (error) { console.error("Failed to get content credentials: " + error); }