stream-chat 10.0.2 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.browser.js +52 -8
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +52 -8
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +52 -8
- package/dist/esm/index.mjs.map +3 -3
- package/dist/types/channel.d.ts +10 -5
- package/dist/types/channel_state.d.ts +1 -0
- package/dist/types/client.d.ts +1 -0
- package/dist/types/utils/activeMemberCount.d.ts +5 -0
- package/package.json +1 -1
- package/src/channel.ts +27 -7
- package/src/channel_state.ts +1 -0
- package/src/client.ts +16 -0
- package/src/utils/activeMemberCount.ts +30 -0
package/dist/cjs/index.node.js
CHANGED
|
@@ -1669,7 +1669,7 @@ var parseVersion = (raw) => {
|
|
|
1669
1669
|
};
|
|
1670
1670
|
var readInjectedVersion = () => {
|
|
1671
1671
|
try {
|
|
1672
|
-
return "10.0
|
|
1672
|
+
return "10.1.0";
|
|
1673
1673
|
} catch {
|
|
1674
1674
|
return void 0;
|
|
1675
1675
|
}
|
|
@@ -15393,6 +15393,25 @@ var reflectReactionEvent = (client, {
|
|
|
15393
15393
|
});
|
|
15394
15394
|
};
|
|
15395
15395
|
|
|
15396
|
+
// src/utils/activeMemberCount.ts
|
|
15397
|
+
var getCarriedActiveMemberCount = ({
|
|
15398
|
+
next,
|
|
15399
|
+
previous
|
|
15400
|
+
}) => {
|
|
15401
|
+
const { active_member_count: nextActiveMemberCount } = next;
|
|
15402
|
+
const {
|
|
15403
|
+
active_member_count: previousActiveMemberCount,
|
|
15404
|
+
member_count: previousMemberCount
|
|
15405
|
+
} = previous ?? {};
|
|
15406
|
+
const hasOwnActiveMemberCount = typeof nextActiveMemberCount === "number";
|
|
15407
|
+
const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === "number";
|
|
15408
|
+
if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return void 0;
|
|
15409
|
+
const memberCount = next.member_count ?? previousMemberCount;
|
|
15410
|
+
const delta = typeof next.member_count === "number" && typeof previousMemberCount === "number" ? next.member_count - previousMemberCount : 0;
|
|
15411
|
+
const shifted = Math.max(0, previousActiveMemberCount + delta);
|
|
15412
|
+
return typeof memberCount === "number" ? Math.min(shifted, memberCount) : shifted;
|
|
15413
|
+
};
|
|
15414
|
+
|
|
15396
15415
|
// src/utils/abort.ts
|
|
15397
15416
|
var abortError = (signal, message) => {
|
|
15398
15417
|
const reason = signal.reason;
|
|
@@ -16642,33 +16661,48 @@ var Channel = class extends ChannelApi {
|
|
|
16642
16661
|
this.state.partialNext({ offlineMode });
|
|
16643
16662
|
}
|
|
16644
16663
|
/**
|
|
16645
|
-
* Reads `state.data`. Assigning publishes `data`, `memberCount
|
|
16646
|
-
* If the object omits `member_count` or
|
|
16647
|
-
* a copy (the assigned object is not
|
|
16648
|
-
*
|
|
16649
|
-
*
|
|
16664
|
+
* Reads `state.data`. Assigning publishes `data`, `memberCount`, `activeMemberCount` and
|
|
16665
|
+
* `ownCapabilities` in one update. If the object omits `member_count`, `active_member_count` or
|
|
16666
|
+
* `own_capabilities`, the last known values are carried onto a copy (the assigned object is not
|
|
16667
|
+
* changed). A carried `active_member_count` moves with `member_count` (shifted by the change in
|
|
16668
|
+
* membership, clamped to `member_count`), since only Query Channels returns it; treat it as a
|
|
16669
|
+
* last-known estimate, refreshed on the next query — it can lag a (de)activation or an
|
|
16670
|
+
* already-deactivated member being added or removed. Editing
|
|
16671
|
+
* `channel.data.x` in place does not reach the state. `ownCapabilities` keeps its array while the
|
|
16672
|
+
* capabilities stay the same (in any order), so a subscriber to it is notified only when they
|
|
16673
|
+
* change.
|
|
16650
16674
|
*/
|
|
16651
16675
|
get data() {
|
|
16652
16676
|
return this.state.getLatestValue().data;
|
|
16653
16677
|
}
|
|
16654
16678
|
set data(next) {
|
|
16655
16679
|
const {
|
|
16680
|
+
activeMemberCount: previousActiveMemberCount,
|
|
16656
16681
|
data: previous,
|
|
16657
16682
|
memberCount: previousMemberCount,
|
|
16658
16683
|
ownCapabilities: previousOwnCapabilities
|
|
16659
16684
|
} = this.state.getLatestValue();
|
|
16660
16685
|
const carriedMemberCount = typeof next?.member_count !== "number" && typeof previous?.member_count === "number" ? previous.member_count : void 0;
|
|
16686
|
+
const carriedActiveMemberCount = next ? getCarriedActiveMemberCount({ next, previous }) : void 0;
|
|
16661
16687
|
const carriedCapabilities = !Array.isArray(next?.own_capabilities) && Array.isArray(previous?.own_capabilities) ? [...previous.own_capabilities] : void 0;
|
|
16662
|
-
const
|
|
16688
|
+
const carriesMemberCount = carriedMemberCount !== void 0;
|
|
16689
|
+
const carriesActiveMemberCount = carriedActiveMemberCount !== void 0;
|
|
16690
|
+
const carriesValues = carriesMemberCount || carriesActiveMemberCount || !!carriedCapabilities;
|
|
16691
|
+
const data = next && carriesValues ? {
|
|
16663
16692
|
...next,
|
|
16664
|
-
...
|
|
16693
|
+
...carriesMemberCount && { member_count: carriedMemberCount },
|
|
16694
|
+
...carriesActiveMemberCount && {
|
|
16695
|
+
active_member_count: carriedActiveMemberCount
|
|
16696
|
+
},
|
|
16665
16697
|
...carriedCapabilities && { own_capabilities: carriedCapabilities }
|
|
16666
16698
|
} : next;
|
|
16667
16699
|
const memberCount = data?.member_count ?? carriedMemberCount;
|
|
16700
|
+
const activeMemberCount = data ? data.active_member_count : previousActiveMemberCount;
|
|
16668
16701
|
const ownCapabilities = data?.own_capabilities ?? carriedCapabilities ?? [];
|
|
16669
16702
|
const toKey = (capabilities) => [...capabilities].sort().join();
|
|
16670
16703
|
const haveSameOwnCapabilities = toKey(previousOwnCapabilities) === toKey(ownCapabilities);
|
|
16671
16704
|
this.state.partialNext({
|
|
16705
|
+
activeMemberCount,
|
|
16672
16706
|
data,
|
|
16673
16707
|
memberCount: memberCount ?? previousMemberCount,
|
|
16674
16708
|
ownCapabilities: haveSameOwnCapabilities ? previousOwnCapabilities : [...ownCapabilities]
|
|
@@ -26076,6 +26110,16 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
26076
26110
|
});
|
|
26077
26111
|
return result;
|
|
26078
26112
|
}
|
|
26113
|
+
async updatePushNotificationPreferences(...args) {
|
|
26114
|
+
const result = await super.updatePushNotificationPreferences(...args);
|
|
26115
|
+
const { user } = this;
|
|
26116
|
+
if (!user) return result;
|
|
26117
|
+
const updated = result.user_preferences[user.id];
|
|
26118
|
+
if (updated) {
|
|
26119
|
+
this.user = { ...user, push_preferences: updated };
|
|
26120
|
+
}
|
|
26121
|
+
return result;
|
|
26122
|
+
}
|
|
26079
26123
|
async unblockUser(blockedUserId, requestOptions) {
|
|
26080
26124
|
const result = await this.unblockUsers(
|
|
26081
26125
|
{
|