stream-chat 9.44.1 → 9.44.2
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 +93 -29
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +93 -29
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +93 -29
- package/dist/esm/index.mjs.map +2 -2
- package/dist/types/channel_manager.d.ts +5 -2
- package/dist/types/client.d.ts +32 -3
- package/dist/types/types.d.ts +9 -0
- package/package.json +1 -1
- package/src/channel_manager.ts +88 -13
- package/src/client.ts +74 -10
- package/src/types.ts +9 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StreamChat } from './client';
|
|
1
|
+
import type { QueryChannelsResponseWithChannels, StreamChat } from './client';
|
|
2
2
|
import type { ChannelFilters, ChannelOptions, ChannelSort, ChannelStateOptions, Event } from './types';
|
|
3
3
|
import type { ValueOrPatch } from './store';
|
|
4
4
|
import { StateStore } from './store';
|
|
@@ -10,6 +10,8 @@ export type ChannelManagerPagination = {
|
|
|
10
10
|
isLoading: boolean;
|
|
11
11
|
isLoadingNext: boolean;
|
|
12
12
|
options: ChannelOptions;
|
|
13
|
+
responseFilters?: ChannelFilters;
|
|
14
|
+
responseSort?: ChannelSort;
|
|
13
15
|
sort: ChannelSort;
|
|
14
16
|
};
|
|
15
17
|
export type ChannelManagerState = {
|
|
@@ -64,7 +66,8 @@ export type ChannelManagerOptions = {
|
|
|
64
66
|
*/
|
|
65
67
|
lockChannelOrder?: boolean;
|
|
66
68
|
};
|
|
67
|
-
export type
|
|
69
|
+
export type QueryChannelsRequestOutput = Channel[] | QueryChannelsResponseWithChannels;
|
|
70
|
+
export type QueryChannelsRequestType = (filters: ChannelFilters, sort?: ChannelSort, options?: ChannelOptions, stateOptions?: ChannelStateOptions) => Promise<QueryChannelsRequestOutput>;
|
|
68
71
|
export declare const DEFAULT_CHANNEL_MANAGER_OPTIONS: {
|
|
69
72
|
abortInFlightQuery: boolean;
|
|
70
73
|
allowNotLoadedChannelPromotionForEvent: {
|
package/dist/types/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { WSConnectionFallback } from './connection_fallback';
|
|
|
8
8
|
import { Campaign } from './campaign';
|
|
9
9
|
import { ChannelBatchUpdater } from './channel_batch_updater';
|
|
10
10
|
import { Segment } from './segment';
|
|
11
|
-
import type { ActiveLiveLocationsAPIResponse, APIErrorResponse, APIResponse, AppSettings, AppSettingsAPIResponse, BannedUsersFilters, BannedUsersPaginationOptions, BannedUsersResponse, BannedUsersSort, BanUserOptions, BaseDeviceFields, BlockList, BlockListResponse, BlockUserAPIResponse, CampaignData, CampaignFilters, CampaignQueryOptions, CampaignResponse, CampaignSort, CastVoteAPIResponse, ChannelAPIResponse, ChannelData, ChannelFilters, ChannelMute, ChannelOptions, ChannelResponse, ChannelSort, ChannelStateOptions, CheckPushResponse, CheckSNSResponse, CheckSQSResponse, Configs, ConnectAPIResponse, CreateChannelOptions, CreateChannelResponse, CreateCommandOptions, CreateCommandResponse, CreateImportOptions, CreateImportResponse, CreateImportURLResponse, CreatePollAPIResponse, CreatePollData, CreatePollOptionAPIResponse, CreatePredefinedFilterOptions, CreateReminderOptions, CustomPermissionOptions, DeactivateUsersOptions, DeleteCommandResponse, DeleteMessageOptions, DeleteUserOptions, Device, DeviceIdentifier, DraftFilters, DraftSort, EndpointName, Event, EventAPIResponse, EventHandler, ExportChannelOptions, ExportChannelRequest, ExportChannelResponse, ExportChannelStatusResponse, ExportUsersRequest, ExportUsersResponse, FlagMessageResponse, FlagReportsFilters, FlagReportsPaginationOptions, FlagReportsResponse, FlagsFilters, FlagsPaginationOptions, FlagsResponse, FlagUserResponse, FutureChannelBansResponse, GetBlockedUsersAPIResponse, GetCampaignOptions, GetChannelTypeResponse, GetCommandResponse, GetHookEventsResponse, GetImportResponse, GetMessageOptions, GetPollAPIResponse, GetRateLimitsResponse, GetRetentionPolicyResponse, GetRetentionPolicyRunsOptions, GetRetentionPolicyRunsResponse, GetThreadAPIResponse, GetThreadOptions, GetUnreadCountAPIResponse, GetUnreadCountBatchAPIResponse, ListChannelResponse, ListCommandsResponse, ListImportsPaginationOptions, ListImportsResponse, ListPredefinedFiltersOptions, ListPredefinedFiltersResponse, LocalMessage, Logger, MarkChannelsReadOptions, MarkDeliveredOptions, MessageFilters, MessageFlagsFilters, MessageFlagsPaginationOptions, MessageFlagsResponse, MessageResponse, Mute, MuteUserOptions, MuteUserResponse, OGAttachment, OwnUserResponse, Pager, PartialMessageUpdate, PartialPollUpdate, PartialThreadUpdate, PartialUserUpdate, PermissionAPIResponse, PermissionsAPIResponse, PollAnswersAPIResponse, PollData, PollOptionData, PollSort, PollVote, PollVoteData, PollVotesAPIResponse, PredefinedFilterResponse, Product, PushPreference, PushProvider, PushProviderConfig, PushProviderID, PushProviderListResponse, PushProviderUpsertResponse, QueryDraftsResponse, QueryFutureChannelBansOptions, QueryMessageHistoryFilters, QueryMessageHistoryOptions, QueryMessageHistoryResponse, QueryMessageHistorySort, QueryPollsFilters, QueryPollsOptions, QueryPollsResponse, QueryReactionsAPIResponse, QueryReactionsOptions, QueryRemindersOptions, QueryRemindersResponse, QuerySegmentsOptions, QuerySegmentTargetsFilter, QueryTeamUsageStatsOptions, QueryTeamUsageStatsResponse, QueryThreadsOptions, QueryVotesFilters, QueryVotesOptions, ReactionFilters, ReactionResponse, ReactionSort, ReactivateUserOptions, ReactivateUsersOptions, ReminderAPIResponse, ReviewFlagReportOptions, ReviewFlagReportResponse, SdkIdentifier, SearchAPIResponse, SearchOptions, SegmentData, SegmentResponse, SegmentTargetsResponse, SegmentType, SendFileAPIResponse, SetRetentionPolicyResponse, SharedLocationResponse, SortParam, StreamChatOptions, SyncOptions, SyncResponse, TaskResponse, TaskStatus, TestPushDataInput, TestSNSDataInput, TestSQSDataInput, TokenOrProvider, TranslateResponse, UnBanUserOptions, UpdateChannelsBatchOptions, UpdateChannelTypeRequest, UpdateChannelTypeResponse, UpdateCommandOptions, UpdateCommandResponse, UpdateLocationPayload, UpdateMessageAPIResponse, UpdateMessageOptions, UpdatePollAPIResponse, UpdatePredefinedFilterOptions, UpdateReminderOptions, UpdateSegmentData, UpdateUsersAPIResponse, UpsertPushPreferencesResponse, UserCustomEvent, UserFilters, UserOptions, UserResponse, UserSort, VoteSort } from './types';
|
|
11
|
+
import type { ActiveLiveLocationsAPIResponse, APIErrorResponse, APIResponse, AppSettings, AppSettingsAPIResponse, BannedUsersFilters, BannedUsersPaginationOptions, BannedUsersResponse, BannedUsersSort, BanUserOptions, BaseDeviceFields, BlockList, BlockListResponse, BlockUserAPIResponse, CampaignData, CampaignFilters, CampaignQueryOptions, CampaignResponse, CampaignSort, CastVoteAPIResponse, ChannelAPIResponse, ChannelData, ChannelFilters, ChannelMute, ChannelOptions, ChannelResponse, ChannelSort, ChannelStateOptions, CheckPushResponse, CheckSNSResponse, CheckSQSResponse, Configs, ConnectAPIResponse, CreateChannelOptions, CreateChannelResponse, CreateCommandOptions, CreateCommandResponse, CreateImportOptions, CreateImportResponse, CreateImportURLResponse, CreatePollAPIResponse, CreatePollData, CreatePollOptionAPIResponse, CreatePredefinedFilterOptions, CreateReminderOptions, CustomPermissionOptions, DeactivateUsersOptions, DeleteCommandResponse, DeleteMessageOptions, DeleteUserOptions, Device, DeviceIdentifier, DraftFilters, DraftSort, EndpointName, Event, EventAPIResponse, EventHandler, ExportChannelOptions, ExportChannelRequest, ExportChannelResponse, ExportChannelStatusResponse, ExportUsersRequest, ExportUsersResponse, FlagMessageResponse, FlagReportsFilters, FlagReportsPaginationOptions, FlagReportsResponse, FlagsFilters, FlagsPaginationOptions, FlagsResponse, FlagUserResponse, FutureChannelBansResponse, GetBlockedUsersAPIResponse, GetCampaignOptions, GetChannelTypeResponse, GetCommandResponse, GetHookEventsResponse, GetImportResponse, GetMessageOptions, GetPollAPIResponse, GetRateLimitsResponse, GetRetentionPolicyResponse, GetRetentionPolicyRunsOptions, GetRetentionPolicyRunsResponse, GetThreadAPIResponse, GetThreadOptions, GetUnreadCountAPIResponse, GetUnreadCountBatchAPIResponse, ListChannelResponse, ListCommandsResponse, ListImportsPaginationOptions, ListImportsResponse, ListPredefinedFiltersOptions, ListPredefinedFiltersResponse, LocalMessage, Logger, MarkChannelsReadOptions, MarkDeliveredOptions, MessageFilters, MessageFlagsFilters, MessageFlagsPaginationOptions, MessageFlagsResponse, MessageResponse, Mute, MuteUserOptions, MuteUserResponse, OGAttachment, OwnUserResponse, Pager, PartialMessageUpdate, PartialPollUpdate, PartialThreadUpdate, PartialUserUpdate, PermissionAPIResponse, PermissionsAPIResponse, PollAnswersAPIResponse, PollData, PollOptionData, PollSort, PollVote, PollVoteData, PollVotesAPIResponse, PredefinedFilterResponse, Product, PushPreference, PushProvider, PushProviderConfig, PushProviderID, PushProviderListResponse, PushProviderUpsertResponse, QueryChannelsAPIResponse, QueryDraftsResponse, QueryFutureChannelBansOptions, QueryMessageHistoryFilters, QueryMessageHistoryOptions, QueryMessageHistoryResponse, QueryMessageHistorySort, QueryPollsFilters, QueryPollsOptions, QueryPollsResponse, QueryReactionsAPIResponse, QueryReactionsOptions, QueryRemindersOptions, QueryRemindersResponse, QuerySegmentsOptions, QuerySegmentTargetsFilter, QueryTeamUsageStatsOptions, QueryTeamUsageStatsResponse, QueryThreadsOptions, QueryVotesFilters, QueryVotesOptions, ReactionFilters, ReactionResponse, ReactionSort, ReactivateUserOptions, ReactivateUsersOptions, ReminderAPIResponse, ReviewFlagReportOptions, ReviewFlagReportResponse, SdkIdentifier, SearchAPIResponse, SearchOptions, SegmentData, SegmentResponse, SegmentTargetsResponse, SegmentType, SendFileAPIResponse, SetRetentionPolicyResponse, SharedLocationResponse, SortParam, StreamChatOptions, SyncOptions, SyncResponse, TaskResponse, TaskStatus, TestPushDataInput, TestSNSDataInput, TestSQSDataInput, TokenOrProvider, TranslateResponse, UnBanUserOptions, UpdateChannelsBatchOptions, UpdateChannelTypeRequest, UpdateChannelTypeResponse, UpdateCommandOptions, UpdateCommandResponse, UpdateLocationPayload, UpdateMessageAPIResponse, UpdateMessageOptions, UpdatePollAPIResponse, UpdatePredefinedFilterOptions, UpdateReminderOptions, UpdateSegmentData, UpdateUsersAPIResponse, UpsertPushPreferencesResponse, UserCustomEvent, UserFilters, UserOptions, UserResponse, UserSort, VoteSort } from './types';
|
|
12
12
|
import { ErrorFromResponse } from './types';
|
|
13
13
|
import { InsightMetrics } from './insights';
|
|
14
14
|
import { Thread } from './thread';
|
|
@@ -24,6 +24,9 @@ import { StateStore } from './store';
|
|
|
24
24
|
import type { MessageComposer } from './messageComposer';
|
|
25
25
|
import type { AbstractOfflineDB } from './offline-support';
|
|
26
26
|
type MessageComposerTearDownFunction = () => void;
|
|
27
|
+
export type QueryChannelsResponseWithChannels = Omit<QueryChannelsAPIResponse, 'channels'> & {
|
|
28
|
+
channels: Channel[];
|
|
29
|
+
};
|
|
27
30
|
type MessageComposerSetupFunction = ({ composer, }: {
|
|
28
31
|
composer: MessageComposer;
|
|
29
32
|
}) => void | MessageComposerTearDownFunction;
|
|
@@ -513,7 +516,29 @@ export declare class StreamChat {
|
|
|
513
516
|
*/
|
|
514
517
|
queryMessageFlags(filterConditions?: MessageFlagsFilters, options?: MessageFlagsPaginationOptions): Promise<MessageFlagsResponse>;
|
|
515
518
|
/**
|
|
516
|
-
*
|
|
519
|
+
* queryChannelsRequestWithResponse - Queries channels and returns the full API response
|
|
520
|
+
* including top-level metadata such as `predefined_filter`.
|
|
521
|
+
*
|
|
522
|
+
* This exists as a compatibility bridge, as changing `queryChannelsRequest()` to return
|
|
523
|
+
* `QueryChannelsAPIResponse` would be a breaking change because it currently returns
|
|
524
|
+
* only the channel list. In the next major release, the request/response APIs should
|
|
525
|
+
* be consolidated so callers can access the full response through the primary API.
|
|
526
|
+
*
|
|
527
|
+
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
528
|
+
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
529
|
+
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
530
|
+
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
531
|
+
*
|
|
532
|
+
* @return {Promise<QueryChannelsAPIResponse>} full search channels response
|
|
533
|
+
*/
|
|
534
|
+
queryChannelsRequestWithResponse(filterConditions: ChannelFilters, sort?: ChannelSort, options?: ChannelOptions): Promise<QueryChannelsAPIResponse>;
|
|
535
|
+
/**
|
|
536
|
+
* queryChannelsRequest - Queries channels and returns the raw channel response list.
|
|
537
|
+
*
|
|
538
|
+
* This preserves the historical return shape for backwards compatibility. Use
|
|
539
|
+
* `queryChannelsRequestWithResponse()` when response level metadata such as
|
|
540
|
+
* `predefined_filter` is needed. In the next major release these APIs should be
|
|
541
|
+
* consolidated into a single full-response API.
|
|
517
542
|
*
|
|
518
543
|
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
519
544
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
@@ -533,10 +558,14 @@ export declare class StreamChat {
|
|
|
533
558
|
* @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
|
|
534
559
|
* - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
|
|
535
560
|
* - stateOptions.skipHydration - Skips returning the channels as instances of the Channel class and rather returns the raw query response.
|
|
561
|
+
* - stateOptions.withResponse - Returns the full query response with hydrated channels. This is a compatibility bridge for internal callers that need response-level metadata while the default return value remains `Channel[]`.
|
|
536
562
|
*
|
|
537
563
|
* @return {Promise<Array<Channel>>} search channels response
|
|
538
564
|
*/
|
|
539
|
-
queryChannels(filterConditions: ChannelFilters, sort
|
|
565
|
+
queryChannels(filterConditions: ChannelFilters, sort: ChannelSort, options: ChannelOptions, stateOptions: ChannelStateOptions & {
|
|
566
|
+
withResponse: true;
|
|
567
|
+
}): Promise<QueryChannelsResponseWithChannels>;
|
|
568
|
+
queryChannels(filterConditions?: ChannelFilters, sort?: ChannelSort, options?: ChannelOptions, stateOptions?: ChannelStateOptions): Promise<Channel[]>;
|
|
540
569
|
/**
|
|
541
570
|
* queryReactions - Query reactions
|
|
542
571
|
*
|
package/dist/types/types.d.ts
CHANGED
|
@@ -949,6 +949,15 @@ export type ChannelStateOptions = {
|
|
|
949
949
|
offlineMode?: boolean;
|
|
950
950
|
skipInitialization?: string[];
|
|
951
951
|
skipHydration?: boolean;
|
|
952
|
+
/**
|
|
953
|
+
* Returns the full query response with hydrated channels from `queryChannels()`.
|
|
954
|
+
*
|
|
955
|
+
* This is a compatibility bridge for internal callers that need response level
|
|
956
|
+
* metadata such as `predefined_filter`. The default `queryChannels()` return value
|
|
957
|
+
* remains `Channel[]` to avoid a breaking change. This should be folded into a
|
|
958
|
+
* single full response API in the next major release.
|
|
959
|
+
*/
|
|
960
|
+
withResponse?: boolean;
|
|
952
961
|
};
|
|
953
962
|
export type CreateChannelOptions = {
|
|
954
963
|
automod?: ChannelConfigAutomod;
|
package/package.json
CHANGED
package/src/channel_manager.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { StreamChat } from './client';
|
|
1
|
+
import type { QueryChannelsResponseWithChannels, StreamChat } from './client';
|
|
2
2
|
import type {
|
|
3
3
|
ChannelFilters,
|
|
4
4
|
ChannelOptions,
|
|
5
5
|
ChannelSort,
|
|
6
6
|
ChannelStateOptions,
|
|
7
7
|
Event,
|
|
8
|
+
QueryChannelsAPIResponse,
|
|
8
9
|
} from './types';
|
|
9
10
|
import type { ValueOrPatch } from './store';
|
|
10
11
|
import { isPatch, StateStore } from './store';
|
|
@@ -34,6 +35,8 @@ export type ChannelManagerPagination = {
|
|
|
34
35
|
isLoading: boolean;
|
|
35
36
|
isLoadingNext: boolean;
|
|
36
37
|
options: ChannelOptions;
|
|
38
|
+
responseFilters?: ChannelFilters;
|
|
39
|
+
responseSort?: ChannelSort;
|
|
37
40
|
sort: ChannelSort;
|
|
38
41
|
};
|
|
39
42
|
|
|
@@ -133,9 +136,14 @@ export type ChannelManagerOptions = {
|
|
|
133
136
|
lockChannelOrder?: boolean;
|
|
134
137
|
};
|
|
135
138
|
|
|
139
|
+
export type QueryChannelsRequestOutput = Channel[] | QueryChannelsResponseWithChannels;
|
|
140
|
+
|
|
136
141
|
export type QueryChannelsRequestType = (
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
filters: ChannelFilters,
|
|
143
|
+
sort?: ChannelSort,
|
|
144
|
+
options?: ChannelOptions,
|
|
145
|
+
stateOptions?: ChannelStateOptions,
|
|
146
|
+
) => Promise<QueryChannelsRequestOutput>;
|
|
139
147
|
|
|
140
148
|
export const DEFAULT_CHANNEL_MANAGER_OPTIONS = {
|
|
141
149
|
abortInFlightQuery: false,
|
|
@@ -152,6 +160,54 @@ export const DEFAULT_CHANNEL_MANAGER_PAGINATION_OPTIONS = {
|
|
|
152
160
|
offset: 0,
|
|
153
161
|
};
|
|
154
162
|
|
|
163
|
+
const mapPredefinedFilterSortToChannelSort = (
|
|
164
|
+
sort: NonNullable<QueryChannelsAPIResponse['predefined_filter']>['sort'],
|
|
165
|
+
): ChannelSort =>
|
|
166
|
+
(sort ?? []).map(({ direction = 1, field }) => ({
|
|
167
|
+
[field]: direction,
|
|
168
|
+
})) as ChannelSort;
|
|
169
|
+
|
|
170
|
+
const getResponsePaginationParams = ({
|
|
171
|
+
queryChannelsResponse,
|
|
172
|
+
sort,
|
|
173
|
+
}: {
|
|
174
|
+
queryChannelsResponse?: Pick<QueryChannelsAPIResponse, 'predefined_filter'>;
|
|
175
|
+
sort: ChannelSort;
|
|
176
|
+
}): Pick<ChannelManagerPagination, 'responseFilters' | 'responseSort'> => {
|
|
177
|
+
const predefinedFilter = queryChannelsResponse?.predefined_filter;
|
|
178
|
+
|
|
179
|
+
if (!predefinedFilter) {
|
|
180
|
+
return {};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
responseFilters: predefinedFilter.filter as ChannelFilters,
|
|
185
|
+
responseSort:
|
|
186
|
+
predefinedFilter.sort !== undefined
|
|
187
|
+
? mapPredefinedFilterSortToChannelSort(predefinedFilter.sort)
|
|
188
|
+
: sort,
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const getResponseFiltersAndSort = (
|
|
193
|
+
pagination: ChannelManagerPagination,
|
|
194
|
+
): Pick<ChannelManagerPagination, 'filters' | 'sort'> => ({
|
|
195
|
+
filters: pagination.responseFilters ?? pagination.filters,
|
|
196
|
+
sort: pagination.responseSort ?? pagination.sort,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const omitResponsePaginationParams = (pagination: ChannelManagerPagination) => {
|
|
200
|
+
const paginationWithoutResponseParams = { ...pagination };
|
|
201
|
+
delete paginationWithoutResponseParams.responseFilters;
|
|
202
|
+
delete paginationWithoutResponseParams.responseSort;
|
|
203
|
+
|
|
204
|
+
return paginationWithoutResponseParams;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const isQueryChannelsResponseWithChannels = (
|
|
208
|
+
response: QueryChannelsRequestOutput,
|
|
209
|
+
): response is QueryChannelsResponseWithChannels => !Array.isArray(response);
|
|
210
|
+
|
|
155
211
|
/**
|
|
156
212
|
* A class that manages a list of channels and changes it based on configuration and WS events. The
|
|
157
213
|
* list of channels is reactive as well as the pagination and it can be subscribed to for state updates.
|
|
@@ -279,23 +335,39 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
279
335
|
...options,
|
|
280
336
|
};
|
|
281
337
|
try {
|
|
282
|
-
const
|
|
338
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
283
339
|
filters,
|
|
284
340
|
sort,
|
|
285
341
|
options,
|
|
286
|
-
stateOptions,
|
|
342
|
+
{ ...stateOptions, withResponse: true },
|
|
287
343
|
);
|
|
344
|
+
const channels = isQueryChannelsResponseWithChannels(queryChannelsResponse)
|
|
345
|
+
? queryChannelsResponse.channels
|
|
346
|
+
: queryChannelsResponse;
|
|
288
347
|
const newOffset = offset + (channels?.length ?? 0);
|
|
289
348
|
const newOptions = { ...options, offset: newOffset };
|
|
290
349
|
const { pagination } = this.state.getLatestValue();
|
|
350
|
+
const responsePaginationParams = getResponsePaginationParams({
|
|
351
|
+
queryChannelsResponse: isQueryChannelsResponseWithChannels(queryChannelsResponse)
|
|
352
|
+
? queryChannelsResponse
|
|
353
|
+
: undefined,
|
|
354
|
+
sort,
|
|
355
|
+
});
|
|
356
|
+
const paginationWithoutResponseParams = omitResponsePaginationParams(pagination);
|
|
291
357
|
|
|
292
358
|
this.state.partialNext({
|
|
293
359
|
channels,
|
|
294
360
|
pagination: {
|
|
295
|
-
|
|
361
|
+
// Drop response derived filter/sort from the previous query before applying
|
|
362
|
+
// the current response. Non predefined queries do not return this metadata,
|
|
363
|
+
// so keeping the old values would make later WS mutations use stale
|
|
364
|
+
// predefined filter semantics. Also the predefined_filter might change, producing
|
|
365
|
+
// a different combination as well so we always need to first clean up.
|
|
366
|
+
...paginationWithoutResponseParams,
|
|
296
367
|
hasNext: (channels?.length ?? 0) >= (limit ?? 1),
|
|
297
368
|
isLoading: false,
|
|
298
369
|
options: newOptions,
|
|
370
|
+
...responsePaginationParams,
|
|
299
371
|
},
|
|
300
372
|
initialized: true,
|
|
301
373
|
error: undefined,
|
|
@@ -368,7 +440,7 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
368
440
|
this.state.next((currentState) => ({
|
|
369
441
|
...currentState,
|
|
370
442
|
pagination: {
|
|
371
|
-
...currentState.pagination,
|
|
443
|
+
...omitResponsePaginationParams(currentState.pagination),
|
|
372
444
|
isLoading: true,
|
|
373
445
|
isLoadingNext: false,
|
|
374
446
|
filters,
|
|
@@ -434,12 +506,15 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
434
506
|
this.state.partialNext({
|
|
435
507
|
pagination: { ...pagination, isLoading: false, isLoadingNext: true },
|
|
436
508
|
});
|
|
437
|
-
const
|
|
509
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
438
510
|
filters,
|
|
439
511
|
sort,
|
|
440
512
|
options,
|
|
441
513
|
this.stateOptions,
|
|
442
514
|
);
|
|
515
|
+
const nextChannels = isQueryChannelsResponseWithChannels(queryChannelsResponse)
|
|
516
|
+
? queryChannelsResponse.channels
|
|
517
|
+
: queryChannelsResponse;
|
|
443
518
|
const { channels } = this.state.getLatestValue();
|
|
444
519
|
const newOffset = offset + (nextChannels?.length ?? 0);
|
|
445
520
|
const newOptions = { ...options, offset: newOffset };
|
|
@@ -498,7 +573,7 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
498
573
|
return;
|
|
499
574
|
}
|
|
500
575
|
|
|
501
|
-
const { sort } = pagination
|
|
576
|
+
const { sort } = getResponseFiltersAndSort(pagination);
|
|
502
577
|
|
|
503
578
|
this.setChannels(
|
|
504
579
|
promoteChannel({
|
|
@@ -535,7 +610,7 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
535
610
|
if (!channels) {
|
|
536
611
|
return;
|
|
537
612
|
}
|
|
538
|
-
const { filters, sort } = pagination
|
|
613
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
539
614
|
|
|
540
615
|
const channelType = event.channel_type;
|
|
541
616
|
const channelId = event.channel_id;
|
|
@@ -594,7 +669,7 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
594
669
|
});
|
|
595
670
|
|
|
596
671
|
const { channels, pagination } = this.state.getLatestValue();
|
|
597
|
-
const { filters, sort } = pagination
|
|
672
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
598
673
|
|
|
599
674
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
600
675
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
@@ -631,7 +706,7 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
631
706
|
});
|
|
632
707
|
|
|
633
708
|
const { channels, pagination } = this.state.getLatestValue();
|
|
634
|
-
const {
|
|
709
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
635
710
|
|
|
636
711
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
637
712
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
@@ -658,7 +733,7 @@ export class ChannelManager extends WithSubscriptions {
|
|
|
658
733
|
|
|
659
734
|
private memberUpdatedHandler = (event: Event) => {
|
|
660
735
|
const { pagination, channels } = this.state.getLatestValue();
|
|
661
|
-
const { filters, sort } = pagination;
|
|
736
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
662
737
|
if (
|
|
663
738
|
!event.member?.user ||
|
|
664
739
|
event.member.user.id !== this.client.userID ||
|
package/src/client.ts
CHANGED
|
@@ -281,6 +281,13 @@ function isString(x: unknown): x is string {
|
|
|
281
281
|
|
|
282
282
|
type MessageComposerTearDownFunction = () => void;
|
|
283
283
|
|
|
284
|
+
export type QueryChannelsResponseWithChannels = Omit<
|
|
285
|
+
QueryChannelsAPIResponse,
|
|
286
|
+
'channels'
|
|
287
|
+
> & {
|
|
288
|
+
channels: Channel[];
|
|
289
|
+
};
|
|
290
|
+
|
|
284
291
|
type MessageComposerSetupFunction = ({
|
|
285
292
|
composer,
|
|
286
293
|
}: {
|
|
@@ -1888,20 +1895,26 @@ export class StreamChat {
|
|
|
1888
1895
|
}
|
|
1889
1896
|
|
|
1890
1897
|
/**
|
|
1891
|
-
*
|
|
1898
|
+
* queryChannelsRequestWithResponse - Queries channels and returns the full API response
|
|
1899
|
+
* including top-level metadata such as `predefined_filter`.
|
|
1900
|
+
*
|
|
1901
|
+
* This exists as a compatibility bridge, as changing `queryChannelsRequest()` to return
|
|
1902
|
+
* `QueryChannelsAPIResponse` would be a breaking change because it currently returns
|
|
1903
|
+
* only the channel list. In the next major release, the request/response APIs should
|
|
1904
|
+
* be consolidated so callers can access the full response through the primary API.
|
|
1892
1905
|
*
|
|
1893
1906
|
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
1894
1907
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
1895
1908
|
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
1896
1909
|
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
1897
1910
|
*
|
|
1898
|
-
* @return {Promise<
|
|
1911
|
+
* @return {Promise<QueryChannelsAPIResponse>} full search channels response
|
|
1899
1912
|
*/
|
|
1900
|
-
async
|
|
1913
|
+
async queryChannelsRequestWithResponse(
|
|
1901
1914
|
filterConditions: ChannelFilters,
|
|
1902
1915
|
sort: ChannelSort = [],
|
|
1903
1916
|
options: ChannelOptions = {},
|
|
1904
|
-
) {
|
|
1917
|
+
): Promise<QueryChannelsAPIResponse> {
|
|
1905
1918
|
const defaultOptions: ChannelOptions = {
|
|
1906
1919
|
state: true,
|
|
1907
1920
|
watch: true,
|
|
@@ -1934,9 +1947,33 @@ export class StreamChat {
|
|
|
1934
1947
|
...restOptions,
|
|
1935
1948
|
};
|
|
1936
1949
|
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1950
|
+
return await this.post<QueryChannelsAPIResponse>(this.baseURL + '/channels', payload);
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
/**
|
|
1954
|
+
* queryChannelsRequest - Queries channels and returns the raw channel response list.
|
|
1955
|
+
*
|
|
1956
|
+
* This preserves the historical return shape for backwards compatibility. Use
|
|
1957
|
+
* `queryChannelsRequestWithResponse()` when response level metadata such as
|
|
1958
|
+
* `predefined_filter` is needed. In the next major release these APIs should be
|
|
1959
|
+
* consolidated into a single full-response API.
|
|
1960
|
+
*
|
|
1961
|
+
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
1962
|
+
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
1963
|
+
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
1964
|
+
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
1965
|
+
*
|
|
1966
|
+
* @return {Promise<Array<ChannelAPIResponse>>} search channels response
|
|
1967
|
+
*/
|
|
1968
|
+
async queryChannelsRequest(
|
|
1969
|
+
filterConditions: ChannelFilters,
|
|
1970
|
+
sort: ChannelSort = [],
|
|
1971
|
+
options: ChannelOptions = {},
|
|
1972
|
+
) {
|
|
1973
|
+
const data = await this.queryChannelsRequestWithResponse(
|
|
1974
|
+
filterConditions,
|
|
1975
|
+
sort,
|
|
1976
|
+
options,
|
|
1940
1977
|
);
|
|
1941
1978
|
|
|
1942
1979
|
// FIXME: In the next major release, return the full QueryChannelsAPIResponse
|
|
@@ -1955,16 +1992,34 @@ export class StreamChat {
|
|
|
1955
1992
|
* @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
|
|
1956
1993
|
* - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
|
|
1957
1994
|
* - stateOptions.skipHydration - Skips returning the channels as instances of the Channel class and rather returns the raw query response.
|
|
1995
|
+
* - stateOptions.withResponse - Returns the full query response with hydrated channels. This is a compatibility bridge for internal callers that need response-level metadata while the default return value remains `Channel[]`.
|
|
1958
1996
|
*
|
|
1959
1997
|
* @return {Promise<Array<Channel>>} search channels response
|
|
1960
1998
|
*/
|
|
1999
|
+
async queryChannels(
|
|
2000
|
+
filterConditions: ChannelFilters,
|
|
2001
|
+
sort: ChannelSort,
|
|
2002
|
+
options: ChannelOptions,
|
|
2003
|
+
stateOptions: ChannelStateOptions & { withResponse: true },
|
|
2004
|
+
): Promise<QueryChannelsResponseWithChannels>;
|
|
2005
|
+
async queryChannels(
|
|
2006
|
+
filterConditions?: ChannelFilters,
|
|
2007
|
+
sort?: ChannelSort,
|
|
2008
|
+
options?: ChannelOptions,
|
|
2009
|
+
stateOptions?: ChannelStateOptions,
|
|
2010
|
+
): Promise<Channel[]>;
|
|
1961
2011
|
async queryChannels(
|
|
1962
2012
|
filterConditions: ChannelFilters,
|
|
1963
2013
|
sort: ChannelSort = [],
|
|
1964
2014
|
options: ChannelOptions = {},
|
|
1965
2015
|
stateOptions: ChannelStateOptions = {},
|
|
1966
|
-
) {
|
|
1967
|
-
const
|
|
2016
|
+
): Promise<Channel[] | QueryChannelsResponseWithChannels> {
|
|
2017
|
+
const queryChannelsResponse = await this.queryChannelsRequestWithResponse(
|
|
2018
|
+
filterConditions,
|
|
2019
|
+
sort,
|
|
2020
|
+
options,
|
|
2021
|
+
);
|
|
2022
|
+
const channels = queryChannelsResponse.channels;
|
|
1968
2023
|
|
|
1969
2024
|
this.dispatchEvent({
|
|
1970
2025
|
type: 'channels.queried',
|
|
@@ -1980,7 +2035,16 @@ export class StreamChat {
|
|
|
1980
2035
|
});
|
|
1981
2036
|
}
|
|
1982
2037
|
|
|
1983
|
-
|
|
2038
|
+
const hydratedChannels = this.hydrateActiveChannels(channels, stateOptions, options);
|
|
2039
|
+
|
|
2040
|
+
if (stateOptions.withResponse) {
|
|
2041
|
+
return {
|
|
2042
|
+
...queryChannelsResponse,
|
|
2043
|
+
channels: hydratedChannels,
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
return hydratedChannels;
|
|
1984
2048
|
}
|
|
1985
2049
|
|
|
1986
2050
|
/**
|
package/src/types.ts
CHANGED
|
@@ -1111,6 +1111,15 @@ export type ChannelStateOptions = {
|
|
|
1111
1111
|
offlineMode?: boolean;
|
|
1112
1112
|
skipInitialization?: string[];
|
|
1113
1113
|
skipHydration?: boolean;
|
|
1114
|
+
/**
|
|
1115
|
+
* Returns the full query response with hydrated channels from `queryChannels()`.
|
|
1116
|
+
*
|
|
1117
|
+
* This is a compatibility bridge for internal callers that need response level
|
|
1118
|
+
* metadata such as `predefined_filter`. The default `queryChannels()` return value
|
|
1119
|
+
* remains `Channel[]` to avoid a breaking change. This should be folded into a
|
|
1120
|
+
* single full response API in the next major release.
|
|
1121
|
+
*/
|
|
1122
|
+
withResponse?: boolean;
|
|
1114
1123
|
};
|
|
1115
1124
|
|
|
1116
1125
|
export type CreateChannelOptions = {
|