{"version":3,"file":"MessageContext.mjs","names":[],"sources":["../../../src/context/MessageContext.tsx"],"sourcesContent":["import type { PropsWithChildren } from 'react';\nimport React, { useContext } from 'react';\n\nimport type {\n  DeleteMessageOptions,\n  LocalMessage,\n  ReactionResponse,\n  SortParamRequest,\n  UserResponse,\n} from 'stream-chat';\n\nimport type { ActionHandlerReturnType } from '../components/Message/hooks/useActionHandler';\nimport type { ReactEventHandler } from '../components/Message/types';\nimport type { GroupStyle } from '../components/MessageList/utils';\nimport type { ReactionsComparator, ReactionType } from '../components/Reactions/types';\n\nimport type { RenderTextFunction } from '../components/Message/renderText';\nimport { requireContext } from './requireContext';\n\nexport type MessageContextValue = {\n  /** Sends a message action. A returned message is ingested; otherwise the local one is removed. */\n  handleAction: ActionHandlerReturnType;\n  handleDelete: (options?: DeleteMessageOptions) => Promise<void> | void;\n  /** Fetches the message reactions, optionally of one type and sorted. */\n  handleFetchReactions: (\n    reactionType?: ReactionType,\n    sort?: SortParamRequest[],\n  ) => Promise<Array<ReactionResponse>>;\n  handleFlag: ReactEventHandler;\n  /** Marks the message and the messages that follow it as unread. */\n  handleMarkUnread: ReactEventHandler;\n  handleMute: ReactEventHandler;\n  /** Opens the message's thread: the `openThread` prop of `Message`, else ChatView navigation. */\n  handleOpenThread: ReactEventHandler;\n  /** Pins or unpins the message. Rejects with the request's error when it fails, after rolling back. */\n  handlePin: ReactEventHandler;\n  handleReaction: (\n    reactionType: string,\n    event: React.BaseSyntheticEvent,\n  ) => Promise<void>;\n  handleRetry: (message: LocalMessage) => Promise<void> | void;\n  isMyMessage: () => boolean;\n  message: LocalMessage;\n  /** Click handler for an @mention in the message; `undefined` when no `onMentionsClick` handler is set. */\n  onMentionsClickMessage?: ReactEventHandler;\n  /** Hover handler for an @mention in the message; `undefined` when no `onMentionsHover` handler is set. */\n  onMentionsHoverMessage?: ReactEventHandler;\n  /** Click handler for the user who posted the message. */\n  onUserClick: ReactEventHandler;\n  /** Hover handler for the user who posted the message. */\n  onUserHover: ReactEventHandler;\n  /**\n   * Keeps the message list scrolled to the bottom when the scroll height grows, e.g. when an\n   * element appears below the last message. Only used in the `VirtualizedMessageList`.\n   */\n  autoscrollToBottom?: () => void;\n  /** If true, picking a reaction in the `ReactionSelector` closes the selector. */\n  closeReactionSelectorOnClick?: boolean;\n  /** Users that have confirmed the message delivery to their device. */\n  deliveredTo?: UserResponse[];\n  /** Overrides the date formatting. Receives the original date and returns a string. */\n  formatDate?: (date: Date) => string;\n  /**\n   * The message's position in its group of consecutive messages from one user: `top`, `middle`,\n   * `bottom` or `single`. The message lists add it to the list item as `str-chat__li--<style>`\n   * (unless `customClasses.message` or `customClasses.virtualMessage` replaces the item's class),\n   * which the default CSS uses to hide the metadata and avatar of `top` and `middle` messages.\n   */\n  groupStyles?: GroupStyle[];\n  /** Whether to highlight the message. The message lists set it on the focused message. */\n  highlighted?: boolean;\n  /** Whether a message is AI generated. */\n  isMessageAIGenerated?: (message: LocalMessage) => boolean;\n  /** Latest own message in the currently displayed message set. */\n  lastOwnMessage?: LocalMessage;\n  /** ID of the last rendered message with status `received`. */\n  lastReceivedId?: string | null;\n  /** DOMRect of the parent MessageList wrapper. */\n  messageListRect?: DOMRect;\n  /** Sort options for the reactions query. */\n  reactionDetailsSort?: SortParamRequest[];\n  /**\n   * Users that have read this message. Only filled for the last own message unless\n   * `returnAllReadData` is set.\n   */\n  readBy?: UserResponse[];\n  /**\n   * Which messages use the grid layout with an avatar column. Defaults to `'incoming'`.\n   * - `true`: incoming and outgoing messages\n   * - `'incoming'`: only messages from other users\n   * - `'outgoing'`: only own messages\n   * - `false`: none\n   */\n  showAvatar?: boolean | 'incoming' | 'outgoing';\n  /** Custom function to render the message text. Defaults to `renderText`. */\n  renderText?: RenderTextFunction;\n  /**\n   * If true, delivery and read receipts are tracked for every own message, otherwise only for the\n   * last one.\n   */\n  returnAllReadData?: boolean;\n  /** Comparator to sort reactions. Defaults to first reaction time if both have one, else type. */\n  sortReactions?: ReactionsComparator;\n  /**\n   * Renders `message.html` instead of the Markdown text. Only server-side code can set\n   * `message.html`. It is inserted unescaped, so enable this only for HTML your server trusts or\n   * sanitizes: script in it runs in the app with the current user's session.\n   */\n  unsafeHTML?: boolean;\n  /**\n   * Which text a translated message shows, for this user only: `'original'` is `message.text`,\n   * `'translated'` is the translation for the user language, falling back to `message.text`.\n   */\n  translationView?: 'original' | 'translated';\n  /** Sets whether this message shows the original or translated text, for this user only. */\n  setTranslationView?: (view: 'original' | 'translated') => void;\n};\n\nexport const MessageContext = React.createContext<MessageContextValue | undefined>(\n  undefined,\n);\n\nexport const MessageProvider = ({\n  children,\n  value,\n}: PropsWithChildren<{\n  value: MessageContextValue;\n}>) => (\n  <MessageContext.Provider value={value as unknown as MessageContextValue}>\n    {children}\n  </MessageContext.Provider>\n);\n\nexport const useMessageContext = () =>\n  requireContext(useContext(MessageContext), 'useMessageContext', 'MessageProvider');\n"],"mappings":";;;;AAsHA,IAAa,iBAAiB,MAAM,cAClC,KAAA,CACF;AAEA,IAAa,mBAAmB,EAC9B,UACA,YAIA,oBAAC,eAAe,UAAhB;CAAgC;CAC7B;AACsB,CAAA;AAG3B,IAAa,0BACX,eAAe,WAAW,cAAc,GAAG,qBAAqB,iBAAiB"}