2021-05-24 15:18:13 +00:00
|
|
|
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
2021-05-24 15:50:16 +00:00
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
2021-06-03 07:51:56 +00:00
|
|
|
import { MatrixClientPeg } from "../../MatrixClientPeg";
|
|
|
|
import { TimelineWindow } from "matrix-js-sdk/src/timeline-window";
|
|
|
|
import { arrayFastClone } from "../arrays";
|
2021-05-24 15:18:13 +00:00
|
|
|
|
2021-06-03 08:09:14 +00:00
|
|
|
export default abstract class Exporter {
|
2021-06-03 07:51:56 +00:00
|
|
|
constructor(protected room: Room) {}
|
|
|
|
|
2021-06-03 08:09:14 +00:00
|
|
|
protected getTimelineConversation = () : MatrixEvent[] => {
|
2021-06-03 07:51:56 +00:00
|
|
|
if (!this.room) return;
|
|
|
|
|
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
|
|
|
|
const timelineSet = this.room.getUnfilteredTimelineSet();
|
|
|
|
|
|
|
|
const timelineWindow = new TimelineWindow(
|
|
|
|
cli, timelineSet,
|
|
|
|
{windowLimit: Number.MAX_VALUE});
|
|
|
|
|
|
|
|
timelineWindow.load(null, 30);
|
|
|
|
|
|
|
|
const events = timelineWindow.getEvents();
|
|
|
|
|
|
|
|
// Clone and reverse the events so that we preserve the order
|
|
|
|
arrayFastClone(events)
|
|
|
|
.reverse()
|
|
|
|
.forEach(event => {
|
|
|
|
cli.decryptEventIfNeeded(event);
|
|
|
|
});
|
|
|
|
|
|
|
|
return events;
|
|
|
|
};
|
|
|
|
|
2021-05-24 15:50:16 +00:00
|
|
|
abstract export(): Promise<Blob>;
|
2021-05-24 15:18:13 +00:00
|
|
|
}
|