Default to "original" for C2PA only in direct rooms

Issue #677
This commit is contained in:
N-Pex 2025-09-02 09:29:05 +02:00
parent b9e221bc30
commit 2dfaef9b8f
4 changed files with 21 additions and 12 deletions

View file

@ -1435,7 +1435,7 @@ export default {
if (!this.uploadBatch) {
this.uploadBatch = this.$matrix.attachmentManager.createUpload(this.room);
}
this.uploadBatch?.addAttachments(files.map((f) => this.$matrix.attachmentManager.createAttachment(f)));
this.uploadBatch?.addFiles(files);
},
showStickerPicker() {
@ -1886,7 +1886,7 @@ export default {
onVoiceRecording(event) {
const batch = this.$matrix.attachmentManager.createUpload(this.room);
batch.addAttachments([this.$matrix.attachmentManager.createAttachment(event.file)]);
batch.addFiles([event.file]);
var text = undefined;
if (this.currentInput && this.currentInput.length > 0) {
text = this.currentInput;

View file

@ -312,7 +312,7 @@ export default defineComponent({
const file = droppedFiles.item(i);
if (file) files.push(file);
}
this.batch.addAttachments(files.map((f) => this.$matrix.attachmentManager.createAttachment(f)));
this.batch.addFiles(files);
},
close() {
this.batch.cancel();

View file

@ -72,7 +72,7 @@ export type AttachmentBatch = {
attachmentsSentCount: ComputedRef<number>;
attachmentsSending: ComputedRef<Attachment[]>;
attachmentsSent: ComputedRef<Attachment[]>;
addAttachments: (attachments: Attachment[]) => void;
addFiles: (files: File[]) => void;
removeAttachment: (attachment: Attachment) => void;
isTooLarge: (attachment: Attachment) => boolean;
canSend: ComputedRef<boolean>;

View file

@ -52,7 +52,7 @@ export class AttachmentManager {
return createUploadBatch(this, room);
}
public createAttachment(file: File): Attachment {
public createAttachment(file: File, room: Room): Attachment {
let a: Attachment = {
status: "loading",
file: file,
@ -69,11 +69,11 @@ export class AttachmentManager {
},
};
const ra = shallowReactive(a);
this.prepareUpload(ra);
this.prepareUpload(ra, room);
return ra;
}
private async prepareUpload(attachment: Attachment): Promise<Attachment> {
private async prepareUpload(attachment: Attachment, room: Room): Promise<Attachment> {
const file = attachment.file;
if (file.type.startsWith("image/")) {
let url = URL.createObjectURL(file);
@ -123,9 +123,18 @@ export class AttachmentManager {
// Default to scaled version if the image does not contain Content Credentials
//
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) {
return true;
}
return false;
};
attachment.useScaled =
attachment.scaledFile !== undefined &&
(attachment.proof === undefined ||
!isDirectRoom(room) ||
attachment.proof.integrity === undefined ||
attachment.proof.integrity.c2pa === undefined);
} catch (error) {
@ -459,9 +468,9 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
attachments.value.sort((a, b) => (b.sendInfo?.statusDate ?? 0) - (a.sendInfo?.statusDate ?? 0));
};
const addAttachments = (attachmentsToAdd: Attachment[]) => {
if (sendingStatus.value == "initial") {
attachments.value.push(...attachmentsToAdd);
const addFiles = (filesToAdd: File[]) => {
if (sendingStatus.value == "initial" && manager !== null && room !== null) {
attachments.value.push(...filesToAdd.map((f) => manager!.createAttachment(f, room)));
}
};
@ -564,7 +573,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
attachmentsSentCount,
attachmentsSending,
attachmentsSent,
addAttachments,
addFiles,
removeAttachment,
isTooLarge,
canSend,
@ -681,7 +690,7 @@ export const createUploadBatch = (manager: AttachmentManager | null, room: Room
attachmentsSentCount,
attachmentsSending,
attachmentsSent,
addAttachments,
addFiles,
removeAttachment,
isTooLarge,
canSend,