Merge pull request #6893 from jaiwanth-v/voice-export

pull/21833/head
Germain 2021-10-01 10:52:41 +01:00 committed by GitHub
commit b86d646fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -21,8 +21,10 @@ import { IExportOptions, ExportType } from "./exportUtils";
import { decryptFile } from "../DecryptFile"; import { decryptFile } from "../DecryptFile";
import { mediaFromContent } from "../../customisations/Media"; import { mediaFromContent } from "../../customisations/Media";
import { formatFullDateNoDay } from "../../DateUtils"; import { formatFullDateNoDay } from "../../DateUtils";
import { isVoiceMessage } from "../EventUtils";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";
import { Direction } from "matrix-js-sdk/src/models/event-timeline"; import { Direction } from "matrix-js-sdk/src/models/event-timeline";
import { IMediaEventContent } from "../../customisations/models/IMediaEventContent";
import { saveAs } from "file-saver"; import { saveAs } from "file-saver";
import { _t } from "../../languageHandler"; import { _t } from "../../languageHandler";
import SdkConfig from "../../SdkConfig"; import SdkConfig from "../../SdkConfig";
@ -200,13 +202,12 @@ export default abstract class Exporter {
let blob: Blob; let blob: Blob;
try { try {
const isEncrypted = event.isEncrypted(); const isEncrypted = event.isEncrypted();
const content = event.getContent(); const content: IMediaEventContent = event.getContent();
const shouldDecrypt = isEncrypted && !content.hasOwnProperty("org.matrix.msc1767.file") const shouldDecrypt = isEncrypted && content.hasOwnProperty("file") && event.getType() !== "m.sticker";
&& event.getType() !== "m.sticker";
if (shouldDecrypt) { if (shouldDecrypt) {
blob = await decryptFile(content.file); blob = await decryptFile(content.file);
} else { } else {
const media = mediaFromContent(event.getContent()); const media = mediaFromContent(content);
const image = await fetch(media.srcHttp); const image = await fetch(media.srcHttp);
blob = await image.blob(); blob = await image.blob();
} }
@ -242,7 +243,10 @@ export default abstract class Exporter {
} }
const fileDate = formatFullDateNoDay(new Date(event.getTs())); const fileDate = formatFullDateNoDay(new Date(event.getTs()));
let [fileName, fileExt] = this.splitFileName(event.getContent().body); let [fileName, fileExt] = this.splitFileName(event.getContent().body);
if (event.getType() === "m.sticker") fileExt = ".png"; if (event.getType() === "m.sticker") fileExt = ".png";
if (isVoiceMessage(event)) fileExt = ".ogg";
return fileDirectory + "/" + fileName + '-' + fileDate + fileExt; return fileDirectory + "/" + fileName + '-' + fileDate + fileExt;
} }