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/types/channel.d.ts
CHANGED
|
@@ -522,11 +522,16 @@ export declare class Channel extends ChannelApi {
|
|
|
522
522
|
get offlineMode(): boolean;
|
|
523
523
|
set offlineMode(offlineMode: boolean);
|
|
524
524
|
/**
|
|
525
|
-
* Reads `state.data`. Assigning publishes `data`, `memberCount
|
|
526
|
-
* If the object omits `member_count` or
|
|
527
|
-
* a copy (the assigned object is not
|
|
528
|
-
*
|
|
529
|
-
*
|
|
525
|
+
* Reads `state.data`. Assigning publishes `data`, `memberCount`, `activeMemberCount` and
|
|
526
|
+
* `ownCapabilities` in one update. If the object omits `member_count`, `active_member_count` or
|
|
527
|
+
* `own_capabilities`, the last known values are carried onto a copy (the assigned object is not
|
|
528
|
+
* changed). A carried `active_member_count` moves with `member_count` (shifted by the change in
|
|
529
|
+
* membership, clamped to `member_count`), since only Query Channels returns it; treat it as a
|
|
530
|
+
* last-known estimate, refreshed on the next query — it can lag a (de)activation or an
|
|
531
|
+
* already-deactivated member being added or removed. Editing
|
|
532
|
+
* `channel.data.x` in place does not reach the state. `ownCapabilities` keeps its array while the
|
|
533
|
+
* capabilities stay the same (in any order), so a subscriber to it is notified only when they
|
|
534
|
+
* change.
|
|
530
535
|
*/
|
|
531
536
|
get data(): Partial<ChannelResponse> | undefined;
|
|
532
537
|
set data(next: Partial<ChannelResponse> | undefined);
|
package/dist/types/client.d.ts
CHANGED
|
@@ -536,6 +536,7 @@ export declare class StreamChat extends ChatApi {
|
|
|
536
536
|
unbanUser(targetUserId: string, options?: UnBanUserOptions): Promise<APIResponse>;
|
|
537
537
|
blockUser(blockedUserId: string, requestOptions?: StreamRequestOptions): Promise<StreamResponse<import(".").BlockUsersResponse>>;
|
|
538
538
|
getBlockedUsers(...args: Parameters<ChatApi['getBlockedUsers']>): Promise<StreamResponse<import(".").GetBlockedUsersResponse>>;
|
|
539
|
+
updatePushNotificationPreferences(...args: Parameters<ChatApi['updatePushNotificationPreferences']>): Promise<StreamResponse<import(".").UpsertPushPreferencesResponse>>;
|
|
539
540
|
unblockUser(blockedUserId: string, requestOptions?: StreamRequestOptions): Promise<StreamResponse<import(".").UnblockUsersResponse>>;
|
|
540
541
|
/**
|
|
541
542
|
* Checks whether a user is muted.
|
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
logChatPromiseExecution,
|
|
20
20
|
sanitizeOutgoingAttachments,
|
|
21
21
|
} from './utils';
|
|
22
|
+
import { getCarriedActiveMemberCount } from './utils/activeMemberCount';
|
|
22
23
|
import { asTimestampNS, nowNs } from './utils/time';
|
|
23
24
|
import { abortError, waitUnlessAborted } from './utils/abort';
|
|
24
25
|
import { normalizeUploadFile } from './upload-utils';
|
|
@@ -1185,11 +1186,16 @@ export class Channel extends ChannelApi {
|
|
|
1185
1186
|
}
|
|
1186
1187
|
|
|
1187
1188
|
/**
|
|
1188
|
-
* Reads `state.data`. Assigning publishes `data`, `memberCount
|
|
1189
|
-
* If the object omits `member_count` or
|
|
1190
|
-
* a copy (the assigned object is not
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1189
|
+
* Reads `state.data`. Assigning publishes `data`, `memberCount`, `activeMemberCount` and
|
|
1190
|
+
* `ownCapabilities` in one update. If the object omits `member_count`, `active_member_count` or
|
|
1191
|
+
* `own_capabilities`, the last known values are carried onto a copy (the assigned object is not
|
|
1192
|
+
* changed). A carried `active_member_count` moves with `member_count` (shifted by the change in
|
|
1193
|
+
* membership, clamped to `member_count`), since only Query Channels returns it; treat it as a
|
|
1194
|
+
* last-known estimate, refreshed on the next query — it can lag a (de)activation or an
|
|
1195
|
+
* already-deactivated member being added or removed. Editing
|
|
1196
|
+
* `channel.data.x` in place does not reach the state. `ownCapabilities` keeps its array while the
|
|
1197
|
+
* capabilities stay the same (in any order), so a subscriber to it is notified only when they
|
|
1198
|
+
* change.
|
|
1193
1199
|
*/
|
|
1194
1200
|
get data(): Partial<ChannelResponse> | undefined {
|
|
1195
1201
|
return this.state.getLatestValue().data;
|
|
@@ -1197,6 +1203,7 @@ export class Channel extends ChannelApi {
|
|
|
1197
1203
|
|
|
1198
1204
|
set data(next: Partial<ChannelResponse> | undefined) {
|
|
1199
1205
|
const {
|
|
1206
|
+
activeMemberCount: previousActiveMemberCount,
|
|
1200
1207
|
data: previous,
|
|
1201
1208
|
memberCount: previousMemberCount,
|
|
1202
1209
|
ownCapabilities: previousOwnCapabilities,
|
|
@@ -1205,27 +1212,40 @@ export class Channel extends ChannelApi {
|
|
|
1205
1212
|
typeof next?.member_count !== 'number' && typeof previous?.member_count === 'number'
|
|
1206
1213
|
? previous.member_count
|
|
1207
1214
|
: undefined;
|
|
1215
|
+
const carriedActiveMemberCount = next
|
|
1216
|
+
? getCarriedActiveMemberCount({ next, previous })
|
|
1217
|
+
: undefined;
|
|
1208
1218
|
// `own_capabilities` stays undefined until known, so "not loaded" isn't read as "none"
|
|
1209
1219
|
const carriedCapabilities =
|
|
1210
1220
|
!Array.isArray(next?.own_capabilities) && Array.isArray(previous?.own_capabilities)
|
|
1211
1221
|
? [...previous.own_capabilities]
|
|
1212
1222
|
: undefined;
|
|
1213
1223
|
|
|
1224
|
+
const carriesMemberCount = carriedMemberCount !== undefined;
|
|
1225
|
+
const carriesActiveMemberCount = carriedActiveMemberCount !== undefined;
|
|
1226
|
+
const carriesValues =
|
|
1227
|
+
carriesMemberCount || carriesActiveMemberCount || !!carriedCapabilities;
|
|
1228
|
+
|
|
1214
1229
|
const data =
|
|
1215
|
-
next &&
|
|
1230
|
+
next && carriesValues
|
|
1216
1231
|
? {
|
|
1217
1232
|
...next,
|
|
1218
|
-
...(
|
|
1233
|
+
...(carriesMemberCount && { member_count: carriedMemberCount }),
|
|
1234
|
+
...(carriesActiveMemberCount && {
|
|
1235
|
+
active_member_count: carriedActiveMemberCount,
|
|
1236
|
+
}),
|
|
1219
1237
|
...(carriedCapabilities && { own_capabilities: carriedCapabilities }),
|
|
1220
1238
|
}
|
|
1221
1239
|
: next;
|
|
1222
1240
|
|
|
1223
1241
|
const memberCount = data?.member_count ?? carriedMemberCount;
|
|
1242
|
+
const activeMemberCount = data ? data.active_member_count : previousActiveMemberCount;
|
|
1224
1243
|
const ownCapabilities = data?.own_capabilities ?? carriedCapabilities ?? [];
|
|
1225
1244
|
const toKey = (capabilities: readonly string[]) => [...capabilities].sort().join();
|
|
1226
1245
|
const haveSameOwnCapabilities =
|
|
1227
1246
|
toKey(previousOwnCapabilities) === toKey(ownCapabilities);
|
|
1228
1247
|
this.state.partialNext({
|
|
1248
|
+
activeMemberCount,
|
|
1229
1249
|
data,
|
|
1230
1250
|
memberCount: memberCount ?? previousMemberCount,
|
|
1231
1251
|
ownCapabilities: haveSameOwnCapabilities
|
package/src/channel_state.ts
CHANGED
package/src/client.ts
CHANGED
|
@@ -1733,6 +1733,22 @@ export class StreamChat extends ChatApi {
|
|
|
1733
1733
|
return result;
|
|
1734
1734
|
}
|
|
1735
1735
|
|
|
1736
|
+
override async updatePushNotificationPreferences(
|
|
1737
|
+
...args: Parameters<ChatApi['updatePushNotificationPreferences']>
|
|
1738
|
+
) {
|
|
1739
|
+
const result = await super.updatePushNotificationPreferences(...args);
|
|
1740
|
+
const { user } = this;
|
|
1741
|
+
if (!user) return result;
|
|
1742
|
+
|
|
1743
|
+
// The full stored preferences after the update, or null when the request only had
|
|
1744
|
+
// channel-level items for this user.
|
|
1745
|
+
const updated = result.user_preferences[user.id];
|
|
1746
|
+
if (updated) {
|
|
1747
|
+
this.user = { ...user, push_preferences: updated };
|
|
1748
|
+
}
|
|
1749
|
+
return result;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1736
1752
|
async unblockUser(blockedUserId: string, requestOptions?: StreamRequestOptions) {
|
|
1737
1753
|
const result = await this.unblockUsers(
|
|
1738
1754
|
{
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChannelResponse } from '../gen/models';
|
|
2
|
+
|
|
3
|
+
export const getCarriedActiveMemberCount = ({
|
|
4
|
+
next,
|
|
5
|
+
previous,
|
|
6
|
+
}: {
|
|
7
|
+
next: Partial<ChannelResponse>;
|
|
8
|
+
previous: Partial<ChannelResponse> | undefined;
|
|
9
|
+
}) => {
|
|
10
|
+
const { active_member_count: nextActiveMemberCount } = next;
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
active_member_count: previousActiveMemberCount,
|
|
14
|
+
member_count: previousMemberCount,
|
|
15
|
+
} = previous ?? {};
|
|
16
|
+
|
|
17
|
+
const hasOwnActiveMemberCount = typeof nextActiveMemberCount === 'number';
|
|
18
|
+
const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === 'number';
|
|
19
|
+
if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return undefined;
|
|
20
|
+
|
|
21
|
+
// Only Query Channels returns the count, so between queries shift the last known value
|
|
22
|
+
// by the change in member_count (an estimate, clamped to [0, member_count]).
|
|
23
|
+
const memberCount = next.member_count ?? previousMemberCount;
|
|
24
|
+
const delta =
|
|
25
|
+
typeof next.member_count === 'number' && typeof previousMemberCount === 'number'
|
|
26
|
+
? next.member_count - previousMemberCount
|
|
27
|
+
: 0;
|
|
28
|
+
const shifted = Math.max(0, previousActiveMemberCount + delta);
|
|
29
|
+
return typeof memberCount === 'number' ? Math.min(shifted, memberCount) : shifted;
|
|
30
|
+
};
|