import { ComputedRef, Ref } from "vue"; import { Proof, MediaMetadata } from "./proof"; 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 AttachmentThumbnail = { data: Uint8Array; mimetype: string; size: number; w: number; h: number; } export type Attachment = { status: "loading" | "loaded"; file: File; dimensions?: { width: number; height: number }; compressedFile?: File; compressedDimensions?: { width: number; height: number }; useCompressed: boolean; src?: string; proof?: Proof; mediaMetadata?: MediaMetadata; thumbnail?: AttachmentThumbnail; detailsViewed: boolean; sendInfo: AttachmentSendInfo; }; export type AttachmentBatch = { sendingStatus: Ref; sendingRootEventId: Ref; sendingRootMessage: Ref; progressPercent: Ref; attachments: Attachment[]; attachmentsSentCount: ComputedRef; attachmentsSending: ComputedRef; attachmentsSent: ComputedRef; addFiles: (files: File[]) => void; removeAttachment: (attachment: Attachment) => void; isTooLarge: (attachment: Attachment) => boolean; canSend: ComputedRef; send: (message: string) => Promise; cancel: () => void; cancelSendAttachment: (attachment: Attachment) => void; };