From 1aab43b2e64963e1463c2e33dacfd348c0ba854f Mon Sep 17 00:00:00 2001
From: grimhilt
Date: Mon, 20 Feb 2023 14:19:41 +0100
Subject: [PATCH 1/7] add link
---
src/utils/exportUtils/HtmlExport.tsx | 41 +++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx
index 77c1bc0155d..f70750363f5 100644
--- a/src/utils/exportUtils/HtmlExport.tsx
+++ b/src/utils/exportUtils/HtmlExport.tsx
@@ -92,7 +92,7 @@ export default class HTMLExporter extends Exporter {
return renderToStaticMarkup(avatar);
}
- protected async wrapHTML(content: string): Promise {
+ protected async wrapHTML(content: string, currentPage: number, nbPages: number): Promise {
const roomAvatar = await this.getRoomAvatar();
const exportDate = formatFullDateNoDayNoTime(new Date());
const creator = this.room.currentState.getStateEvents(EventType.RoomCreate, "")?.getSender();
@@ -131,6 +131,32 @@ export default class HTMLExporter extends Exporter {
);
const topicText = topic ? _t("Topic: %(topic)s", { topic }) : "";
+ const previousMessagesLink = renderToStaticMarkup(
+ currentPage !== 0 ? (
+
+ ) : (
+ <>>
+ )
+ );
+
+ const nextMessagesLink = renderToStaticMarkup(
+ currentPage !== (nbPages - 1) ? (
+
+ ) : (
+ <>>
+ )
+ );
return `
@@ -171,6 +197,7 @@ export default class HTMLExporter extends Exporter {
+ ${previousMessagesLink}
@@ -384,7 +412,12 @@ export default class HTMLExporter extends Exporter {
return eventTile;
}
- protected async createHTML(events: MatrixEvent[], start: number): Promise {
+ protected async createHTML(
+ events: MatrixEvent[],
+ start: number,
+ currentPage: number,
+ nbPages: number,
+ ): Promise {
let content = "";
let prevEvent: MatrixEvent | null = null;
for (let i = start; i < Math.min(start + 1000, events.length); i++) {
@@ -409,7 +442,7 @@ export default class HTMLExporter extends Exporter {
content += body;
prevEvent = event;
}
- return this.wrapHTML(content);
+ return this.wrapHTML(content, currentPage, nbPages);
}
public async export(): Promise {
@@ -432,7 +465,7 @@ export default class HTMLExporter extends Exporter {
const usedClasses = new Set();
for (let page = 0; page < res.length / 1000; page++) {
- const html = await this.createHTML(res, page * 1000);
+ const html = await this.createHTML(res, page * 1000, page, res.length / 1000);
const document = new DOMParser().parseFromString(html, "text/html");
document.querySelectorAll("*").forEach((element) => {
element.classList.forEach((c) => usedClasses.add(c));
From 2a4702636198d24378d7da7cf461c0ac43b3e153 Mon Sep 17 00:00:00 2001
From: grimhilt
Date: Mon, 20 Feb 2023 14:30:39 +0100
Subject: [PATCH 2/7] update snapshot
---
test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap | 2 ++
1 file changed, 2 insertions(+)
diff --git a/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap b/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap
index c47170d3eda..f1962fba716 100644
--- a/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap
+++ b/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap
@@ -40,6 +40,7 @@ exports[`HTMLExport should export 1`] = `
+
From a473b96d7bfa5ed1b7984f88ee795d117de5c4e5 Mon Sep 17 00:00:00 2001
From: grimhilt
Date: Mon, 20 Feb 2023 14:59:48 +0100
Subject: [PATCH 3/7] add test
---
test/utils/exportUtils/HTMLExport-test.ts | 29 +++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/test/utils/exportUtils/HTMLExport-test.ts b/test/utils/exportUtils/HTMLExport-test.ts
index 7e1f7a53b78..7d5aafc646c 100644
--- a/test/utils/exportUtils/HTMLExport-test.ts
+++ b/test/utils/exportUtils/HTMLExport-test.ts
@@ -315,4 +315,33 @@ describe("HTMLExport", () => {
expect(fileName).not.toMatch(/^files\/hello/);
}
});
+
+ it("should add link to next and previous file", async () => {
+ const exporter = new HTMLExporter(
+ room,
+ ExportType.LastNMessages,
+ {
+ attachmentsIncluded: false,
+ maxSize: 1_024 * 1_024,
+ },
+ () => {},
+ );
+
+ //@ts-ignore private access
+ const firstPage = exporter.wrapHTML("", 0, 3).then((res) => {
+ expect(res).not.toContain('Previous group of messages');
+ expect(res).toContain('');
+ });
+ //@ts-ignore private access
+ const middlePage = exporter.wrapHTML("", 1, 3).then((res) => {
+ expect(res).toContain('');
+ expect(res).toContain('');
+ });
+ //@ts-ignore private access
+ const lastPage = exporter.wrapHTML("", 2, 3).then((res) => {
+ expect(res).toContain('');
+ expect(res).not.toContain('Next group of messages');
+ });
+
+ });
});
From 2312fe9364af8f515344bec58d254025a7c31906 Mon Sep 17 00:00:00 2001
From: grimhilt
Date: Mon, 20 Feb 2023 15:27:29 +0100
Subject: [PATCH 4/7] remove room introduction when it is not the first file
---
src/utils/exportUtils/HtmlExport.tsx | 43 ++++++++++++++--------------
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx
index f70750363f5..fcc6a3f40d0 100644
--- a/src/utils/exportUtils/HtmlExport.tsx
+++ b/src/utils/exportUtils/HtmlExport.tsx
@@ -132,22 +132,19 @@ export default class HTMLExporter extends Exporter {
const topicText = topic ? _t("Topic: %(topic)s", { topic }) : "";
const previousMessagesLink = renderToStaticMarkup(
- currentPage !== 0 ? (
-
- ) : (
- <>>
- )
+ currentPage !== 0 ? (
+
+ ) : (
+ <>>
+ ),
);
const nextMessagesLink = renderToStaticMarkup(
- currentPage !== (nbPages - 1) ? (
+ currentPage !== nbPages - 1 ? (
) : (
<>>
- )
+ ),
);
return `
@@ -216,13 +213,17 @@ export default class HTMLExporter extends Exporter {
aria-live="polite"
role="list"
>
-
- ${roomAvatar}
-
${this.room.name}
-
${createdText}
${exportedText}
-
-
${topicText}
-
+ ${
+ currentPage == 0
+ ? `
+ ${roomAvatar}
+
${this.room.name}
+
${createdText}
${exportedText}
+
+
${topicText}
+
`
+ : ""
+ }
${content}
From 1fa7494c1a42279bd36b067bf41745f11a969172 Mon Sep 17 00:00:00 2001
From: grimhilt
Date: Mon, 20 Feb 2023 15:27:49 +0100
Subject: [PATCH 5/7] fix eslint
---
test/utils/exportUtils/HTMLExport-test.ts | 34 +++++++++++++++--------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/test/utils/exportUtils/HTMLExport-test.ts b/test/utils/exportUtils/HTMLExport-test.ts
index 7d5aafc646c..bbdfa9e6479 100644
--- a/test/utils/exportUtils/HTMLExport-test.ts
+++ b/test/utils/exportUtils/HTMLExport-test.ts
@@ -326,22 +326,34 @@ describe("HTMLExport", () => {
},
() => {},
);
-
+
+ // test link to the first page
//@ts-ignore private access
- const firstPage = exporter.wrapHTML("", 0, 3).then((res) => {
- expect(res).not.toContain('Previous group of messages');
- expect(res).toContain('');
+ exporter.wrapHTML("", 0, 3).then((res) => {
+ expect(res).not.toContain("Previous group of messages");
+ expect(res).toContain(
+ '',
+ );
});
+
+ // test link for a middle page
//@ts-ignore private access
- const middlePage = exporter.wrapHTML("", 1, 3).then((res) => {
- expect(res).toContain('');
- expect(res).toContain('');
+ exporter.wrapHTML("", 1, 3).then((res) => {
+ expect(res).toContain(
+ '',
+ );
+ expect(res).toContain(
+ '',
+ );
});
+
+ // test link for last page
//@ts-ignore private access
- const lastPage = exporter.wrapHTML("", 2, 3).then((res) => {
- expect(res).toContain('');
- expect(res).not.toContain('Next group of messages');
+ exporter.wrapHTML("", 2, 3).then((res) => {
+ expect(res).toContain(
+ '',
+ );
+ expect(res).not.toContain("Next group of messages");
});
-
});
});
From d19f9115391afcb7f6ae077c1b4d8a254fe39b87 Mon Sep 17 00:00:00 2001
From: grimhilt
Date: Mon, 20 Feb 2023 15:28:01 +0100
Subject: [PATCH 6/7] update snapshot
---
.../__snapshots__/HTMLExport-test.ts.snap | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap b/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap
index f1962fba716..c4f3533e11e 100644
--- a/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap
+++ b/test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap
@@ -60,12 +60,12 @@ exports[`HTMLExport should export 1`] = `
role="list"
>
-
!
-
!myroom:example.org
-
created this room.
This is the start of export of !myroom:example.org. Exported by @userId:matrix.org at 2022/11/17.
-
-
-
+ !
+ !myroom:example.org
+ created this room.
This is the start of export of !myroom:example.org. Exported by @userId:matrix.org at 2022/11/17.
+
+
+
Thu, Jan 1 1970
@user49:example.com
U
@user48:example.com
U
@user47:example.com
U
@user46:example.com
U
@user45:example.com
U
@user44:example.com
U
@user43:example.com
U
@user42:example.com
U
@user41:example.com
U
@user40:example.com
U
@user39:example.com
U
@user38:example.com
U
@user37:example.com
U
@user36:example.com
U
@user35:example.com
U
@user34:example.com
U
@user33:example.com
U
@user32:example.com
U
@user31:example.com
U
@user30:example.com
U
@user29:example.com
U
@user28:example.com
U
@user27:example.com
U
@user26:example.com
U
@user25:example.com
U
@user24:example.com
U
@user23:example.com
U
@user22:example.com
U
@user21:example.com
U
@user20:example.com
U
@user19:example.com
U
@user18:example.com
U
@user17:example.com
U
@user16:example.com
U
@user15:example.com
U
@user14:example.com
U
@user13:example.com
U
@user12:example.com
U
@user11:example.com
U
@user10:example.com
U
@user9:example.com
U
@user8:example.com
U
@user7:example.com
U
@user6:example.com
U
@user5:example.com
U
@user4:example.com
U
@user3:example.com
U
@user2:example.com
U
@user1:example.com
U
@user0:example.com
U
From e6f7cbebeedef4913280dc39dbeac08ade129e15 Mon Sep 17 00:00:00 2001
From: grimhilt
Date: Tue, 21 Feb 2023 15:38:31 +0100
Subject: [PATCH 7/7] remote next link when have a single file
---
src/utils/exportUtils/HtmlExport.tsx | 2 +-
test/utils/exportUtils/__snapshots__/HTMLExport-test.ts.snap | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/utils/exportUtils/HtmlExport.tsx b/src/utils/exportUtils/HtmlExport.tsx
index fcc6a3f40d0..eed712720e8 100644
--- a/src/utils/exportUtils/HtmlExport.tsx
+++ b/src/utils/exportUtils/HtmlExport.tsx
@@ -144,7 +144,7 @@ export default class HTMLExporter extends Exporter {
);
const nextMessagesLink = renderToStaticMarkup(
- currentPage !== nbPages - 1 ? (
+ currentPage < nbPages - 1 ? (
-
+