Refactor, move HTML export to a new file and switch to TypeScript

This commit is contained in:
Jaiwanth
2021-05-22 11:36:28 +05:30
parent e59f23880b
commit dfb7aa4320
3 changed files with 98 additions and 69 deletions
+56
View File
@@ -0,0 +1,56 @@
import { MatrixClientPeg } from "../../MatrixClientPeg";
import { arrayFastClone } from "../arrays";
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
import exportAsHTML from "./HtmlExport";
export const exportFormats = Object.freeze({
"HTML": "HTML",
"JSON": "JSON",
"LOGS": "LOGS",
});
export const exportOptions = Object.freeze({
"TIMELINE": "TIMELINE",
});
const getTimelineConversation = (room) => {
if (!room) return;
const cli = MatrixClientPeg.get();
const timelineSet = room.getUnfilteredTimelineSet();
const timelineWindow = new TimelineWindow(
cli, timelineSet,
{windowLimit: Number.MAX_VALUE});
timelineWindow.load(null, 20);
const events = timelineWindow.getEvents();
// Clone and reverse the events so that we preserve the order
arrayFastClone(events)
.reverse()
.forEach(event => {
cli.decryptEventIfNeeded(event);
});
console.log(events);
return events;
};
const exportConversationalHistory = async (room, format, options) => {
const res = getTimelineConversation(room);
switch (format) {
case exportFormats.HTML:
await exportAsHTML(res, room);
break;
case exportFormats.JSON:
break;
case exportFormats.LOGS:
break;
}
};
export default exportConversationalHistory;