Defaults for original/compressed media

Issue #697.
This commit is contained in:
N-Pex 2025-10-23 11:35:52 +02:00
parent 221f8ced1a
commit 002666d273

View file

@ -5,6 +5,7 @@ import {
EventAttachmentUrlType, EventAttachmentUrlType,
KeanuEvent, KeanuEvent,
KeanuEventExtension, KeanuEventExtension,
KeanuRoom,
} from "./eventAttachment"; } from "./eventAttachment";
import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import { Counter, ModeOfOperation } from "aes-js"; import { Counter, ModeOfOperation } from "aes-js";
@ -48,11 +49,11 @@ export class AttachmentManager {
.catch(() => {}); .catch(() => {});
} }
public createUpload(room: Room) { public createUpload(room: KeanuRoom) {
return createUploadBatch(this, room); return createUploadBatch(this, room);
} }
public createAttachment(file: File, room: Room): Attachment { public createAttachment(file: File, room: KeanuRoom): Attachment {
let a: Attachment = { let a: Attachment = {
status: "loading", status: "loading",
file: file, file: file,
@ -73,7 +74,7 @@ export class AttachmentManager {
return ra; return ra;
} }
private async prepareUpload(attachment: Attachment, room: Room): Promise<Attachment> { private async prepareUpload(attachment: Attachment, room: KeanuRoom): Promise<Attachment> {
const file = attachment.file; const file = attachment.file;
if (file.type.startsWith("image/")) { if (file.type.startsWith("image/")) {
let url = URL.createObjectURL(file); let url = URL.createObjectURL(file);
@ -125,17 +126,26 @@ export class AttachmentManager {
const isDirectRoom = (room: Room) => { const isDirectRoom = (room: Room) => {
// TODO - Use the is_direct accountData flag (m.direct). WE (as the client) // TODO - Use the is_direct accountData flag (m.direct). WE (as the client)
// apprently need to set this... // 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 true;
} }
return false; return false;
}; };
attachment.useCompressed = const isChannel = room.displayType == "im.keanu.room_type_channel";
attachment.compressedFile !== undefined && const isFileDrop = room.displayType == "im.keanu.room_type_file";
(attachment.proof === undefined ||
!isDirectRoom(room) || let useOriginal = false;
attachment.proof.integrity === undefined || if (isChannel) {
attachment.proof.integrity.c2pa === undefined); 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) { } catch (error) {
console.error("Failed to get content credentials: " + error); console.error("Failed to get content credentials: " + error);
} }