stream-chat
Version:
JS SDK for the Stream Chat API
46 lines (45 loc) • 1.72 kB
TypeScript
import type { StreamChat } from './client';
import { StateStore } from './store';
import type { AttachmentManager } from '.';
export type UploadRecord = {
id: string;
uploadProgress?: number;
};
export type UploadManagerState = {
uploads: Record<string, UploadRecord>;
};
/**
* @internal
*/
export declare class UploadManager {
private readonly client;
readonly state: StateStore<UploadManagerState>;
private inFlightUploads;
constructor(client: StreamChat);
private resolveAttachmentManager;
get uploads(): Record<string, UploadRecord>;
getUpload: (id: string) => UploadRecord;
/**
* Clears all upload records.
* Invoked when the user disconnects so a later session does not inherit stale upload state.
* Aborts every in-flight upload request via its `UploadRequestOptions.abortSignal`.
*/
reset: () => void;
/**
* Removes the upload record for `id` if present.
* If an upload is still in progress, aborts its `UploadRequestOptions.abortSignal`.
*/
deleteUploadRecord: (id: string) => void;
/**
* Starts an upload for `id`, or returns the existing in-flight promise if one is already running.
* Uses {@link StreamChat.channel}(`channelCid`) → `messageComposer.attachmentManager.doUploadRequest`.
* Resolves with that result; rejects if the upload rejects (the record is removed from state either way).
*/
upload: ({ id, channelCid, file, }: {
id: string;
channelCid: string;
file: Parameters<typeof AttachmentManager.prototype.doUploadRequest>[0];
}) => ReturnType<typeof AttachmentManager.prototype.doUploadRequest>;
private upsertUpload;
private updateUpload;
}