From 245c3bdfab97d7b7103354f4ef824dacf19c8bf3 Mon Sep 17 00:00:00 2001 From: yaya-usman Date: Tue, 10 May 2022 23:03:42 +0300 Subject: [PATCH 1/2] exported chat date iso formatted --- src/DateUtils.ts | 4 ++++ src/utils/exportUtils/Exporter.ts | 6 ++---- src/utils/exportUtils/JSONExport.ts | 4 ++-- src/utils/exportUtils/PlainTextExport.ts | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/DateUtils.ts b/src/DateUtils.ts index 20227354f02..bac7481a4f2 100644 --- a/src/DateUtils.ts +++ b/src/DateUtils.ts @@ -177,6 +177,10 @@ export function formatFullDateNoDay(date: Date) { }); } +export function formatFullDateNoDayISO(date: Date) { + return date.toISOString(); +} + export function formatFullDateNoDayNoTime(date: Date) { return ( date.getFullYear() + diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index 7b4a7bf342f..ea88125e7e5 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -25,11 +25,10 @@ import { MatrixClientPeg } from "../../MatrixClientPeg"; import { ExportType, IExportOptions } from "./exportUtils"; import { decryptFile } from "../DecryptFile"; import { mediaFromContent } from "../../customisations/Media"; -import { formatFullDateNoDay } from "../../DateUtils"; +import { formatFullDateNoDay, formatFullDateNoDayISO } from "../../DateUtils"; import { isVoiceMessage } from "../EventUtils"; import { IMediaEventContent } from "../../customisations/models/IMediaEventContent"; import { _t } from "../../languageHandler"; -import SdkConfig from "../../SdkConfig"; type BlobFile = { name: string; @@ -76,8 +75,7 @@ export default abstract class Exporter { } protected async downloadZIP(): Promise { - const brand = SdkConfig.get().brand; - const filenameWithoutExt = `${brand} - Chat Export - ${formatFullDateNoDay(new Date())}`; + const filenameWithoutExt = `${this.room.name}-${formatFullDateNoDayISO(new Date())}`; const filename = `${filenameWithoutExt}.zip`; const { default: JSZip } = await import('jszip'); diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index b0b4b330b06..57ee1ea447e 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -20,7 +20,7 @@ import { EventType } from "matrix-js-sdk/src/@types/event"; import { logger } from "matrix-js-sdk/src/logger"; import Exporter from "./Exporter"; -import { formatFullDateNoDay, formatFullDateNoDayNoTime } from "../../DateUtils"; +import { formatFullDateNoDayISO, formatFullDateNoDayNoTime } from "../../DateUtils"; import { ExportType, IExportOptions } from "./exportUtils"; import { _t } from "../../languageHandler"; import { haveRendererForEvent } from "../../events/EventTileFactory"; @@ -108,7 +108,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.room.name}-${formatFullDateNoDayISO(new Date())}.json`; this.downloadPlainText(fileName, text); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index e86c56e9f4c..da5dbcaf007 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -19,7 +19,7 @@ import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event"; import { logger } from "matrix-js-sdk/src/logger"; import Exporter from "./Exporter"; -import { formatFullDateNoDay } from "../../DateUtils"; +import { formatFullDateNoDayISO } from "../../DateUtils"; import { _t } from "../../languageHandler"; import { ExportType, IExportOptions } from "./exportUtils"; import { textForEvent } from "../../TextForEvent"; @@ -136,7 +136,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.room.name}-${formatFullDateNoDayISO(new Date())}.txt`; this.downloadPlainText(fileName, text); } From eb9f262567558905c5af7a226e448f14c1a03f24 Mon Sep 17 00:00:00 2001 From: yaya-usman Date: Tue, 10 May 2022 23:03:42 +0300 Subject: [PATCH 2/2] code refacto filename date format --- src/utils/exportUtils/Exporter.ts | 4 +++- src/utils/exportUtils/JSONExport.ts | 2 +- src/utils/exportUtils/PlainTextExport.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index ea88125e7e5..74eeed1b8ea 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -29,6 +29,7 @@ import { formatFullDateNoDay, formatFullDateNoDayISO } from "../../DateUtils"; import { isVoiceMessage } from "../EventUtils"; import { IMediaEventContent } from "../../customisations/models/IMediaEventContent"; import { _t } from "../../languageHandler"; +import SdkConfig from "../../SdkConfig"; type BlobFile = { name: string; @@ -75,7 +76,8 @@ export default abstract class Exporter { } protected async downloadZIP(): Promise { - const filenameWithoutExt = `${this.room.name}-${formatFullDateNoDayISO(new Date())}`; + const brand = SdkConfig.get().brand; + const filenameWithoutExt = `${brand} - ${this.room.name} - Chat Export -${formatFullDateNoDayISO(new Date())}`; const filename = `${filenameWithoutExt}.zip`; const { default: JSZip } = await import('jszip'); diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index 57ee1ea447e..9e5987e4e4f 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -108,7 +108,7 @@ export default class JSONExporter extends Exporter { this.addFile("export.json", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `${this.room.name}-${formatFullDateNoDayISO(new Date())}.json`; + const fileName = `matrix-${this.room.name}-export-${formatFullDateNoDayISO(new Date())}.json`; this.downloadPlainText(fileName, text); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index da5dbcaf007..ee1c3aeed48 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -136,7 +136,7 @@ export default class PlainTextExporter extends Exporter { this.addFile("export.txt", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `${this.room.name}-${formatFullDateNoDayISO(new Date())}.txt`; + const fileName = `matrix-${this.room.name}-export-${formatFullDateNoDayISO(new Date())}.txt`; this.downloadPlainText(fileName, text); }