Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
25 changes: 25 additions & 0 deletions src/components/ChannelHeader/__tests__/ChannelHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }}`.
*/
Expand All @@ -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],
Expand All @@ -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 })}`;
}
Loading