Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

conversation export named after room #7992

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/utils/exportUtils/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,18 @@ export default abstract class Exporter {
this.files.push(file);
}

protected santizeFileName(filename: string): string {
filename = filename.normalize('NFD').replace(/[\u0300-\u036f]/g, "");
filename = filename.replace(/[ ]/gim, "-");
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
Sinharitik589 marked this conversation as resolved.
Show resolved Hide resolved
filename = filename.replace(/[^a-z0-9.,_-]/gim, "");
return filename.trim();
}

protected async downloadZIP(): Promise<string | void> {
const brand = SdkConfig.get().brand;
const filenameWithoutExt = `${brand} - Chat Export - ${formatFullDateNoDay(new Date())}`;
const filenameWithoutExt = this.santizeFileName(
`${brand} - ${this.room.name} - Chat Export - ${formatFullDateNoDay(new Date())}`,
);
const filename = `${filenameWithoutExt}.zip`;
const { default: JSZip } = await import('jszip');

Expand Down
4 changes: 3 additions & 1 deletion src/utils/exportUtils/JSONExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export default class JSONExporter extends Exporter {
this.addFile("export.json", new Blob([text]));
await this.downloadZIP();
} else {
const fileName = `matrix-export-${formatFullDateNoDay(new Date())}.json`;
const fileName = this.santizeFileName(
`matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.json`,
);
this.downloadPlainText(fileName, text);
}

Expand Down
4 changes: 3 additions & 1 deletion src/utils/exportUtils/PlainTextExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export default class PlainTextExporter extends Exporter {
this.addFile("export.txt", new Blob([text]));
await this.downloadZIP();
} else {
const fileName = `matrix-export-${formatFullDateNoDay(new Date())}.txt`;
const fileName = this.santizeFileName(
`matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.txt`,
);
this.downloadPlainText(fileName, text);
}

Expand Down