import { ComputedRef, Ref } from "vue"; export class UploadPromise { wrappedPromise: Promise; aborted: boolean = false; onAbort: (() => void) | undefined = undefined; constructor(wrappedPromise: Promise) { 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 | undefined; randomRotation: number; // For UI effects randomTranslationX: number; // For UI effects randomTranslationY: number; // For UI effects }; export type Attachment = { status: "loading" | "loaded"; file: File; dimensions?: { width: number; height: number }; scaledFile?: File; scaledDimensions?: { width: number; height: number }; useScaled: boolean; src?: string; proof?: any; sendInfo?: AttachmentSendInfo; }; export type AttachmentBatch = { sendingStatus: Ref<"initial" | "sending" | "sent" | "canceled" | "failed">; sendingRootEventId: Ref; sendingPromise: Ref | undefined>; attachments: Ref; attachmentsSentCount: ComputedRef; attachmentsSending: ComputedRef; attachmentsSent: ComputedRef; addAttachment: (attachment: Attachment) => void; removeAttachment: (attachment: Attachment) => void; send: (message: string) => Promise; cancel: () => void; cancelSendAttachment: (attachment: Attachment) => void; };