Repository navigation
feat: expose the channel's active member count in v10 (REACT-1376) - #2001
NikolaGoranNaumovski merged 9 commits into
Conversation
Publish activeMemberCount on the channel state and carry the last known active_member_count across data updates that omit it, shifted with member_count.
…ct-1376-support-active-member-count
…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.
|
I tested Setup
ScriptPaste this into the browser console. Set After each step, the script prints the SDK's 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);ResultAll members are active. Each cell shows active / members:
To see it in the UI, open the channel in the example app after step 4. The 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 |
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.
1773f00 to
cf15986
Compare
…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)
## [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)
|
🎉 This PR is included in version 10.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## [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)
…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 -->
CLA
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_countfor each channel when the request hasinclude_active_member_count: true.active_member_countis the number of members who are not deactivated or deleted. v10's generated client already has both fields. This PR exposes the count inchannel.stateand keeps it through later channel updates.State
ChannelStatehas a newactiveMemberCountslice (inMembersState). It isundefineduntil a response carriesactive_member_count.channel.datasetter publishesactiveMemberCountwithdata,memberCountandownCapabilitiesin one update.Carrying the count
Only Query Channels returns
active_member_count. Other responses and events that replacechannel.data(watch, update,channel.updated, …) don't have it. When the new data omits it and the previous data had it:member_countandown_capabilitiesalready are;member_count, and stays between 0 andmember_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.mdmentions the new slice and the carry rule.Tests
test/unit/channel_state.test.jscovers the initial value, the carry, a new count from the server, moving withmember_count, achannel.updatedevent, the bounds, and clearingchannel.data.test/unit/client.test.jschecks 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.getstream api DeactivateUserfor Carol, then reload → Carol: deactivated → 4 / 3.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
channel.stateactiveMemberCount, filled from Query Channels withinclude_active_member_count.🤖 Generated with Claude Code