From 2dfaef9b8f84cf6c33e61ca84650a877a5e478c6 Mon Sep 17 00:00:00 2001 From: N-Pex Date: Tue, 2 Sep 2025 09:29:05 +0200 Subject: [PATCH] Default to "original" for C2PA only in direct rooms Issue #677 --- src/components/Chat.vue | 4 +-- .../file_mode/SendAttachmentsLayout.vue | 2 +- src/models/attachment.ts | 2 +- src/models/attachmentManager.ts | 25 +++++++++++++------ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 8f80b3c..d5f0021 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -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; diff --git a/src/components/file_mode/SendAttachmentsLayout.vue b/src/components/file_mode/SendAttachmentsLayout.vue index 8feb742..b1fdf32 100644 --- a/src/components/file_mode/SendAttachmentsLayout.vue +++ b/src/components/file_mode/SendAttachmentsLayout.vue @@ -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(); diff --git a/src/models/attachment.ts b/src/models/attachment.ts index 1513c22..bc4402e 100644 --- a/src/models/attachment.ts +++ b/src/models/attachment.ts @@ -72,7 +72,7 @@ export type AttachmentBatch = { attachmentsSentCount: ComputedRef; attachmentsSending: ComputedRef; attachmentsSent: ComputedRef; - addAttachments: (attachments: Attachment[]) => void; + addFiles: (files: File[]) => void; removeAttachment: (attachment: Attachment) => void; isTooLarge: (attachment: Attachment) => boolean; canSend: ComputedRef; diff --git a/src/models/attachmentManager.ts b/src/models/attachmentManager.ts index a8a9a6c..ca427a0 100644 --- a/src/models/attachmentManager.ts +++ b/src/models/attachmentManager.ts @@ -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 { + private async prepareUpload(attachment: Attachment, room: Room): Promise { 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,