Room export fixes

This commit is contained in:
N Pex 2022-05-24 13:15:48 +00:00
parent 2241d8f3a0
commit 277d6ceca6
5 changed files with 134 additions and 114 deletions

View file

@ -6,7 +6,7 @@
<v-row class="chat-header-row flex-nowrap">
<v-col cols="auto" class="chat-header-members text-start ma-0 pa-0" @click.stop="onHeaderClicked">
<v-avatar size="40" class="me-2">
<v-img v-if="room.avatar || memberAvatar" :src="room.avatar || memberAvatar" />
<v-img v-if="room.avatar" :src="room.avatar" />
</v-avatar>
</v-col>
@ -104,6 +104,7 @@ import chatMixin from "./chatMixin";
import util from "../plugins/utils";
import JSZip from "jszip";
import { saveAs } from "file-saver";
import { EventTimelineSet } from "matrix-js-sdk";
export default {
name: "RoomExport",
@ -159,6 +160,7 @@ export default {
},
data() {
return {
timelineSet: null,
events: [],
fetchedEvents: 0,
totalEvents: 0,
@ -182,10 +184,7 @@ export default {
},
computed: {
exportDate() {
return this.$t("export.exported_date", {date: util.formatDay(Date.now().valueOf())});
},
timelineSet() {
return this.room.getUnfilteredTimelineSet();
return this.$t("export.exported_date", { date: util.formatDay(Date.now().valueOf()) });
},
},
methods: {
@ -241,7 +240,28 @@ export default {
this.getEvents()
.then((events) => {
this.events = events.reverse();
var decryptionPromises = [];
for (const event of this.events) {
if (event.isEncrypted()) {
decryptionPromises.push(
this.$matrix.matrixClient.decryptEventIfNeeded(event, {
isRetry: true,
emit: false,
})
);
}
}
return Promise.all(decryptionPromises).then(() => {
return events;
});
})
.then((events) => {
// Create a timeline and add the events to that, so that relations etc are aggregated correctly!
this.timelineSet = new EventTimelineSet(null, { unstableClientRelationAggregation: true });
this.timelineSet.addEventsToTimeline(events.reverse(), true, this.timelineSet.getLiveTimeline(), "");
this.events = events;
// Wait a tick so UI is updated.
return new Promise((resolve, ignoredReject) => {
this.$nextTick(() => {
resolve(true);
@ -382,7 +402,8 @@ export default {
console.log("All media added, total size: " + currentMediaSize);
let root = this.$refs.exportRoot;
var doc = "<html><head>\n";
var doc = "<!DOCTYPE html>\n<html><head>\n<meta charset=\"utf-8\"/>\n";
for (const sheet of document.styleSheets) {
doc += "<style type='text/css'>\n";
@ -394,7 +415,8 @@ export default {
}
doc += "</style>\n";
}
doc += "</head><body><div class='v-application v-application--is-ltr theme--light' style='height:100%;overflow-y:auto'>";
doc +=
"</head><body><div class='v-application v-application--is-ltr theme--light' style='height:100%;overflow-y:auto'>";
const getCssRules = function(el) {
if (el.classList.contains("op-button")) {
el.innerHTML = "";
@ -412,7 +434,10 @@ export default {
zip.file("chat.html", doc);
zip.generateAsync({ type: "blob" }).then((content) => {
saveAs(content, "example.zip");
saveAs(
content,
this.$t("export.export_filename", { date: util.formatDay(Date.now().valueOf()) }) + ".zip"
);
this.status = "";
this.$emit("close");
});