Room export fixes
This commit is contained in:
parent
2241d8f3a0
commit
277d6ceca6
5 changed files with 134 additions and 114 deletions
|
|
@ -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");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -16,7 +16,13 @@ export default {
|
|||
mounted() {
|
||||
this.$matrix.on("Room.timeline", this.pollMixinOnEvent);
|
||||
this.pollQuestion =
|
||||
(this.event && this.event.getContent()["org.matrix.msc3381.poll.start"]["question"]["body"]) || "";
|
||||
(this.event &&
|
||||
this.event.getContent()["m.poll.start"] &&
|
||||
this.event.getContent()["m.poll.start"]["question"]["body"]) ||
|
||||
(this.event &&
|
||||
this.event.getContent()["org.matrix.msc3381.poll.start"] &&
|
||||
this.event.getContent()["org.matrix.msc3381.poll.start"]["question"]["body"]) ||
|
||||
"";
|
||||
this.updateAnswers();
|
||||
},
|
||||
destroyed() {
|
||||
|
|
@ -34,7 +40,12 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
updateAnswers() {
|
||||
let answers = (this.event && this.event.getContent()["org.matrix.msc3381.poll.start"]["answers"]) || [];
|
||||
let answers =
|
||||
(this.event && this.event.getContent()["m.poll.start"] && this.event.getContent()["m.poll.start"]["answers"]) ||
|
||||
(this.event &&
|
||||
this.event.getContent()["org.matrix.msc3381.poll.start"] &&
|
||||
this.event.getContent()["org.matrix.msc3381.poll.start"]["answers"]) ||
|
||||
[];
|
||||
var answerMap = {};
|
||||
var answerArray = [];
|
||||
answers.forEach((a) => {
|
||||
|
|
@ -45,17 +56,21 @@ export default {
|
|||
});
|
||||
|
||||
// Kind of poll
|
||||
this.pollIsDisclosed =
|
||||
(this.event &&
|
||||
this.event.getContent()["org.matrix.msc3381.poll.start"]["kind"] != "org.matrix.msc3381.poll.undisclosed") ||
|
||||
false;
|
||||
this.pollIsDisclosed = false;
|
||||
if (this.event) {
|
||||
if (this.event.getContent()["m.poll.start"]) {
|
||||
this.pollIssDisclosed = this.event.getContent()["m.poll.start"]["kind"] != "m.poll.undisclosed" || false;
|
||||
} else if (this.event.getContent()["org.matrix.msc3381.poll.start"]) {
|
||||
this.pollIssDisclosed =
|
||||
this.event.getContent()["org.matrix.msc3381.poll.start"]["kind"] != "org.matrix.msc3381.poll.undisclosed" ||
|
||||
false;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for poll end
|
||||
this.pollEndRelations = this.timelineSet.getRelationsForEvent(
|
||||
this.event.getId(),
|
||||
"m.reference",
|
||||
"org.matrix.msc3381.poll.end"
|
||||
);
|
||||
this.pollEndRelations =
|
||||
this.timelineSet.getRelationsForEvent(this.event.getId(), "m.reference", "m.poll.end") ||
|
||||
this.timelineSet.getRelationsForEvent(this.event.getId(), "m.reference", "org.matrix.msc3381.poll.end");
|
||||
if (this.pollEndRelations) {
|
||||
const endMessages = this.pollEndRelations.getRelations() || [];
|
||||
if (endMessages.length > 0) {
|
||||
|
|
@ -64,11 +79,9 @@ export default {
|
|||
}
|
||||
|
||||
// Process votes
|
||||
this.pollResponseRelations = this.timelineSet.getRelationsForEvent(
|
||||
this.event.getId(),
|
||||
"m.reference",
|
||||
"org.matrix.msc3381.poll.response"
|
||||
);
|
||||
this.pollResponseRelations =
|
||||
this.timelineSet.getRelationsForEvent(this.event.getId(), "m.reference", "m.poll.response") ||
|
||||
this.timelineSet.getRelationsForEvent(this.event.getId(), "m.reference", "org.matrix.msc3381.poll.response");
|
||||
var userVotes = {};
|
||||
if (this.pollResponseRelations) {
|
||||
const votes = this.pollResponseRelations.getRelations() || [];
|
||||
|
|
@ -78,7 +91,11 @@ export default {
|
|||
continue; // Invalid vote, after poll was closed.
|
||||
}
|
||||
const sender = vote.getSender();
|
||||
const answersFromThisUser = vote.getContent()["org.matrix.msc3381.poll.response"]["answers"] || [];
|
||||
const answersFromThisUser =
|
||||
(vote.getContent()["m.poll.response"] && vote.getContent()["m.poll.response"]["answers"]) ||
|
||||
(vote.getContent()["org.matrix.msc3381.poll.response"] &&
|
||||
vote.getContent()["org.matrix.msc3381.poll.response"]["answers"]) ||
|
||||
[];
|
||||
if (answersFromThisUser.length == 0) {
|
||||
delete userVotes[sender];
|
||||
} else {
|
||||
|
|
@ -158,7 +175,7 @@ export default {
|
|||
return; // Not for this room
|
||||
}
|
||||
this.$matrix.matrixClient.decryptEventIfNeeded(event).then(() => {
|
||||
if (event.getType().startsWith("org.matrix.msc3381.poll.")) {
|
||||
if (event.getType().startsWith("m.poll.") || event.getType().startsWith("org.matrix.msc3381.poll.")) {
|
||||
this.updateAnswers();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue