Skip to content

feat: expose the channel's active member count in v10 (REACT-1376) - #2001

Merged
NikolaGoranNaumovski merged 9 commits into
masterfrom
nikolanaumovski/react-1376-support-active-member-count
Nov 16, 2026
Merged

NikolaGoranNaumovski merged 9 commits into
masterfrom
nikolanaumovski/react-1376-support-active-member-count

Conversation

@NikolaGoranNaumovski

@NikolaGoranNaumovski NikolaGoranNaumovski commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

Description of the changes, What, Why and How?

Ticket: https://linear.app/stream/issue/REACT-1376
Docs: Query Channels – active member count
v9 counterpart: #2002
React v15: GetStream/stream-chat-react#3413

Query Channels returns active_member_count for each channel when the request has include_active_member_count: true. active_member_count is the number of members who are not deactivated or deleted. v10's generated client already has both fields. This PR exposes the count in channel.state and keeps it through later channel updates.

State

  • ChannelState has a new activeMemberCount slice (in MembersState). It is undefined until a response carries active_member_count.
  • The channel.data setter publishes activeMemberCount with data, memberCount and ownCapabilities in one update.

Carrying the count

Only Query Channels returns active_member_count. Other responses and events that replace channel.data (watch, update, channel.updated, …) don't have it. When the new data omits it and the previous data had it:

  • the previous count is carried onto a copy of the new data, as member_count and own_capabilities already are;
  • it moves by the change in member_count, and stays between 0 and member_count. For example, a member removed between two queries lowers it by one.

When the new data has active_member_count, it is used as is.

ai-docs/v10-breaking-changes.md mentions the new slice and the carry rule.

Tests

  • test/unit/channel_state.test.js covers the initial value, the carry, a new count from the server, moving with member_count, a channel.updated event, the bounds, and clearing channel.data.
  • test/unit/client.test.js checks that a queried channel keeps its count after a channel query that omits it.

Demo

React v15 with GetStream/stream-chat-react#3413 and this PR's build, against the live API. Left: the app, used by hand. Top right: a terminal. Bottom right: the app's DevTools console, which lists each member as active / deactivated and prints member_count / active_member_count.

  1. "Product team": Nikola (owner), Alice, Bob, Carol, all active → 4 / 4.
  2. getstream api DeactivateUser for Carol, then reload → Carol: deactivated → 4 / 3.
  3. Add Dana in the UI → 5 / 4. Remove Bob → 4 / 3. Rename the channel (channel.updated) → 4 / 3.

The header and the Members view show the active count (4 → 3 after the reload); the Members list still shows every member.

1-active-member-count-v10-v15.mp4

Changelog

  • Add channel.state activeMemberCount, filled from Query Channels with include_active_member_count.

🤖 Generated with Claude Code

Publish activeMemberCount on the channel state and carry the last known
active_member_count across data updates that omit it, shifted with member_count.
@NikolaGoranNaumovski
NikolaGoranNaumovski changed the base branch from release-v10 to master November 9, 2026 09:47
Comment thread src/channel.ts Resolved
Comment thread src/channel.ts Resolved
Comment thread src/channel.ts Resolved
…ount

Only Query Channels returns active_member_count, so between queries it was
being guessed from member_count deltas. The backend recomputes it fresh per
query (and drops its cache on deactivate/delete), so that shift could be
wrong (a departed member may have been inactive). Carry the last known count
unchanged instead, still capped at member_count.

Also drop the now-redundant getCarriedActiveMemberCount memberCount param
(derived from next/previous) and the explicit activeMemberCount: undefined
state initializer.
… estimate

Addresses review: move getCarriedActiveMemberCount out of channel.ts into
src/utils/activeMemberCount.ts (matching the v9 counterpart), inline its
single-use params type, and document the carried count as a last-known
estimate (refreshed only on the next Query Channels) in the data setter docs
and v10-breaking-changes.md.
@MartinCupela

Copy link
Copy Markdown
Contributor

I tested d743b317 in the browser against the live API. When an active member is added, the carried activeMemberCount doesn't go up. It stays wrong until the next Query Channels with include_active_member_count. Here's how to reproduce it.

