Handle encrypted stickers and store stickers in a separate folder

This commit is contained in:
Jaiwanth 2021-06-02 12:06:00 +05:30
parent c63c59b408
commit 692e499cf2
3 changed files with 9 additions and 7 deletions

View File

@ -137,7 +137,6 @@ export function wantsDateSeparator(prevEventDate: Date, nextEventDate: Date): bo
return prevEventDate.getDay() !== nextEventDate.getDay();
}
export function formatFullDateNoDay(date: Date) {
return (
date.getFullYear() +

View File

@ -176,7 +176,9 @@ export default class MFileBody extends React.Component {
placeholder = (
<div className="mx_MFileBody_info">
<span className="mx_MFileBody_info_icon" >
{this.props.isExporting ? <img class="mx_export_attach_icon" src="icons/attach.svg" /> : null}
{this.props.isExporting ?
<img className="mx_export_attach_icon" src="icons/attach.svg" />
: null}
</span>
<span className="mx_MFileBody_info_filename">{this.presentableTextForFile(content, false)}</span>
</div>

View File

@ -156,7 +156,9 @@ export default class HTMLExporter extends Exporter {
try {
const isEncrypted = event.isEncrypted();
const content = event.getContent();
if (isEncrypted && !content.hasOwnProperty("org.matrix.msc1767.file")) {
const shouldDecrypt = isEncrypted && !content.hasOwnProperty("org.matrix.msc1767.file")
&& event.getType() !== "m.sticker";
if (shouldDecrypt) {
blob = await decryptFile(content.file);
} else {
const media = mediaFromContent(event.getContent());
@ -185,7 +187,7 @@ export default class HTMLExporter extends Exporter {
if (lastDot === -1) return [file, ""];
const fileName = file.slice(0, lastDot);
const ext = file.slice(lastDot + 1);
return [fileName, ext];
return [fileName, '.' + ext];
}
protected getFilePath(event: MatrixEvent) {
@ -202,12 +204,11 @@ export default class HTMLExporter extends Exporter {
fileDirectory = "audio";
break;
default:
fileDirectory = "files";
break;
fileDirectory = event.getType() === "m.sticker" ? "stickers" : "files";
}
const fileDate = formatFullDateNoDay(new Date(event.getTs()));
const [fileName, fileExt] = this.splitFileName(event.getContent().body);
const filePath = fileDirectory + "/" + fileName + '-' + fileDate + '.' + fileExt;
const filePath = fileDirectory + "/" + fileName + '-' + fileDate + fileExt;
return filePath;
}