{"version":3,"file":"useTypingUsers.mjs","names":[],"sources":["../../../../../src/components/TypingIndicator/hooks/useTypingUsers.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { Channel, ChannelConfig, ChannelStateData } from 'stream-chat';\n\nimport { useChatContext } from '../../../context/ChatContext';\nimport { useStateStore } from '../../../store';\nimport type { TypingEntry } from './useDebouncedTypingActive';\n\nconst typingEventsStateSelector = ({ typingEvents }: ChannelConfig) => ({\n  typingEventsEnabled: typingEvents.enabled,\n});\n\nconst channelTypingSelector = ({ typing }: ChannelStateData) => ({ typing });\n\n/**\n * The other users typing in `channel`: in its main list, or, with `parentId`, in the replies of that\n * thread. Empty while the channel's `typingEvents.enabled` is false.\n */\nexport const useTypingUsers = (channel: Channel, parentId?: string): TypingEntry[] => {\n  const { client } = useChatContext();\n  const ownUserId = client.user?.id;\n  const { typingEventsEnabled } = useStateStore(\n    channel.configState,\n    typingEventsStateSelector,\n  );\n  const { typing } = useStateStore(channel.state, channelTypingSelector);\n\n  return useMemo(() => {\n    if (typingEventsEnabled === false) return [];\n    const isInList = ({ parent_id }: TypingEntry) =>\n      parentId ? parent_id === parentId : !parent_id;\n    return (Object.values(typing) as TypingEntry[]).filter(\n      (entry) => entry.user?.id !== ownUserId && isInList(entry),\n    );\n  }, [ownUserId, parentId, typing, typingEventsEnabled]);\n};\n"],"mappings":";;;;AAOA,IAAM,6BAA6B,EAAE,oBAAmC,EACtE,qBAAqB,aAAa,QACpC;AAEA,IAAM,yBAAyB,EAAE,cAAgC,EAAE,OAAO;;;;;AAM1E,IAAa,kBAAkB,SAAkB,aAAqC;CACpF,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,YAAY,OAAO,MAAM;CAC/B,MAAM,EAAE,wBAAwB,cAC9B,QAAQ,aACR,yBACF;CACA,MAAM,EAAE,WAAW,cAAc,QAAQ,OAAO,qBAAqB;CAErE,OAAO,cAAc;EACnB,IAAI,wBAAwB,OAAO,OAAO,CAAC;EAC3C,MAAM,YAAY,EAAE,gBAClB,WAAW,cAAc,WAAW,CAAC;EACvC,OAAQ,OAAO,OAAO,MAAM,CAAC,CAAmB,QAC7C,UAAU,MAAM,MAAM,OAAO,aAAa,SAAS,KAAK,CAC3D;CACF,GAAG;EAAC;EAAW;EAAU;EAAQ;CAAmB,CAAC;AACvD"}