Setup

  1. Build this branch: yarn install && yarn build.
  2. In stream-chat-react, check out #3413 (e125ccb4), then run yarn install && yarn build.
  3. Run examples/vite with STREAM_CHAT_JS_PATH set to this branch's checkout, then npx vite.
  4. Open the app and check in DevTools (Network or performance.getEntriesByType('resource')) that stream-chat loads from this branch's dist/esm/index.mjs.

Script

Paste this into the browser console. Set a, b and c to three active users other than you. The example app exposes the client as window.streamDebug.client. In another app, use your own StreamChat instance.

After each step, the script prints the SDK's activeMemberCount / memberCount next to a fresh Query Channels count from the server:

const client = window.streamDebug.client;
const [a, b, c] = ['<user-a>', '<user-b>', '<user-c>']; // three active users other than you
const id = `active-count-${Date.now()}`;
const cid = `messaging:${id}`;
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const sdk = (channel) => {
  const { activeMemberCount, memberCount } = channel.state.getLatestValue();
  return `${activeMemberCount} / ${memberCount}`;
};
// A separate Query Channels that isn't hydrated, so it doesn't change the channel's state.
const server = async () => {
  const { channels: [response] } = await client.queryChannels({
    filter_conditions: { cid },
    include_active_member_count: true,
    watch: false,
    state: true,
    message_limit: 0,
  });
  return `${response.channel.active_member_count} / ${response.channel.member_count}`;
};
const log = async (step, channel) => {
  await wait(1500); // let channel.updated arrive
  console.log(`${step}: SDK ${sdk(channel)}, server ${await server()}`);
};

await client.channel('messaging', id, { members: [client.userID, a, b] }).watch();
const [channel] = await client.queryChannelsAndHydrate({
  filter_conditions: { cid },
  include_active_member_count: true,
});
await log('0. Query Channels with the count', channel);
await channel.addMembers({ members: [c] });
await log('1. add c', channel);
await channel.removeMembers({ members: [a, b] });
await log('2. remove a and b', channel);
await channel.addMembers({ members: [a, b] });
await log('3. add a and b back', channel);
await channel.updatePartial({ set: { name: 'renamed' } });
await log('4. rename (channel.updated)', channel);

Result

All members are active. Each cell shows active / members:

Step SDK Server With the shift by the member_count change
0. Query Channels with the count 3 / 3 3 / 3 3 / 3
1. add c 3 / 4 4 / 4 4 / 4
2. remove a and b 2 / 2 2 / 2 2 / 2
3. add a and b back 2 / 4 4 / 4 4 / 4
4. rename (channel.updated) 2 / 4 4 / 4 4 / 4
  • Step 1: the count doesn't move when an active member is added.
  • Step 2: the count is right only because the cap at member_count kicked in.
  • Steps 3 and 4: the cap only ever lowers the count, so it stays at 2 after the members come back.
  • Last column: the shift from the earlier version matches the server at every step.

To see it in the UI, open the channel in the example app after step 4. The ChannelHeader from #3413 shows "2 members · 1 online" for the 4-member channel. Running client.queryChannelsAndHydrate({ filter_conditions: { cid }, include_active_member_count: true }) again brings it back to "4 members".

I didn't test the deactivated-user cases, because deactivating a user needs a server-side key. To add them, deactivate one of the users before step 0, for example with getstream api DeactivateUser, as in your demo. Then add or remove that user. The shift is expected to be off by one there, and that's the estimate the docs describe.

The carried active_member_count was kept unchanged (only capped down at
member_count), so adding an active member never raised it — the count stayed
wrong until the next Query Channels with include_active_member_count. Shift the
last known count by the change in member_count instead (clamped to
[0, member_count]), which tracks the server for active-member adds and removes.

It remains a last-known estimate, refreshed on the next query, that can lag an
already-deactivated member being added or removed.

