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/esm/index.mjs
CHANGED
|
@@ -1391,7 +1391,7 @@ var parseVersion = (raw) => {
|
|
|
1391
1391
|
};
|
|
1392
1392
|
var readInjectedVersion = () => {
|
|
1393
1393
|
try {
|
|
1394
|
-
return "10.0
|
|
1394
|
+
return "10.1.0";
|
|
1395
1395
|
} catch {
|
|
1396
1396
|
return void 0;
|
|
1397
1397
|
}
|
|
@@ -15115,6 +15115,25 @@ var reflectReactionEvent = (client, {
|
|
|
15115
15115
|
});
|
|
15116
15116
|
};
|
|
15117
15117
|
|
|
15118
|
+
// src/utils/activeMemberCount.ts
|
|
15119
|
+
var getCarriedActiveMemberCount = ({
|
|
15120
|
+
next,
|
|
15121
|
+
previous
|
|
15122
|
+
}) => {
|
|
15123
|
+
const { active_member_count: nextActiveMemberCount } = next;
|
|
15124
|
+
const {
|
|
15125
|
+
active_member_count: previousActiveMemberCount,
|
|
15126
|
+
member_count: previousMemberCount
|
|
15127
|
+
} = previous ?? {};
|
|
15128
|
+
const hasOwnActiveMemberCount = typeof nextActiveMemberCount === "number";
|
|
15129
|
+
const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === "number";
|
|
15130
|
+
if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return void 0;
|
|
15131
|
+
const memberCount = next.member_count ?? previousMemberCount;
|
|
15132
|
+
const delta = typeof next.member_count === "number" && typeof previousMemberCount === "number" ? next.member_count - previousMemberCount : 0;
|
|
15133
|
+
const shifted = Math.max(0, previousActiveMemberCount + delta);
|
|
15134
|
+
return typeof memberCount === "number" ? Math.min(shifted, memberCount) : shifted;
|
|
15135
|
+
};
|
|
15136
|
+
|
|
15118
15137
|
// src/utils/abort.ts
|
|
15119
15138
|
var abortError = (signal, message) => {
|
|
15120
15139
|
const reason = signal.reason;
|
|
@@ -16364,33 +16383,48 @@ var Channel = class extends ChannelApi {
|
|
|
16364
16383
|
this.state.partialNext({ offlineMode });
|
|
16365
16384
|
}
|
|
16366
16385
|
/**
|
|
16367
|
-
* Reads `state.data`. Assigning publishes `data`, `memberCount
|
|
16368
|
-
* If the object omits `member_count` or
|
|
16369
|
-
* a copy (the assigned object is not
|
|
16370
|
-
*
|
|
16371
|
-
*
|
|
16386
|
+
* Reads `state.data`. Assigning publishes `data`, `memberCount`, `activeMemberCount` and
|
|
16387
|
+
* `ownCapabilities` in one update. If the object omits `member_count`, `active_member_count` or
|
|
16388
|
+
* `own_capabilities`, the last known values are carried onto a copy (the assigned object is not
|
|
16389
|
+
* changed). A carried `active_member_count` moves with `member_count` (shifted by the change in
|
|
16390
|
+
* membership, clamped to `member_count`), since only Query Channels returns it; treat it as a
|
|
16391
|
+
* last-known estimate, refreshed on the next query — it can lag a (de)activation or an
|
|
16392
|
+
* already-deactivated member being added or removed. Editing
|
|
16393
|
+
* `channel.data.x` in place does not reach the state. `ownCapabilities` keeps its array while the
|
|
16394
|
+
* capabilities stay the same (in any order), so a subscriber to it is notified only when they
|
|
16395
|
+
* change.
|
|
16372
16396
|
*/
|
|
16373
16397
|
get data() {
|
|
16374
16398
|
return this.state.getLatestValue().data;
|
|
16375
16399
|
}
|
|
16376
16400
|
set data(next) {
|
|
16377
16401
|
const {
|
|
16402
|
+
activeMemberCount: previousActiveMemberCount,
|
|
16378
16403
|
data: previous,
|
|
16379
16404
|
memberCount: previousMemberCount,
|
|
16380
16405
|
ownCapabilities: previousOwnCapabilities
|
|
16381
16406
|
} = this.state.getLatestValue();
|
|
16382
16407
|
const carriedMemberCount = typeof next?.member_count !== "number" && typeof previous?.member_count === "number" ? previous.member_count : void 0;
|
|
16408
|
+
const carriedActiveMemberCount = next ? getCarriedActiveMemberCount({ next, previous }) : void 0;
|
|
16383
16409
|
const carriedCapabilities = !Array.isArray(next?.own_capabilities) && Array.isArray(previous?.own_capabilities) ? [...previous.own_capabilities] : void 0;
|
|
16384
|
-
const
|
|
16410
|
+
const carriesMemberCount = carriedMemberCount !== void 0;
|
|
16411
|
+
const carriesActiveMemberCount = carriedActiveMemberCount !== void 0;
|
|
16412
|
+
const carriesValues = carriesMemberCount || carriesActiveMemberCount || !!carriedCapabilities;
|
|
16413
|
+
const data = next && carriesValues ? {
|
|
16385
16414
|
...next,
|
|
16386
|
-
...
|
|
16415
|
+
...carriesMemberCount && { member_count: carriedMemberCount },
|
|
16416
|
+
...carriesActiveMemberCount && {
|
|
16417
|
+
active_member_count: carriedActiveMemberCount
|
|
16418
|
+
},
|
|
16387
16419
|
...carriedCapabilities && { own_capabilities: carriedCapabilities }
|
|
16388
16420
|
} : next;
|
|
16389
16421
|
const memberCount = data?.member_count ?? carriedMemberCount;
|
|
16422
|
+
const activeMemberCount = data ? data.active_member_count : previousActiveMemberCount;
|
|
16390
16423
|
const ownCapabilities = data?.own_capabilities ?? carriedCapabilities ?? [];
|
|
16391
16424
|
const toKey = (capabilities) => [...capabilities].sort().join();
|
|
16392
16425
|
const haveSameOwnCapabilities = toKey(previousOwnCapabilities) === toKey(ownCapabilities);
|
|
16393
16426
|
this.state.partialNext({
|
|
16427
|
+
activeMemberCount,
|
|
16394
16428
|
data,
|
|
16395
16429
|
memberCount: memberCount ?? previousMemberCount,
|
|
16396
16430
|
ownCapabilities: haveSameOwnCapabilities ? previousOwnCapabilities : [...ownCapabilities]
|
|
@@ -25798,6 +25832,16 @@ var StreamChat = class _StreamChat extends ChatApi {
|
|
|
25798
25832
|
});
|
|
25799
25833
|
return result;
|
|
25800
25834
|
}
|
|
25835
|
+
async updatePushNotificationPreferences(...args) {
|
|
25836
|
+
const result = await super.updatePushNotificationPreferences(...args);
|
|
25837
|
+
const { user } = this;
|
|
25838
|
+
if (!user) return result;
|
|
25839
|
+
const updated = result.user_preferences[user.id];
|
|
25840
|
+
if (updated) {
|
|
25841
|
+
this.user = { ...user, push_preferences: updated };
|
|
25842
|
+
}
|
|
25843
|
+
return result;
|
|
25844
|
+
}
|
|
25801
25845
|
async unblockUser(blockedUserId, requestOptions) {
|
|
25802
25846
|
const result = await this.unblockUsers(
|
|
25803
25847
|
{
|