From cb0d2a2c4f49e72713b743c1d5af3323c36da593 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 25 Jun 2021 13:54:05 -0600 Subject: [PATCH] Encrypt the voice message file if needed Fixes https://github.com/vector-im/element-web/issues/17729 "oops, should have done that" --- src/ContentMessages.tsx | 2 +- .../views/rooms/VoiceRecordComposerTile.tsx | 8 +++-- src/voice/VoiceRecording.ts | 31 +++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 9042d47243..7a3cf5d50f 100644 --- a/src/ContentMessages.tsx +++ b/src/ContentMessages.tsx @@ -307,7 +307,7 @@ function readFileAsArrayBuffer(file: File | Blob): Promise { * If the file is unencrypted then the object will have a "url" key. * If the file is encrypted then the object will have a "file" key. */ -function uploadFile( +export function uploadFile( matrixClient: MatrixClient, roomId: string, file: File | Blob, diff --git a/src/components/views/rooms/VoiceRecordComposerTile.tsx b/src/components/views/rooms/VoiceRecordComposerTile.tsx index 122ba0ca0b..248d196506 100644 --- a/src/components/views/rooms/VoiceRecordComposerTile.tsx +++ b/src/components/views/rooms/VoiceRecordComposerTile.tsx @@ -65,12 +65,13 @@ export default class VoiceRecordComposerTile extends React.PureComponent; private amplitudes: number[] = []; // at each second mark, generated @@ -214,13 +221,6 @@ export class VoiceRecording extends EventEmitter implements IDestroyable { return this.buffer.length > 0; } - public get mxcUri(): string { - if (!this.mxc) { - throw new Error("Recording has not been uploaded yet"); - } - return this.mxc; - } - private onAudioProcess = (ev: AudioProcessingEvent) => { this.processAudioUpdate(ev.playbackTime); @@ -290,7 +290,7 @@ export class VoiceRecording extends EventEmitter implements IDestroyable { }; public async start(): Promise { - if (this.mxc || this.hasRecording) { + if (this.lastUpload || this.hasRecording) { throw new Error("Recording already prepared"); } if (this.recording) { @@ -362,20 +362,19 @@ export class VoiceRecording extends EventEmitter implements IDestroyable { this.observable.close(); } - public async upload(): Promise { + public async upload(inRoomId: string): Promise { if (!this.hasRecording) { throw new Error("No recording available to upload"); } - if (this.mxc) return this.mxc; + if (this.lastUpload) return this.lastUpload; this.emit(RecordingState.Uploading); - this.mxc = await this.client.uploadContent(new Blob([this.audioBuffer], { + const { url: mxc, file: encrypted } = await uploadFile(this.client, inRoomId, new Blob([this.audioBuffer], { type: this.contentType, - }), { - onlyContentUri: false, // to stop the warnings in the console - }).then(r => r['content_uri']); + })); + this.lastUpload = {mxc, encrypted}; this.emit(RecordingState.Uploaded); - return this.mxc; + return this.lastUpload; } }