UNPKG

stream-chat

Version:

JS SDK for the Stream Chat API

160 lines (159 loc) 7.89 kB
import { AttachmentManager } from './attachmentManager'; import { CustomDataManager } from './CustomDataManager'; import { LinkPreviewsManager } from './linkPreviewsManager'; import { LocationComposer } from './LocationComposer'; import { PollComposer } from './pollComposer'; import { TextComposer } from './textComposer'; import type { MessageComposerMiddlewareValue } from './middleware'; import { MessageComposerMiddlewareExecutor, MessageDraftComposerMiddlewareExecutor } from './middleware'; import type { Unsubscribe } from '../store'; import { StateStore } from '../store'; import { generateUUIDv4 } from '../utils'; import { Channel } from '../channel'; import { Thread } from '../thread'; import type { ChannelAPIResponse, CommandResponse, DraftResponse, LocalMessage, LocalMessageBase, MessageResponse } from '../types'; import { WithSubscriptions } from '../utils/WithSubscriptions'; import type { StreamChat } from '../client'; import type { MessageComposerConfig } from './configuration/types'; import type { CommandSuggestionDisabledReason, TextComposerCommandActivationEffect, TextComposerCommandClearEffect } from './middleware/textComposer/types'; import type { AttachmentManagerSnapshot } from './attachmentManager'; import type { CustomDataManagerSnapshot } from './CustomDataManager'; import type { LinkPreviewsManagerSnapshot } from './linkPreviewsManager'; import type { LocationComposerSnapshot } from './LocationComposer'; import type { PollComposerSnapshot } from './pollComposer'; import type { TextComposerSnapshot } from './textComposer'; import type { DeepPartial } from '../types.utility'; type UnregisterSubscriptions = Unsubscribe; export type LastComposerChange = { draftUpdate: number | null; stateUpdate: number; }; export type EditingAuditState = { lastChange: LastComposerChange; }; export type BuiltInMessageComposerEffect = TextComposerCommandActivationEffect | TextComposerCommandClearEffect; export type CustomMessageComposerEffect = { type: string & {}; } & Record<string, unknown>; export type MessageComposerEffect = BuiltInMessageComposerEffect | CustomMessageComposerEffect; export type MessageComposerEffectHandler<T extends { type: string; } = MessageComposerEffect> = (effect: T, composer: MessageComposer) => void; export type MessageComposerSnapshot = { attachmentManager: AttachmentManagerSnapshot; customDataManager: CustomDataManagerSnapshot; linkPreviewsManager: LinkPreviewsManagerSnapshot; locationComposer: LocationComposerSnapshot; pollComposer: PollComposerSnapshot; textComposer: TextComposerSnapshot; }; export type LocalMessageWithLegacyThreadId = LocalMessage & { legacyThreadId?: string; }; export type CompositionContext = Channel | Thread | LocalMessageWithLegacyThreadId; export type MessageComposerState = { id: string; draftId: string | null; pollId: string | null; quotedMessage: LocalMessageBase | null; showReplyInChannel: boolean; /** * Baseline snapshot of the message being edited (if any). * This is intentionally immutable with respect to the editing session and can be used for restore/cancel. */ editedMessage: LocalMessage | null; }; export type MessageComposerOptions = { client: StreamChat; compositionContext: CompositionContext; composition?: DraftResponse | MessageResponse | LocalMessage; config?: DeepPartial<MessageComposerConfig>; }; export declare class MessageComposer extends WithSubscriptions { readonly channel: Channel; readonly state: StateStore<MessageComposerState>; readonly editingAuditState: StateStore<EditingAuditState>; readonly configState: StateStore<MessageComposerConfig>; readonly compositionContext: CompositionContext; readonly compositionMiddlewareExecutor: MessageComposerMiddlewareExecutor; readonly draftCompositionMiddlewareExecutor: MessageDraftComposerMiddlewareExecutor; attachmentManager: AttachmentManager; linkPreviewsManager: LinkPreviewsManager; textComposer: TextComposer; pollComposer: PollComposer; locationComposer: LocationComposer; customDataManager: CustomDataManager; private snapshots; private effectHandlers; constructor({ composition, config, compositionContext, client, }: MessageComposerOptions); static evaluateContextType(compositionContext: CompositionContext): "message" | "channel" | "thread" | "legacy_thread"; static constructTag(compositionContext: CompositionContext): `${ReturnType<typeof MessageComposer.evaluateContextType>}_${string}`; static generateId: typeof generateUUIDv4; get config(): MessageComposerConfig; get editedMessage(): LocalMessage | undefined; set editedMessage(editedMessage: LocalMessage | undefined); setEditedMessage: (editedMessage: LocalMessage | null | undefined) => void; get contextType(): "message" | "channel" | "thread" | "legacy_thread"; get tag(): `message_${string}` | `channel_${string}` | `thread_${string}` | `legacy_thread_${string}`; get threadId(): string | null; get client(): StreamChat; get id(): string; get draftId(): string | null; get lastChange(): LastComposerChange; get quotedMessage(): LocalMessageBase | null; getCommandDisabledReason: (command: CommandResponse) => CommandSuggestionDisabledReason | undefined; isCommandDisabled: (command: CommandResponse) => boolean; get pollId(): string | null; get showReplyInChannel(): boolean; get hasSendableData(): boolean; get compositionIsEmpty(): boolean; get contentIsEmpty(): boolean; get lastChangeOriginIsLocal(): boolean; updateConfig(config: DeepPartial<MessageComposerConfig>): void; refreshId: () => void; initState: ({ composition, }?: { composition?: DraftResponse | MessageResponse | LocalMessage; }) => void; initStateFromChannelResponse: (channelApiResponse: ChannelAPIResponse) => void; initEditingAuditState: (composition?: DraftResponse | MessageResponse | LocalMessage) => EditingAuditState; clearSnapshots: () => void; getSnapshot: () => MessageComposerSnapshot; restoreSnapshot: (snapshot: MessageComposerSnapshot) => void; captureSnapshot: (snapshot?: MessageComposerSnapshot) => void; popSnapshot: () => MessageComposerSnapshot | undefined; registerEffectHandler: <T extends { type: string; }>(type: T["type"], handler: MessageComposerEffectHandler<T>) => void; applyEffects: <T extends { type: string; }>(effects?: T[]) => void; private logStateUpdateTimestamp; private logDraftUpdateTimestamp; registerDraftEventSubscriptions: () => () => void; registerSubscriptions: () => UnregisterSubscriptions; private subscribeMessageUpdated; private subscribeMessageComposerSetupStateChange; private subscribeMessageDeleted; private subscribeDraftUpdated; private subscribeDraftDeleted; private subscribeTextComposerStateChanged; private subscribeAttachmentManagerStateChanged; private subscribeLocationComposerStateChanged; private subscribeLinkPreviewsManagerStateChanged; private subscribePollComposerStateChanged; private subscribeCustomDataManagerStateChanged; private subscribeMessageComposerStateChanged; private subscribeMessageComposerConfigStateChanged; setQuotedMessage: (quotedMessage: LocalMessage | null) => void; toggleShowReplyInChannel: () => void; clear: () => void; restore: () => void; compose: () => Promise<MessageComposerMiddlewareValue["state"] | undefined>; composeDraft: () => Promise<import("./middleware").MessageDraftComposerMiddlewareValueState | undefined>; createDraft: () => Promise<void>; deleteDraft: () => Promise<void>; getDraft: () => Promise<void>; createPoll: () => Promise<void>; sendLocation: () => Promise<void>; } export {};