diff --git a/src/ContentMessages.tsx b/src/ContentMessages.tsx index 9042d472439..7a3cf5d50fa 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 122ba0ca0b5..eb86737d58f 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; } }