stream-chat 9.54.4 → 9.56.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 +38 -4
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +38 -4
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +38 -4
- package/dist/esm/index.mjs.map +3 -3
- package/dist/types/channel.d.ts +3 -1
- package/dist/types/types.d.ts +43 -1
- package/dist/types/utils/activeMemberCount.d.ts +7 -0
- package/package.json +1 -1
- package/src/channel.ts +11 -1
- package/src/client.ts +13 -3
- package/src/types.ts +51 -2
- package/src/utils/activeMemberCount.ts +34 -0
package/dist/types/channel.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Channel {
|
|
|
13
13
|
_client: StreamChat;
|
|
14
14
|
type: string;
|
|
15
15
|
id: string | undefined;
|
|
16
|
-
|
|
16
|
+
private _channelData;
|
|
17
17
|
_data: Partial<ChannelData & ChannelResponse>;
|
|
18
18
|
cid: string;
|
|
19
19
|
/** */
|
|
@@ -55,6 +55,8 @@ export declare class Channel {
|
|
|
55
55
|
* @return {Channel} Returns a new uninitialized channel
|
|
56
56
|
*/
|
|
57
57
|
constructor(client: StreamChat, type: string, id: string | undefined, data: ChannelData);
|
|
58
|
+
get data(): Partial<ChannelData & ChannelResponse> | undefined;
|
|
59
|
+
set data(next: Partial<ChannelData & ChannelResponse> | undefined);
|
|
58
60
|
/**
|
|
59
61
|
* getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
|
|
60
62
|
*
|
package/dist/types/types.d.ts
CHANGED
|
@@ -41,6 +41,24 @@ export type APIResponse = {
|
|
|
41
41
|
duration: string;
|
|
42
42
|
blocklist?: BlockListResponse;
|
|
43
43
|
};
|
|
44
|
+
export type PagerDefaults = {
|
|
45
|
+
limit: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Request limit defaults applied by the server when the corresponding field is omitted.
|
|
49
|
+
*/
|
|
50
|
+
export type AppDefaults = {
|
|
51
|
+
get_or_create_channel: {
|
|
52
|
+
members: PagerDefaults;
|
|
53
|
+
messages: PagerDefaults;
|
|
54
|
+
};
|
|
55
|
+
query_channels: {
|
|
56
|
+
limit: number;
|
|
57
|
+
max_limit: number;
|
|
58
|
+
member_limit: number;
|
|
59
|
+
message_limit: number;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
44
62
|
export type TranslateResponse = {
|
|
45
63
|
language: string;
|
|
46
64
|
translated_text: string;
|
|
@@ -97,6 +115,7 @@ export type AppSettingsAPIResponse = APIResponse & {
|
|
|
97
115
|
cdn_expiration_seconds?: number;
|
|
98
116
|
chat_primary_use_case?: string;
|
|
99
117
|
custom_action_handler_url?: string;
|
|
118
|
+
defaults?: AppDefaults;
|
|
100
119
|
datadog_info?: {
|
|
101
120
|
api_key: string;
|
|
102
121
|
site: string;
|
|
@@ -165,6 +184,7 @@ export type AppSettingsAPIResponse = APIResponse & {
|
|
|
165
184
|
sqs_url?: string;
|
|
166
185
|
suspended?: boolean;
|
|
167
186
|
suspended_explanation?: string;
|
|
187
|
+
two_way_block_effect_enabled?: boolean;
|
|
168
188
|
use_hook_v2?: boolean;
|
|
169
189
|
user_response_time_enabled?: boolean;
|
|
170
190
|
user_search_disallowed_roles?: string[] | null;
|
|
@@ -280,6 +300,7 @@ export type ChannelResponse = CustomChannelData & {
|
|
|
280
300
|
frozen: boolean;
|
|
281
301
|
id: string;
|
|
282
302
|
type: string;
|
|
303
|
+
active_member_count?: number;
|
|
283
304
|
blocked?: boolean;
|
|
284
305
|
auto_translation_enabled?: boolean;
|
|
285
306
|
auto_translation_language?: TranslationLanguages;
|
|
@@ -613,14 +634,30 @@ export type PushPreference = {
|
|
|
613
634
|
chat_preferences?: ChatPreferences;
|
|
614
635
|
disabled_until?: string;
|
|
615
636
|
remove_disable?: boolean;
|
|
637
|
+
remove_schedule?: boolean;
|
|
638
|
+
schedule?: PushScheduleInput;
|
|
616
639
|
user_id?: string;
|
|
617
640
|
};
|
|
641
|
+
export type QuietHoursRuleInput = {
|
|
642
|
+
end: string;
|
|
643
|
+
start: string;
|
|
644
|
+
days?: string[];
|
|
645
|
+
};
|
|
646
|
+
export type PushScheduleInput = {
|
|
647
|
+
quiet_hours?: QuietHoursRuleInput[];
|
|
648
|
+
timezone?: string;
|
|
649
|
+
};
|
|
650
|
+
export type PushScheduleResponse = {
|
|
651
|
+
quiet_hours: QuietHoursRuleInput[];
|
|
652
|
+
timezone: string;
|
|
653
|
+
};
|
|
618
654
|
/** Per-user push preferences returned by the API (matches OpenAPI `PushPreferencesResponse`). */
|
|
619
655
|
export type PushPreferencesResponse = {
|
|
620
656
|
call_level?: CallLevelPushPreference;
|
|
621
657
|
chat_level?: ChatLevelPushPreference;
|
|
622
658
|
chat_preferences?: ChatPreferences;
|
|
623
659
|
disabled_until?: string;
|
|
660
|
+
schedule?: PushScheduleResponse;
|
|
624
661
|
};
|
|
625
662
|
/** Per-channel push preferences returned by the API (matches OpenAPI `ChannelPushPreferencesResponse`). */
|
|
626
663
|
export type ChannelPushPreference = {
|
|
@@ -965,6 +1002,7 @@ export type BanUserOptions = UnBanUserOptions & {
|
|
|
965
1002
|
delete_reactions?: boolean;
|
|
966
1003
|
};
|
|
967
1004
|
export type ChannelOptions = {
|
|
1005
|
+
include_active_member_count?: boolean;
|
|
968
1006
|
limit?: number;
|
|
969
1007
|
member_limit?: number;
|
|
970
1008
|
message_limit?: number;
|
|
@@ -2107,6 +2145,10 @@ export type ChannelConfigFields = {
|
|
|
2107
2145
|
};
|
|
2108
2146
|
export type ChannelConfigWithInfo = ChannelConfigFields & CreatedAtUpdatedAt & {
|
|
2109
2147
|
commands?: CommandResponse[];
|
|
2148
|
+
scheduled_messages_max_lead_time_seconds?: number;
|
|
2149
|
+
scheduled_messages_max_per_channel?: number;
|
|
2150
|
+
scheduled_messages_max_per_user?: number;
|
|
2151
|
+
scheduled_messages_min_lead_time_seconds?: number;
|
|
2110
2152
|
};
|
|
2111
2153
|
export type ChannelData = CustomChannelData & Partial<{
|
|
2112
2154
|
blocked: boolean;
|
|
@@ -2465,7 +2507,7 @@ export type DeleteChannelsResponse = {
|
|
|
2465
2507
|
} & Partial<TaskResponse>;
|
|
2466
2508
|
export type DeleteType = 'soft' | 'hard' | 'pruning';
|
|
2467
2509
|
export type DeleteUserOptions = {
|
|
2468
|
-
conversations?: Exclude<DeleteType, 'pruning'
|
|
2510
|
+
conversations?: Exclude<DeleteType, 'pruning'> | 'keep';
|
|
2469
2511
|
messages?: DeleteType;
|
|
2470
2512
|
new_channel_owner_id?: string;
|
|
2471
2513
|
user?: DeleteType;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChannelResponse } from '../types';
|
|
2
|
+
type MemberCounts = Pick<ChannelResponse, 'active_member_count' | 'member_count'>;
|
|
3
|
+
export declare const withCarriedActiveMemberCount: <TData extends MemberCounts>({ next, previous, }: {
|
|
4
|
+
next: TData;
|
|
5
|
+
previous?: MemberCounts;
|
|
6
|
+
}) => TData;
|
|
7
|
+
export {};
|
package/package.json
CHANGED
package/src/channel.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ChannelState } from './channel_state';
|
|
|
3
3
|
import { CooldownTimer } from './CooldownTimer';
|
|
4
4
|
import { MessageComposer } from './messageComposer';
|
|
5
5
|
import { MessageReceiptsTracker } from './messageDelivery';
|
|
6
|
+
import { withCarriedActiveMemberCount } from './utils/activeMemberCount';
|
|
6
7
|
import {
|
|
7
8
|
channelHasReadEvents,
|
|
8
9
|
generateChannelTempCid,
|
|
@@ -92,7 +93,7 @@ export class Channel {
|
|
|
92
93
|
_client: StreamChat;
|
|
93
94
|
type: string;
|
|
94
95
|
id: string | undefined;
|
|
95
|
-
|
|
96
|
+
private _channelData: Partial<ChannelData & ChannelResponse> | undefined;
|
|
96
97
|
_data: Partial<ChannelData & ChannelResponse>;
|
|
97
98
|
cid: string;
|
|
98
99
|
/** */
|
|
@@ -180,6 +181,15 @@ export class Channel {
|
|
|
180
181
|
this.cooldownTimer = new CooldownTimer({ channel: this });
|
|
181
182
|
}
|
|
182
183
|
|
|
184
|
+
public get data(): Partial<ChannelData & ChannelResponse> | undefined {
|
|
185
|
+
return this._channelData;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public set data(next: Partial<ChannelData & ChannelResponse> | undefined) {
|
|
189
|
+
const previous = this._channelData;
|
|
190
|
+
this._channelData = next && withCarriedActiveMemberCount({ next, previous });
|
|
191
|
+
}
|
|
192
|
+
|
|
183
193
|
/**
|
|
184
194
|
* getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
|
|
185
195
|
*
|
package/src/client.ts
CHANGED
|
@@ -2542,10 +2542,20 @@ export class StreamChat {
|
|
|
2542
2542
|
* @return {<UpsertPushPreferencesResponse>}
|
|
2543
2543
|
*/
|
|
2544
2544
|
async setPushPreferences(preferences: PushPreference[]) {
|
|
2545
|
-
|
|
2545
|
+
const result = await this.post<UpsertPushPreferencesResponse>(
|
|
2546
2546
|
this.baseURL + '/push_preferences',
|
|
2547
2547
|
{ preferences },
|
|
2548
2548
|
);
|
|
2549
|
+
const { user } = this;
|
|
2550
|
+
if (!user) return result;
|
|
2551
|
+
|
|
2552
|
+
// The full stored preferences after the update, or null when the request only had
|
|
2553
|
+
// channel-level items for this user.
|
|
2554
|
+
const updated = result.user_preferences[user.id];
|
|
2555
|
+
if (updated) {
|
|
2556
|
+
this.user = { ...user, push_preferences: updated };
|
|
2557
|
+
}
|
|
2558
|
+
return result;
|
|
2549
2559
|
}
|
|
2550
2560
|
|
|
2551
2561
|
/**
|
|
@@ -4656,10 +4666,10 @@ export class StreamChat {
|
|
|
4656
4666
|
}
|
|
4657
4667
|
if (
|
|
4658
4668
|
typeof options.conversations !== 'undefined' &&
|
|
4659
|
-
!['soft', 'hard'].includes(options.conversations)
|
|
4669
|
+
!['soft', 'hard', 'keep'].includes(options.conversations)
|
|
4660
4670
|
) {
|
|
4661
4671
|
throw new Error(
|
|
4662
|
-
'Invalid delete user options. conversations must be one of [soft hard]',
|
|
4672
|
+
'Invalid delete user options. conversations must be one of [soft hard keep]',
|
|
4663
4673
|
);
|
|
4664
4674
|
}
|
|
4665
4675
|
if (
|
package/src/types.ts
CHANGED
|
@@ -75,6 +75,26 @@ export type APIResponse = {
|
|
|
75
75
|
blocklist?: BlockListResponse;
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
+
export type PagerDefaults = {
|
|
79
|
+
limit: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Request limit defaults applied by the server when the corresponding field is omitted.
|
|
84
|
+
*/
|
|
85
|
+
export type AppDefaults = {
|
|
86
|
+
get_or_create_channel: {
|
|
87
|
+
members: PagerDefaults;
|
|
88
|
+
messages: PagerDefaults;
|
|
89
|
+
};
|
|
90
|
+
query_channels: {
|
|
91
|
+
limit: number;
|
|
92
|
+
max_limit: number;
|
|
93
|
+
member_limit: number;
|
|
94
|
+
message_limit: number;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
78
98
|
export type TranslateResponse = {
|
|
79
99
|
language: string;
|
|
80
100
|
translated_text: string;
|
|
@@ -143,6 +163,7 @@ export type AppSettingsAPIResponse = APIResponse & {
|
|
|
143
163
|
cdn_expiration_seconds?: number;
|
|
144
164
|
chat_primary_use_case?: string;
|
|
145
165
|
custom_action_handler_url?: string;
|
|
166
|
+
defaults?: AppDefaults;
|
|
146
167
|
datadog_info?: {
|
|
147
168
|
api_key: string;
|
|
148
169
|
site: string;
|
|
@@ -211,6 +232,7 @@ export type AppSettingsAPIResponse = APIResponse & {
|
|
|
211
232
|
sqs_url?: string;
|
|
212
233
|
suspended?: boolean;
|
|
213
234
|
suspended_explanation?: string;
|
|
235
|
+
two_way_block_effect_enabled?: boolean;
|
|
214
236
|
use_hook_v2?: boolean;
|
|
215
237
|
user_response_time_enabled?: boolean;
|
|
216
238
|
user_search_disallowed_roles?: string[] | null;
|
|
@@ -341,6 +363,7 @@ export type ChannelResponse = CustomChannelData & {
|
|
|
341
363
|
frozen: boolean;
|
|
342
364
|
id: string;
|
|
343
365
|
type: string;
|
|
366
|
+
active_member_count?: number;
|
|
344
367
|
blocked?: boolean;
|
|
345
368
|
auto_translation_enabled?: boolean;
|
|
346
369
|
auto_translation_language?: TranslationLanguages;
|
|
@@ -738,15 +761,34 @@ export type PushPreference = {
|
|
|
738
761
|
chat_preferences?: ChatPreferences;
|
|
739
762
|
disabled_until?: string; // snooze until this time
|
|
740
763
|
remove_disable?: boolean; // stop snoozing (clears disabled_until)
|
|
764
|
+
remove_schedule?: boolean;
|
|
765
|
+
schedule?: PushScheduleInput;
|
|
741
766
|
user_id?: string;
|
|
742
767
|
};
|
|
743
768
|
|
|
769
|
+
export type QuietHoursRuleInput = {
|
|
770
|
+
end: string;
|
|
771
|
+
start: string;
|
|
772
|
+
days?: string[];
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
export type PushScheduleInput = {
|
|
776
|
+
quiet_hours?: QuietHoursRuleInput[];
|
|
777
|
+
timezone?: string;
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
export type PushScheduleResponse = {
|
|
781
|
+
quiet_hours: QuietHoursRuleInput[];
|
|
782
|
+
timezone: string;
|
|
783
|
+
};
|
|
784
|
+
|
|
744
785
|
/** Per-user push preferences returned by the API (matches OpenAPI `PushPreferencesResponse`). */
|
|
745
786
|
export type PushPreferencesResponse = {
|
|
746
787
|
call_level?: CallLevelPushPreference;
|
|
747
788
|
chat_level?: ChatLevelPushPreference;
|
|
748
789
|
chat_preferences?: ChatPreferences;
|
|
749
790
|
disabled_until?: string;
|
|
791
|
+
schedule?: PushScheduleResponse;
|
|
750
792
|
};
|
|
751
793
|
|
|
752
794
|
/** Per-channel push preferences returned by the API (matches OpenAPI `ChannelPushPreferencesResponse`). */
|
|
@@ -1144,6 +1186,7 @@ export type BanUserOptions = UnBanUserOptions & {
|
|
|
1144
1186
|
};
|
|
1145
1187
|
|
|
1146
1188
|
export type ChannelOptions = {
|
|
1189
|
+
include_active_member_count?: boolean;
|
|
1147
1190
|
limit?: number;
|
|
1148
1191
|
member_limit?: number;
|
|
1149
1192
|
message_limit?: number;
|
|
@@ -2676,6 +2719,11 @@ export type ChannelConfigFields = {
|
|
|
2676
2719
|
export type ChannelConfigWithInfo = ChannelConfigFields &
|
|
2677
2720
|
CreatedAtUpdatedAt & {
|
|
2678
2721
|
commands?: CommandResponse[];
|
|
2722
|
+
// scheduled message limits, present only when the app has scheduled messages enabled
|
|
2723
|
+
scheduled_messages_max_lead_time_seconds?: number;
|
|
2724
|
+
scheduled_messages_max_per_channel?: number;
|
|
2725
|
+
scheduled_messages_max_per_user?: number;
|
|
2726
|
+
scheduled_messages_min_lead_time_seconds?: number;
|
|
2679
2727
|
};
|
|
2680
2728
|
|
|
2681
2729
|
export type ChannelData = CustomChannelData &
|
|
@@ -3347,10 +3395,11 @@ export type DeleteType = 'soft' | 'hard' | 'pruning';
|
|
|
3347
3395
|
`user`:
|
|
3348
3396
|
- soft: marks user as deleted and retains all user data
|
|
3349
3397
|
- pruning: marks user as deleted and nullifies user information
|
|
3350
|
-
- hard: deletes user completely - this requires hard option for messages and
|
|
3398
|
+
- hard: deletes user completely - this requires hard option for messages, and hard or keep option for conversations
|
|
3351
3399
|
`conversations`:
|
|
3352
3400
|
- soft: marks all conversation channels as deleted (same effect as Delete Channels with 'hard' option disabled)
|
|
3353
3401
|
- hard: deletes channel and all its data completely including messages (same effect as Delete Channels with 'hard' option enabled)
|
|
3402
|
+
- keep: doesn't delete any conversation channels. Use it with user hard, where an unset value defaults to hard
|
|
3354
3403
|
`messages`:
|
|
3355
3404
|
- soft: marks all user messages as deleted without removing any related message data
|
|
3356
3405
|
- pruning: marks all user messages as deleted, nullifies message information and removes some message data such as reactions and flags
|
|
@@ -3358,7 +3407,7 @@ export type DeleteType = 'soft' | 'hard' | 'pruning';
|
|
|
3358
3407
|
`new_channel_owner_id`: any channels owned by the hard-deleted user will be transferred to this user ID
|
|
3359
3408
|
*/
|
|
3360
3409
|
export type DeleteUserOptions = {
|
|
3361
|
-
conversations?: Exclude<DeleteType, 'pruning'
|
|
3410
|
+
conversations?: Exclude<DeleteType, 'pruning'> | 'keep';
|
|
3362
3411
|
messages?: DeleteType;
|
|
3363
3412
|
new_channel_owner_id?: string;
|
|
3364
3413
|
user?: DeleteType;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ChannelResponse } from '../types';
|
|
2
|
+
|
|
3
|
+
type MemberCounts = Pick<ChannelResponse, 'active_member_count' | 'member_count'>;
|
|
4
|
+
|
|
5
|
+
export const withCarriedActiveMemberCount = <TData extends MemberCounts>({
|
|
6
|
+
next,
|
|
7
|
+
previous,
|
|
8
|
+
}: {
|
|
9
|
+
next: TData;
|
|
10
|
+
previous?: MemberCounts;
|
|
11
|
+
}) => {
|
|
12
|
+
const { active_member_count: nextActiveMemberCount, member_count: nextMemberCount } =
|
|
13
|
+
next;
|
|
14
|
+
const {
|
|
15
|
+
active_member_count: previousActiveMemberCount,
|
|
16
|
+
member_count: previousMemberCount,
|
|
17
|
+
} = previous ?? {};
|
|
18
|
+
const hasOwnActiveMemberCount = typeof nextActiveMemberCount === 'number';
|
|
19
|
+
const hasPreviousActiveMemberCount = typeof previousActiveMemberCount === 'number';
|
|
20
|
+
if (hasOwnActiveMemberCount || !hasPreviousActiveMemberCount) return next;
|
|
21
|
+
|
|
22
|
+
// Only Query Channels returns the count, so between queries shift the last known value
|
|
23
|
+
// by the change in member_count (an estimate, clamped to [0, member_count]).
|
|
24
|
+
const memberCount = nextMemberCount ?? previousMemberCount;
|
|
25
|
+
const delta =
|
|
26
|
+
typeof nextMemberCount === 'number' && typeof previousMemberCount === 'number'
|
|
27
|
+
? nextMemberCount - previousMemberCount
|
|
28
|
+
: 0;
|
|
29
|
+
const shifted = Math.max(0, previousActiveMemberCount + delta);
|
|
30
|
+
const carriedActiveMemberCount =
|
|
31
|
+
typeof memberCount === 'number' ? Math.min(shifted, memberCount) : shifted;
|
|
32
|
+
|
|
33
|
+
return { ...next, active_member_count: carriedActiveMemberCount };
|
|
34
|
+
};
|