fix: use configured brand name in JSON and PlainText chat export filenames (#33680)

* fix: use configured brand name in JSON and PlainText chat export filenames

The JSON and PlainText chat export functions were using the hardcoded
default 'matrix' as the brand name in filenames, while the HTML/ZIP
export correctly used the configured brand (e.g., 'Element').

This made the filenames inconsistent:
- ZIP: Element - Room - Chat Export - timestamp.zip
- JSON: matrix - Room - Chat Export - timestamp.json

Now both JSON and PlainText exports pass SdkConfig.get().brand to
makeFileNameNoExtension(), matching the behavior of the base Exporter
class used by HTML exports.

Fixes #32853

Signed-off-by: RoySerbi <roy676564@gmail.com>

* refactor: read brand from SdkConfig inside makeFileNameNoExtension

Address review feedback from @t3chguy: the brand parameter on
makeFileNameNoExtension was effectively dead (all three call sites passed
SdkConfig.get().brand and the 'matrix' default was unreachable).

- Exporter.makeFileNameNoExtension now reads SdkConfig.get().brand directly
- All call sites (Exporter, JSONExport, PlainTextExport) simplified to no-arg
- Drop now-unused SdkConfig imports in JSONExport and PlainTextExport

Tests are unchanged: they already mock SdkConfig to return 'Element', so the
existing 'Element-branded destination file name' snapshots remain valid.

---------

Signed-off-by: RoySerbi <roy676564@gmail.com>
This commit is contained in:
RoyS
2026-06-01 16:44:28 +03:00
committed by GitHub
parent 531fc76726
commit 210421ac47
5 changed files with 7 additions and 7 deletions
+3 -3
View File
@@ -56,7 +56,7 @@ export default abstract class Exporter {
}
public get destinationFileName(): string {
return this.makeFileNameNoExtension(SdkConfig.get().brand) + ".zip";
return this.makeFileNameNoExtension() + ".zip";
}
protected onBeforeUnload(this: void, e: BeforeUnloadEvent): string {
@@ -77,12 +77,12 @@ export default abstract class Exporter {
this.files.push(file);
}
protected makeFileNameNoExtension(brand = "matrix"): string {
protected makeFileNameNoExtension(): string {
// First try to use the real name of the room, then a translated copy of a generic name,
// then finally hardcoded default to guarantee we'll have a name.
const safeRoomName = sanitizeFilename(this.room.name ?? _t("common|unnamed_room")).trim() || "Unnamed Room";
const safeDate = formatFullDateNoDayISO(new Date()).replace(/:/g, "-"); // ISO format automatically removes a lot of stuff for us
const safeBrand = sanitizeFilename(brand);
const safeBrand = sanitizeFilename(SdkConfig.get().brand);
return `${safeBrand} - ${safeRoomName} - Chat Export - ${safeDate}`;
}
@@ -16,7 +16,7 @@ describe("JSONExport", () => {
jest.setSystemTime(REPEATABLE_DATE);
});
it("should have a Matrix-branded destination file name", () => {
it("should have an Element-branded destination file name", () => {
const roomName = "My / Test / Room: Welcome";
const client = createTestClient();
const stubOptions: IExportOptions = {
@@ -34,7 +34,7 @@ describe("PlainTextExport", () => {
stubRoom = mkStubRoom("!myroom:example.org", roomName, client);
});
it("should have a Matrix-branded destination file name", () => {
it("should have an Element-branded destination file name", () => {
const exporter = new PlainTextExporter(stubRoom, ExportType.Timeline, stubOptions, () => {});
expect(exporter.destinationFileName).toMatchSnapshot();
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`JSONExport should have a Matrix-branded destination file name 1`] = `"matrix - My Test Room Welcome - Chat Export - 2022-11-17T16-58-32.517Z.json"`;
exports[`JSONExport should have an Element-branded destination file name 1`] = `"Element - My Test Room Welcome - Chat Export - 2022-11-17T16-58-32.517Z.json"`;
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`PlainTextExport should have a Matrix-branded destination file name 1`] = `"matrix - My Test Room Welcome - Chat Export - 2022-11-17T16-58-32.517Z.txt"`;
exports[`PlainTextExport should have an Element-branded destination file name 1`] = `"Element - My Test Room Welcome - Chat Export - 2022-11-17T16-58-32.517Z.txt"`;