import { Message } from '@ably/chat'; /** Props for the useMessageWindow hook */ export interface UseMessageWindowProps { /** Number of rows kept mounted (ex‑overscan). Defaults to 200 */ windowSize?: number; /** Extra rows rendered above & below the viewport. Defaults to 20 */ overscan?: number; /** historyBatchSize - Number of messages to fetch in a single history request. Defaults to 300 */ historyBatchSize?: number; } /** Response interface for the useMessageWindow hook */ export interface UseMessageWindowResponse { /** Messages that should be rendered in the UI */ activeMessages: Message[]; /** Add or update messages */ updateMessages: (messages: Message[], prepend?: boolean) => void; /** Jump to the latest message */ showLatestMessages: () => void; /** Scroll by ±delta rows (positive = newer) */ scrollBy: (delta: number) => void; /** Centre the window on a specific message serial */ showMessagesAroundSerial: (serial: string) => void; /** `true` while a history query is running */ loading: boolean; /** `true` if their are more messages that can be fetched from history*/ hasMoreHistory: boolean; /** Triggers another history fetch from the point of the earliest message*/ loadMoreHistory: () => Promise; } /** * A React hook to manage message windowing and history for chat. * * This hook manages a virtualized window of messages from a larger chat history, providing efficient * rendering for large conversations. * * - Must be used within a `ChatRoomProvider` component. * * * Features: * - *Virtualized Windowing*: Exposes a subset of the total messages in memory for efficient rendering * - *Realtime updates*: Automatically handles new messages, edits, deletions, and reactions. * - *History Pagination*: Loads older messages on demand with configurable batch sizes. * - *Discontinuity Recovery*: Automatically recovers missing messages after network disruptions. * - *Navigation Controls*: Jump to latest, scroll by delta, or center on specific messages * * @param opts - Configuration options for the message window * @returns Hook interface with message data and control methods * * * @example * // Basic usage * function AdvancedChatRoom() { * const { * activeMessages, * updateMessages, * scrollBy, * showMessagesAroundSerial, * loadMoreHistory, * hasMoreHistory, * loading * } = useMessageWindow({ * windowSize: 100, // Smaller window for better performance * }); * * const handleJumpToMessage = (messageSerial: string) => { * showMessagesAroundSerial(messageSerial); * }; * * const handleScrollUp = () => { * scrollBy(-10); // Scroll 10 messages toward older * }; * * const handleScrollDown = () => { * scrollBy(10); // Scroll 10 messages toward newer * }; * * return ( * *
*
* * * {hasMoreHistory && ( * * )} *
* *
* {activeMessages.map(msg => ( * handleJumpToMessage(msg.serial)} * /> * ))} *
*
*
* ); * } * */ export declare const useMessageWindow: ({ windowSize, overscan, historyBatchSize, }?: UseMessageWindowProps) => UseMessageWindowResponse;