import React, { PropsWithChildren, useContext, MutableRefObject, RefObject, } from 'react'; import { Conversation, Message } from '@tencentcloud/chat'; import { MessageListProps, TUIMessageInputBasicProps, TUIMessageProps } from '../components'; import { OperateMessageParams } from '../components/TUIChat/hooks/useHandleMessage'; export interface TUIChatStateContextValue { conversation?: Conversation, messageList?: Array, nextReqMessageID?: string, isCompleted?: boolean, init?: boolean, highlightedMessageId?: string, lastMessageID?:string, isSameLastMessageID?: boolean, messageListRef?: RefObject, textareaRef?: MutableRefObject, operateData?: OperateMessageParams, noMore?: boolean, messageConfig?: TUIMessageProps, cloudCustomData?: string, TUIMessageInputConfig?: TUIMessageInputBasicProps, audioSource?: HTMLAudioElement, vidoeSource?: HTMLVideoElement, TUIMessageListConfig?: MessageListProps, uploadPendingMessageList?: Array, } export const TUIChatStateContext = React.createContext(null); export function TUIChatStateContextProvider({ children, value }:PropsWithChildren<{ value: TUIChatStateContextValue }>):React.ReactElement { return ( {children} ); } export function useTUIChatStateContext(componentName?:string) :TUIChatStateContextValue { const contextValue = useContext(TUIChatStateContext); if (!contextValue && componentName) { return {} as TUIChatStateContextValue; } return (contextValue as unknown) as TUIChatStateContextValue; }