Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversation export named after room #7992

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/utils/exportUtils/Exporter.ts
Expand Up @@ -75,9 +75,15 @@ export default abstract class Exporter {
this.files.push(file);
}

public santizeFileName(filename: string): string {
filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, "");
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
filename = filename.replace(/[ ]/gim, "-");
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
Sinharitik589 marked this conversation as resolved.
Show resolved Hide resolved
return filename.trim();
}
t3chguy marked this conversation as resolved.
Show resolved Hide resolved

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
8 changes: 7 additions & 1 deletion src/utils/exportUtils/JSONExport.ts
Expand Up @@ -91,6 +91,12 @@ export default class JSONExporter extends Exporter {
return this.createJSONString();
}

public santizeFileName(filename: string): string {
filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, "");
filename = filename.replace(/[ ]/gim, "-");
return filename.trim();
}

public async export() {
logger.info("Starting export process...");
logger.info("Fetching events...");
Expand All @@ -108,7 +114,7 @@ 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
8 changes: 7 additions & 1 deletion src/utils/exportUtils/PlainTextExport.ts
Expand Up @@ -119,6 +119,12 @@ export default class PlainTextExporter extends Exporter {
return content;
}

public santizeFileName(filename: string): string {
filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, "");
filename = filename.replace(/[ ]/gim, "-");
return filename.trim();
}

public async export() {
this.updateProgress(_t("Starting export process..."));
this.updateProgress(_t("Fetching events..."));
Expand All @@ -136,7 +142,7 @@ 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