{"version":3,"file":"useChannelHasMembersOnline.mjs","names":[],"sources":["../../../../../src/components/ChannelHeader/hooks/useChannelHasMembersOnline.ts"],"sourcesContent":["import type { Channel, ChannelWatchState } from 'stream-chat';\n\nimport { useChannel } from '../../../context';\nimport { useChatContext } from '../../../context/ChatContext';\nimport { useStateStore } from '../../../store';\n\nexport type UseChannelHasMembersOnlineParams = {\n  channel?: Channel;\n  enabled?: boolean;\n};\n\nconst watchersSelector = (nextValue: ChannelWatchState) => ({\n  watchers: nextValue.watchers,\n});\n\n/**\n * Whether anyone but the current user is watching the channel. The current user is excluded: the\n * other participant of a DM would otherwise look online as soon as the local user starts watching.\n * `channel` defaults to the channel in context, and `enabled: false` returns false.\n */\nexport const useChannelHasMembersOnline = ({\n  channel: channelOverride,\n  enabled = true,\n}: UseChannelHasMembersOnlineParams = {}) => {\n  const contextChannel = useChannel();\n  const channel = channelOverride ?? contextChannel;\n  const { client } = useChatContext();\n  const { watchers } = useStateStore(channel.state, watchersSelector);\n\n  if (!enabled) return false;\n\n  const ownUserId = client.user?.id;\n  return Object.keys(watchers).some((id) => id !== ownUserId);\n};\n"],"mappings":";;;;AAWA,IAAM,oBAAoB,eAAkC,EAC1D,UAAU,UAAU,SACtB;;;;;;AAOA,IAAa,8BAA8B,EACzC,SAAS,iBACT,UAAU,SAC0B,CAAC,MAAM;CAC3C,MAAM,iBAAiB,WAAW;CAClC,MAAM,UAAU,mBAAmB;CACnC,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,EAAE,aAAa,cAAc,QAAQ,OAAO,gBAAgB;CAElE,IAAI,CAAC,SAAS,OAAO;CAErB,MAAM,YAAY,OAAO,MAAM;CAC/B,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,MAAM,OAAO,OAAO,SAAS;AAC5D"}