diff --git a/examples/vite/src/App.tsx b/examples/vite/src/App.tsx index bb82ec832..e50a68e28 100644 --- a/examples/vite/src/App.tsx +++ b/examples/vite/src/App.tsx @@ -150,6 +150,7 @@ const CHANNELS_PAGE_SIZE = 10; const UNREAD_LIST_ID = 'channels:unread'; const requestOptions: ChannelPaginatorRequestOptions = { + include_active_member_count: true, presence: true, state: true, }; diff --git a/src/components/ChannelHeader/__tests__/ChannelHeader.test.tsx b/src/components/ChannelHeader/__tests__/ChannelHeader.test.tsx index f3ae7e8a4..713cc6d1e 100644 --- a/src/components/ChannelHeader/__tests__/ChannelHeader.test.tsx +++ b/src/components/ChannelHeader/__tests__/ChannelHeader.test.tsx @@ -198,6 +198,31 @@ describe('ChannelHeader', () => { }); }); + it('shows the active member count in the subtitle when the channel has one', async () => { + await renderComponent({ + channelData: { + ...channelCustom({ image: 'image.jpg', name: 'test-channel-1' }), + active_member_count: 8, + member_count: 10, + }, + }); + + expect(await screen.findByText(/^8 members/)).toBeInTheDocument(); + expect(screen.queryByText(/^10 members/)).not.toBeInTheDocument(); + }); + + it('keeps the subtitle and shows zero when the channel has members but none are active', async () => { + await renderComponent({ + channelData: { + ...channelCustom({ image: 'image.jpg', name: 'test-channel-1' }), + active_member_count: 0, + member_count: 10, + }, + }); + + expect(await screen.findByText(/^0 members/)).toBeInTheDocument(); + }); + it('should display correct member_count in subtitle', async () => { const { container } = await renderComponent({ channelData: { diff --git a/src/components/ChannelHeader/hooks/useChannelHeaderOnlineStatus.ts b/src/components/ChannelHeader/hooks/useChannelHeaderOnlineStatus.ts index f1e9097b8..181419d2c 100644 --- a/src/components/ChannelHeader/hooks/useChannelHeaderOnlineStatus.ts +++ b/src/components/ChannelHeader/hooks/useChannelHeaderOnlineStatus.ts @@ -8,7 +8,13 @@ import { useIsDmChannel } from '../../../hooks'; import { getOnlineMembers } from './onlineMembers'; import { useChannelHasOtherMembersOnline } from './useChannelHasOtherMembersOnline'; -const membersSelector = ({ memberCount, members, watchers }: ChannelStateData) => ({ +const membersSelector = ({ + activeMemberCount, + memberCount, + members, + watchers, +}: ChannelStateData) => ({ + activeMemberCount, memberCount, members, watchers, @@ -24,6 +30,9 @@ export type UseChannelHeaderOnlineStatusParams = { * is true or who watch the channel. Null when the channel has no members. `channel` defaults to the * channel in context. * + * N is the channel's active member count (members who are not deactivated or deleted) when the + * channel was queried with `include_active_member_count: true`, otherwise its total member count. + * * `user.online` stays current only on channels queried or watched with `presence: true`. The copy * gets the count as both `{{ onlineCount }}` and `{{ watcherCount }}`. */ @@ -32,10 +41,11 @@ export function useChannelHeaderOnlineStatus({ }: UseChannelHeaderOnlineStatusParams = {}): string | null { const { t } = useTranslationContext(); const channel = useResolvedChannel(channelOverride); - const { memberCount, members, watchers } = useStateStore( + const { activeMemberCount, memberCount, members, watchers } = useStateStore( channel.state, membersSelector, ); + const displayedMemberCount = activeMemberCount ?? memberCount; const onlineCount = useMemo( () => getOnlineMembers({ members, watchers }).length, [members, watchers], @@ -54,5 +64,5 @@ export function useChannelHeaderOnlineStatus({ : t('common.offline.label', 'Offline'); } - return `${t('channelHeader.online.members.label', '{{ memberCount }} members', { memberCount })} · ${t('channelHeader.online.online.label', '{{ onlineCount }} online', { onlineCount, watcherCount: onlineCount })}`; + return `${t('channelHeader.online.members.label', '{{ memberCount }} members', { memberCount: displayedMemberCount })} · ${t('channelHeader.online.online.label', '{{ onlineCount }} online', { onlineCount, watcherCount: onlineCount })}`; }