{"version":3,"file":"useChannelMemberCount.mjs","names":[],"sources":["../../../../../../src/plugins/ChannelDetail/Views/ChannelMembersView/useChannelMemberCount.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport type { Channel } from 'stream-chat';\n\n// Channel events that may change `member_count`, which the SDK refreshes in `channel.data`.\n// Re-reading it on these events needs no count bookkeeping in the views that change membership.\nconst MEMBER_COUNT_EVENTS = [\n  'member.added',\n  'member.removed',\n  'channel.updated',\n] as const;\n\n/** Reactive channel member count. */\nexport const useChannelMemberCount = (channel: Channel) => {\n  const [memberCount, setMemberCount] = useState(channel.data?.member_count ?? 0);\n\n  useEffect(() => {\n    const syncMemberCount = () => setMemberCount(channel.data?.member_count ?? 0);\n\n    syncMemberCount();\n\n    const subscriptions = MEMBER_COUNT_EVENTS.map((event) =>\n      channel.on(event, syncMemberCount),\n    );\n\n    return () => subscriptions.forEach((subscription) => subscription.unsubscribe());\n  }, [channel]);\n\n  return memberCount;\n};\n"],"mappings":";;AAKA,IAAM,sBAAsB;CAC1B;CACA;CACA;AACF;;AAGA,IAAa,yBAAyB,YAAqB;CACzD,MAAM,CAAC,aAAa,kBAAkB,SAAS,QAAQ,MAAM,gBAAgB,CAAC;CAE9E,gBAAgB;EACd,MAAM,wBAAwB,eAAe,QAAQ,MAAM,gBAAgB,CAAC;EAE5E,gBAAgB;EAEhB,MAAM,gBAAgB,oBAAoB,KAAK,UAC7C,QAAQ,GAAG,OAAO,eAAe,CACnC;EAEA,aAAa,cAAc,SAAS,iBAAiB,aAAa,YAAY,CAAC;CACjF,GAAG,CAAC,OAAO,CAAC;CAEZ,OAAO;AACT"}