2025-06-11 14:59:34 +02:00
|
|
|
import { ComputedRef, Ref } from "vue";
|
2025-07-04 12:51:57 +02:00
|
|
|
import { Proof } from "./proof";
|
2025-06-11 14:59:34 +02:00
|
|
|
|
2025-06-09 09:44:37 +02:00
|
|
|
export class UploadPromise<Type> {
|
|
|
|
|
wrappedPromise: Promise<Type>;
|
|
|
|
|
aborted: boolean = false;
|
|
|
|
|
onAbort: (() => void) | undefined = undefined;
|
|
|
|
|
|
|
|
|
|
constructor(wrappedPromise: Promise<Type>) {
|
|
|
|
|
this.wrappedPromise = wrappedPromise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abort() {
|
|
|
|
|
this.aborted = true;
|
|
|
|
|
if (this.onAbort) {
|
|
|
|
|
this.onAbort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
then(resolve: any, reject: any) {
|
|
|
|
|
this.wrappedPromise = this.wrappedPromise.then(resolve, reject);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch(handler: any) {
|
|
|
|
|
this.wrappedPromise = this.wrappedPromise.catch(handler);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type AttachmentSendStatus = "initial" | "sending" | "sent" | "canceled" | "failed";
|
|
|
|
|
|
|
|
|
|
export type AttachmentSendInfo = {
|
|
|
|
|
status: AttachmentSendStatus;
|
|
|
|
|
statusDate: number; //ms
|
|
|
|
|
mediaEventId: string | undefined;
|
|
|
|
|
progress: number;
|
|
|
|
|
promise: UploadPromise<string> | undefined;
|
|
|
|
|
randomRotation: number; // For UI effects
|
|
|
|
|
randomTranslationX: number; // For UI effects
|
|
|
|
|
randomTranslationY: number; // For UI effects
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-10 09:46:07 +02:00
|
|
|
export type AttachmentThumbnail = {
|
|
|
|
|
data: Uint8Array;
|
|
|
|
|
mimetype: string;
|
|
|
|
|
size: number;
|
|
|
|
|
w: number;
|
|
|
|
|
h: number;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-09 09:44:37 +02:00
|
|
|
export type Attachment = {
|
|
|
|
|
status: "loading" | "loaded";
|
|
|
|
|
file: File;
|
|
|
|
|
dimensions?: { width: number; height: number };
|
|
|
|
|
scaledFile?: File;
|
|
|
|
|
scaledDimensions?: { width: number; height: number };
|
|
|
|
|
useScaled: boolean;
|
|
|
|
|
src?: string;
|
2025-07-04 12:51:57 +02:00
|
|
|
proof?: Proof;
|
2025-06-09 09:44:37 +02:00
|
|
|
sendInfo?: AttachmentSendInfo;
|
2025-07-10 09:46:07 +02:00
|
|
|
thumbnail?: AttachmentThumbnail;
|
2025-06-09 09:44:37 +02:00
|
|
|
};
|
2025-06-11 14:59:34 +02:00
|
|
|
|
|
|
|
|
export type AttachmentBatch = {
|
|
|
|
|
sendingStatus: Ref<"initial" | "sending" | "sent" | "canceled" | "failed">;
|
|
|
|
|
sendingRootEventId: Ref<string | undefined>;
|
|
|
|
|
sendingPromise: Ref<Promise<any> | undefined>;
|
|
|
|
|
attachments: Ref<Attachment[]>;
|
|
|
|
|
attachmentsSentCount: ComputedRef<number>;
|
|
|
|
|
attachmentsSending: ComputedRef<Attachment[]>;
|
|
|
|
|
attachmentsSent: ComputedRef<Attachment[]>;
|
2025-07-17 11:22:26 +02:00
|
|
|
addAttachments: (attachments: Attachment[]) => void;
|
2025-06-11 14:59:34 +02:00
|
|
|
removeAttachment: (attachment: Attachment) => void;
|
2025-06-11 18:04:56 +02:00
|
|
|
isTooLarge: (attachment: Attachment) => boolean;
|
|
|
|
|
canSend: ComputedRef<boolean>;
|
2025-06-11 14:59:34 +02:00
|
|
|
send: (message: string) => Promise<any>;
|
|
|
|
|
cancel: () => void;
|
|
|
|
|
cancelSendAttachment: (attachment: Attachment) => void;
|
|
|
|
|
};
|
|
|
|
|
|