Verified against the live API (add / remove / re-add / rename): the SDK's
active_member_count now matches the server's at every step.
@NikolaGoranNaumovski
NikolaGoranNaumovski force-pushed the nikolanaumovski/react-1376-support-active-member-count branch from 1773f00 to cf15986 Compare November 16, 2026 12:42
NikolaGoranNaumovski added a commit that referenced this pull request Nov 16, 2026
…REACT-1376) (#2002)

## CLA

- [x] I have signed the [Stream
CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform)
(required).
- [x] Code changes are tested

## Description of the changes, What, Why and How?

Ticket: https://linear.app/stream/issue/REACT-1376
Docs: [Query Channels – active member
count](https://getstream.io/chat/docs/javascript/query-channels/#active-member-count)
v10 counterpart: #2001

Query Channels returns `active_member_count` for each channel when the
request has `include_active_member_count: true`. `active_member_count`
is the number of members who are not deactivated or deleted. Only Query
Channels returns it, so every later write to `channel.data` that comes
from another response or event (`watch`, `query`, `update`,
`channel.updated`, …) used to drop it. This PR keeps the count, with the
same rule as v10.

### Types (`src/types.ts`)

- `ChannelResponse.active_member_count?: number`
- `ChannelOptions.include_active_member_count?: boolean`

### `channel.data` carries the count

`channel.data` is now a getter/setter, as in v10. The setter runs
`withCarriedActiveMemberCount({ next, previous })`
(`src/utils/activeMemberCount.ts`):
- `next` is stored unchanged when it has its own `active_member_count`,
or when there is no previous count. So assignments that don't involve
the count keep their object identity.
- Otherwise a copy of `next` gets the previous count:
  - moved by the change in `member_count`;
  - kept between 0 and `member_count`.

In-place edits (`channel.data.x = y`) still work, because the getter
returns the stored object.

**Why a setter and not per call site:** the first version wrapped the 8
SDK call sites that assign `channel.data`. Recording a demo with React
v14 showed that this isn't enough. React v14's `ChannelList`
(`useChannelListShape`) replaces `channel.data` with `event.channel` on
`channel.updated`, which dropped the count after every rename or member
change. A setter covers every writer: the SDK, React, React Native and
Angular.

### Tests

- `test/unit/utils/activeMemberCount.test.ts`: the carry rules (own
count wins, no previous count, copy, moving with `member_count`, unknown
`member_count`, bounds).
- `test/unit/channel_active_member_count.test.ts`:
  - `queryChannels` sends the flag and keeps the count;
- the count is kept when a consumer replaces `channel.data` the way
React v14's ChannelList does;
  - it moves with `member_count`;
- it survives a `channel.updated` event and a channel query that omits
it;
  - a new count from the server wins;
  - identity is kept when there is nothing to carry;
  - `channel.data` can be cleared.

  On `release-v9`, the 4 carry tests fail.
- e2e against the live API (12/12), and in the Vite example with React
v14: rename, add and remove member, `watch()` and re-query all keep the
count.

### Demo

React v14 (`release-v14`, no UI change) with this PR's build, against
the live API. Left: the app, used by hand. Top right: a terminal. Bottom
right: the app's DevTools console, which lists each member as active /
deactivated and prints `member_count` / `active_member_count`.
1. "Product team": Nikola (owner), Alice, Bob, Carol, all active → 4 /
4.
2. `getstream api DeactivateUser` for Carol, then reload → Carol:
deactivated → 4 / 3.
3. Add Dana in the UI → 5 / 4. Remove Bob → 4 / 3. Rename the channel
(`channel.updated`) → 4 / 3.

v14 shows `member_count` in its header, so the console is where the
active count is visible. The rename step is the one that used to drop
the count before the `channel.data` setter.


https://github.com/user-attachments/assets/ee441828-068a-40a5-a39a-81dd3d0cd93f

## Changelog

- Add `active_member_count` / `include_active_member_count` types.
- Keep `channel.data.active_member_count` across channel updates and
`channel.data` writes that don't return it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@NikolaGoranNaumovski
NikolaGoranNaumovski merged commit 99fea1c into master Nov 16, 2026
7 checks passed
@NikolaGoranNaumovski
NikolaGoranNaumovski deleted the nikolanaumovski/react-1376-support-active-member-count branch November 16, 2026 12:46
github-actions Bot pushed a commit that referenced this pull request Nov 17, 2026
## [10.1.0](v10.0.2...v10.1.0) (2026-11-17)

### Features

* expose the channel's active member count in v10 (REACT-1376) ([#2001](#2001)) ([99fea1c](99fea1c)), closes [#2002](#2002) [GetStream/stream-chat-react#3413](GetStream/stream-chat-react#3413)
* support quiet hours for push notifications in v10 (REACT-1375) ([#1999](#1999)) ([0f5f5c1](0f5f5c1)), closes [#2000](#2000)
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 10.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions Bot pushed a commit that referenced this pull request Nov 17, 2026
## [9.56.0](v9.55.0...v9.56.0) (2026-11-17)

### Bug Fixes

* **types:** add two_way_block_effect_enabled to the app settings response ([#2010](#2010)) ([34481ab](34481ab)), closes [#1742](#1742) [#1887](#1887) [#2000](#2000) [#2000](#2000)

### Features

* keep the channel's active member count across channel updates (REACT-1376) ([#2002](#2002)) ([a7b712f](a7b712f)), closes [#2001](#2001)
* support quiet hours for push notifications (REACT-1375) ([#2000](#2000)) ([6627030](6627030)), closes [#1999](#1999)
NikolaGoranNaumovski added a commit to GetStream/stream-chat-react that referenced this pull request Nov 24, 2026
…view (REACT-1376) (#3413)

### 🎯 Goal

Ticket: https://linear.app/stream/issue/REACT-1376
Docs: [Query Channels – active member
count](https://getstream.io/chat/docs/javascript/query-channels/#active-member-count)

Depends on GetStream/stream-chat-js#2001 (the `channel.state`
`activeMemberCount` slice). Merge it after that is released and the
`stream-chat` dependency is bumped. Until then CI fails on types and on
the new header test (`activeMemberCount` doesn't exist in the released
`stream-chat`); with the #2001 build, types, lint and all tests pass.

When the channel list is queried with `include_active_member_count:
true`, the member count shown in the UI should be the active member
count: members who are not deactivated or deleted. Without the option,
nothing changes.

### 🛠 Implementation details

- **New hook:** `useDisplayedMemberCount(channel)`
(`src/hooks/useDisplayedMemberCount.ts`, exported from `src/hooks`). It
reads `activeMemberCount` and `memberCount` from `channel.state` and
returns `activeMemberCount ?? memberCount`.
- **Channel header:** `useChannelHeaderOnlineStatus` uses the hook for
the "N members" text.
- **Channel members view:** `ChannelMembersView` uses the hook in place
of `useChannelMemberCount`.

`useChannelMembersSearch` keeps `useChannelMemberCount` (the total
`member_count`). It only uses it for `hasMembers` (the empty state), and
a channel whose members are all deactivated still has members to list.

**Open question:** the Members view title now shows the active count,
while its list shows every member, deactivated ones included (for
example "3 members" above four rows). Should the title show the total
instead, or should deactivated members be marked in the list?

### Tests

- [x] Code changes are tested
- `src/hooks/__tests__/useDisplayedMemberCount.test.tsx`: falls back to
`memberCount`, prefers `activeMemberCount` (including 0), and follows
state changes.
- `ChannelHeader.test.tsx`: the subtitle shows the active count.
- `ChannelMembersView.test.tsx`: the existing tests now mock
`useDisplayedMemberCount` in place of `useChannelMemberCount`.

### 🎨 UI Changes

The member count in the channel header and the channel members view
shows the active member count when one is known.

The Vite example with this PR and the GetStream/stream-chat-js#2001
build, against the live API. Left: the app, used by hand. Top right: a
terminal. Bottom right: the app's DevTools console, which lists each
member as active / deactivated and prints `member_count` /
`active_member_count`.
1. "Product team": Nikola (owner), Alice, Bob, Carol, all active →
header "4 members".
2. `getstream api DeactivateUser` for Carol, then reload → header "3
members"; the Members list still shows all four.
3. Add Dana in the UI → "4 members" (5 listed). Remove Bob → "3
members". Rename the channel → still "3 members".


https://github.com/user-attachments/assets/3d1f756f-c40b-48f3-9f4b-79ac56d41e07

🤖 Generated with [Claude Code](https://claude.com/claude-code)



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Channel headers now show the active member count when available,
including zero. If it isn’t available, they continue to show the total
member count.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants