WIP improve export
This commit is contained in:
parent
9a124c5ab9
commit
94bf35875a
3 changed files with 174 additions and 169 deletions
|
|
@ -27,12 +27,12 @@
|
||||||
<div v-if="!event.isRelation() && !event.isRedacted() && !event.isRedaction()" :ref="event.getId()">
|
<div v-if="!event.isRelation() && !event.isRedacted() && !event.isRedaction()" :ref="event.getId()">
|
||||||
<div class="message-wrapper">
|
<div class="message-wrapper">
|
||||||
<component
|
<component
|
||||||
:is="componentForEvent(event, true)"
|
:is="componentForEventForExport(event, true)"
|
||||||
:room="room"
|
:room="room"
|
||||||
:originalEvent="event"
|
:originalEvent="event"
|
||||||
:nextEvent="events[index + 1]"
|
:nextEvent="events[index + 1]"
|
||||||
:timelineSet="timelineSet"
|
:timelineSet="timelineSet"
|
||||||
:componentFn="componentForEvent"
|
:componentFn="componentForEventForExport"
|
||||||
ref="exportedEvent"
|
ref="exportedEvent"
|
||||||
v-on:layout-change="onLayoutChange"
|
v-on:layout-change="onLayoutChange"
|
||||||
/>
|
/>
|
||||||
|
|
@ -153,6 +153,7 @@ export default {
|
||||||
return {
|
return {
|
||||||
timelineSet: null,
|
timelineSet: null,
|
||||||
events: [],
|
events: [],
|
||||||
|
exportComponents: [],
|
||||||
fetchedEvents: 0,
|
fetchedEvents: 0,
|
||||||
totalEvents: 0,
|
totalEvents: 0,
|
||||||
processedEvents: 0,
|
processedEvents: 0,
|
||||||
|
|
@ -179,6 +180,22 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
componentForEventForExport(event, forExport) {
|
||||||
|
const comp = this.componentForEvent(event, forExport);
|
||||||
|
const self = this;
|
||||||
|
if (comp) {
|
||||||
|
if (!comp.mixins) {
|
||||||
|
comp.mixins = [];
|
||||||
|
}
|
||||||
|
comp.mixins.push({
|
||||||
|
created: function() {
|
||||||
|
console.error("Created", this.name);
|
||||||
|
self.exportComponents.push(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return comp;
|
||||||
|
},
|
||||||
cancelExport() {
|
cancelExport() {
|
||||||
this.cancelled = true;
|
this.cancelled = true;
|
||||||
},
|
},
|
||||||
|
|
@ -230,6 +247,8 @@ export default {
|
||||||
var currentMediaSize = 0;
|
var currentMediaSize = 0;
|
||||||
var maxMediaSize = 1024 * 1024 * 1024; // 1GB
|
var maxMediaSize = 1024 * 1024 * 1024; // 1GB
|
||||||
|
|
||||||
|
this.exportComponents = [];
|
||||||
|
|
||||||
this.getEvents()
|
this.getEvents()
|
||||||
.then((events) => {
|
.then((events) => {
|
||||||
var decryptionPromises = [];
|
var decryptionPromises = [];
|
||||||
|
|
@ -282,6 +301,8 @@ export default {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.totalEvents = this.exportComponents.length;
|
||||||
|
|
||||||
// UI updated, start processing events
|
// UI updated, start processing events
|
||||||
zip = new JSZip();
|
zip = new JSZip();
|
||||||
var avatarFolder = zip.folder("avatars");
|
var avatarFolder = zip.folder("avatars");
|
||||||
|
|
@ -291,22 +312,8 @@ export default {
|
||||||
var filesFolder = zip.folder("files");
|
var filesFolder = zip.folder("files");
|
||||||
|
|
||||||
var downloadPromises = [];
|
var downloadPromises = [];
|
||||||
let components = this.$refs.exportedEvent;
|
|
||||||
for (const parentComp of components) {
|
|
||||||
let childComponents = [parentComp];
|
|
||||||
|
|
||||||
// Some components, i.e. the media threads, have subcomponents
|
for (const comp of this.exportComponents.filter((c) => c.event != undefined)) {
|
||||||
// that we want to export. So pickup subcomponents here as well.
|
|
||||||
if (parentComp.$refs && parentComp.$refs.exportedEvent) {
|
|
||||||
if (Array.isArray(parentComp.$refs.exportedEvent)) {
|
|
||||||
for (const child of parentComp.$refs.exportedEvent) {
|
|
||||||
childComponents.push(child);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
childComponents.push(parentComp.$refs.exportedEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const comp of childComponents.filter((c) => c.event != undefined)) {
|
|
||||||
// Avatars need downloading?
|
// Avatars need downloading?
|
||||||
if (comp.$el && comp.$el.nodeType == 1) {
|
if (comp.$el && comp.$el.nodeType == 1) {
|
||||||
const avatars = comp.$el.getElementsByClassName("v-avatar");
|
const avatars = comp.$el.getElementsByClassName("v-avatar");
|
||||||
|
|
@ -369,13 +376,15 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let componentClass = comp.$options
|
|
||||||
? comp.$options.__file.split("/").reverse()[0].split(".")[0]
|
|
||||||
: "invalid_component";
|
|
||||||
let attachment =
|
let attachment =
|
||||||
comp.event && comp.event.getId
|
comp.event && comp.event.getId
|
||||||
? this.$matrix.attachmentManager.getEventAttachment(comp.event)
|
? this.$matrix.attachmentManager.getEventAttachment(comp.event)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
let componentClass = comp.$options
|
||||||
|
? comp.$options.__file.split("/").reverse()[0].split(".")[0]
|
||||||
|
: "invalid_component";
|
||||||
|
console.error("Processi", componentClass, comp.event, comp.originalEvent, attachment);
|
||||||
|
|
||||||
|
|
||||||
if (attachment && (attachment.srcSize = 0 || currentMediaSize + attachment.srcSize <= maxMediaSize)) {
|
if (attachment && (attachment.srcSize = 0 || currentMediaSize + attachment.srcSize <= maxMediaSize)) {
|
||||||
downloadPromises.push(
|
downloadPromises.push(
|
||||||
|
|
@ -472,7 +481,6 @@ export default {
|
||||||
this.processedEvents += 1;
|
this.processedEvents += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Promise.all(downloadPromises);
|
return Promise.all(downloadPromises);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,6 @@ import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk";
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const $matrix: any = inject("globalMatrix");
|
const $matrix: any = inject("globalMatrix");
|
||||||
|
|
||||||
type RootType = InstanceType<typeof MessageOutgoing | typeof MessageIncoming>;
|
|
||||||
const rootRef = useTemplateRef<RootType>("root");
|
|
||||||
|
|
||||||
const emits = defineEmits<
|
const emits = defineEmits<
|
||||||
MessageEmits & { (event: "layout-change", value: { element: Element | undefined; action: () => void }): void }
|
MessageEmits & { (event: "layout-change", value: { element: Element | undefined; action: () => void }): void }
|
||||||
>();
|
>();
|
||||||
|
|
@ -44,8 +41,7 @@ const props = defineProps<MessageProps>();
|
||||||
|
|
||||||
const processThread = () => {
|
const processThread = () => {
|
||||||
if (!event.value?.isRedacted()) {
|
if (!event.value?.isRedacted()) {
|
||||||
const el = rootRef.value?.$el;
|
_processThread();
|
||||||
emits("layout-change", { element: el, action: _processThread });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -149,9 +149,10 @@ export class AttachmentManager {
|
||||||
attachment.loadSrc = (options?: EventAttachmentLoadSrcOptions) => {
|
attachment.loadSrc = (options?: EventAttachmentLoadSrcOptions) => {
|
||||||
if (attachment.src && !options?.asBlob) {
|
if (attachment.src && !options?.asBlob) {
|
||||||
return Promise.resolve({data: attachment.src, type: "src"});
|
return Promise.resolve({data: attachment.src, type: "src"});
|
||||||
} else if (attachment.srcPromise) {
|
} else if (attachment.srcPromise && !options?.asBlob) {
|
||||||
return attachment.srcPromise;
|
return attachment.srcPromise;
|
||||||
}
|
}
|
||||||
|
Implement loadBlob somewhere here!
|
||||||
attachment.srcPromise = this._loadEventAttachmentOrThumbnail(event, false, !!options?.asBlob, (percent) => {
|
attachment.srcPromise = this._loadEventAttachmentOrThumbnail(event, false, !!options?.asBlob, (percent) => {
|
||||||
attachment.srcProgress = percent;
|
attachment.srcProgress = percent;
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue