mirror of
https://github.com/element-hq/element-web.git
synced 2024-12-14 04:40:28 +03:00
Add return types to ABC Exporter
This commit is contained in:
parent
637e3afa48
commit
3fc4be0be9
1 changed files with 13 additions and 13 deletions
|
@ -35,12 +35,12 @@ export default abstract class Exporter {
|
||||||
window.addEventListener("onunload", this.abortWriter);
|
window.addEventListener("onunload", this.abortWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onBeforeUnload(e: BeforeUnloadEvent) {
|
protected onBeforeUnload(e: BeforeUnloadEvent): string {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return e.returnValue = "Are you sure you want to exit during this export?";
|
return e.returnValue = "Are you sure you want to exit during this export?";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected addFile(filePath: string, blob: Blob) {
|
protected addFile(filePath: string, blob: Blob): void {
|
||||||
const file = {
|
const file = {
|
||||||
name: filePath,
|
name: filePath,
|
||||||
stream: () => blob.stream(),
|
stream: () => blob.stream(),
|
||||||
|
@ -48,7 +48,7 @@ export default abstract class Exporter {
|
||||||
this.files.push(file);
|
this.files.push(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async downloadZIP() {
|
protected async downloadZIP(): Promise<any> {
|
||||||
const filename = `matrix-export-${formatFullDateNoDay(new Date())}.zip`;
|
const filename = `matrix-export-${formatFullDateNoDay(new Date())}.zip`;
|
||||||
|
|
||||||
// Support for older browsers
|
// Support for older browsers
|
||||||
|
@ -78,14 +78,14 @@ export default abstract class Exporter {
|
||||||
await this.pumpToFileStream(reader);
|
await this.pumpToFileStream(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected cleanUp() {
|
protected cleanUp(): string {
|
||||||
console.log("Cleaning up...");
|
console.log("Cleaning up...");
|
||||||
window.removeEventListener("beforeunload", this.onBeforeUnload);
|
window.removeEventListener("beforeunload", this.onBeforeUnload);
|
||||||
window.removeEventListener("onunload", this.abortWriter);
|
window.removeEventListener("onunload", this.abortWriter);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public async cancelExport() {
|
public async cancelExport(): Promise<void> {
|
||||||
console.log("Cancelling export...");
|
console.log("Cancelling export...");
|
||||||
this.cancelled = true;
|
this.cancelled = true;
|
||||||
await this.abortWriter();
|
await this.abortWriter();
|
||||||
|
@ -105,7 +105,7 @@ export default abstract class Exporter {
|
||||||
await this.writer?.abort();
|
await this.writer?.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async pumpToFileStream(reader: ReadableStreamDefaultReader) {
|
protected async pumpToFileStream(reader: ReadableStreamDefaultReader): Promise<void> {
|
||||||
const res = await reader.read();
|
const res = await reader.read();
|
||||||
if (res.done) await this.writer.close();
|
if (res.done) await this.writer.close();
|
||||||
else {
|
else {
|
||||||
|
@ -114,7 +114,7 @@ export default abstract class Exporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected setEventMetadata(event: MatrixEvent) {
|
protected setEventMetadata(event: MatrixEvent): MatrixEvent {
|
||||||
const roomState = this.client.getRoom(this.room.roomId).currentState;
|
const roomState = this.client.getRoom(this.room.roomId).currentState;
|
||||||
event.sender = roomState.getSentinelMember(
|
event.sender = roomState.getSentinelMember(
|
||||||
event.getSender(),
|
event.getSender(),
|
||||||
|
@ -127,7 +127,7 @@ export default abstract class Exporter {
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getLimit() {
|
protected getLimit(): number {
|
||||||
let limit: number;
|
let limit: number;
|
||||||
switch (this.exportType) {
|
switch (this.exportType) {
|
||||||
case exportTypes.LAST_N_MESSAGES:
|
case exportTypes.LAST_N_MESSAGES:
|
||||||
|
@ -195,7 +195,7 @@ export default abstract class Exporter {
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getMediaBlob(event: MatrixEvent) {
|
protected async getMediaBlob(event: MatrixEvent): Promise<Blob> {
|
||||||
let blob: Blob;
|
let blob: Blob;
|
||||||
try {
|
try {
|
||||||
const isEncrypted = event.isEncrypted();
|
const isEncrypted = event.isEncrypted();
|
||||||
|
@ -215,7 +215,7 @@ export default abstract class Exporter {
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected splitFileName(file: string) {
|
protected splitFileName(file: string): string[] {
|
||||||
const lastDot = file.lastIndexOf('.');
|
const lastDot = file.lastIndexOf('.');
|
||||||
if (lastDot === -1) return [file, ""];
|
if (lastDot === -1) return [file, ""];
|
||||||
const fileName = file.slice(0, lastDot);
|
const fileName = file.slice(0, lastDot);
|
||||||
|
@ -223,7 +223,7 @@ export default abstract class Exporter {
|
||||||
return [fileName, '.' + ext];
|
return [fileName, '.' + ext];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getFilePath(event: MatrixEvent) {
|
protected getFilePath(event: MatrixEvent): string {
|
||||||
const mediaType = event.getContent().msgtype;
|
const mediaType = event.getContent().msgtype;
|
||||||
let fileDirectory: string;
|
let fileDirectory: string;
|
||||||
switch (mediaType) {
|
switch (mediaType) {
|
||||||
|
@ -245,7 +245,7 @@ export default abstract class Exporter {
|
||||||
return fileDirectory + "/" + fileName + '-' + fileDate + fileExt;
|
return fileDirectory + "/" + fileName + '-' + fileDate + fileExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isReply(event: MatrixEvent) {
|
protected isReply(event: MatrixEvent): boolean {
|
||||||
const isEncrypted = event.isEncrypted();
|
const isEncrypted = event.isEncrypted();
|
||||||
// If encrypted, in_reply_to lies in event.event.content
|
// If encrypted, in_reply_to lies in event.event.content
|
||||||
const content = isEncrypted ? event.event.content : event.getContent();
|
const content = isEncrypted ? event.event.content : event.getContent();
|
||||||
|
@ -253,7 +253,7 @@ export default abstract class Exporter {
|
||||||
return !!(relatesTo && relatesTo["m.in_reply_to"]);
|
return !!(relatesTo && relatesTo["m.in_reply_to"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected isAttachment(mxEv: MatrixEvent) {
|
protected isAttachment(mxEv: MatrixEvent): boolean {
|
||||||
const attachmentTypes = ["m.sticker", "m.image", "m.file", "m.video", "m.audio"];
|
const attachmentTypes = ["m.sticker", "m.image", "m.file", "m.video", "m.audio"];
|
||||||
return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype);
|
return mxEv.getType() === attachmentTypes[0] || attachmentTypes.includes(mxEv.getContent().msgtype);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue