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
package/dist/esm/index.mjs
CHANGED
|
@@ -12280,6 +12280,33 @@ var DEFAULT_CHANNEL_MANAGER_OPTIONS = {
|
|
|
12280
12280
|
var DEFAULT_CHANNEL_MANAGER_PAGINATION_OPTIONS = {
|
|
12281
12281
|
offset: 0
|
|
12282
12282
|
};
|
|
12283
|
+
var mapPredefinedFilterSortToChannelSort = (sort) => (sort ?? []).map(({ direction = 1, field }) => ({
|
|
12284
|
+
[field]: direction
|
|
12285
|
+
}));
|
|
12286
|
+
var getResponsePaginationParams = ({
|
|
12287
|
+
queryChannelsResponse,
|
|
12288
|
+
sort
|
|
12289
|
+
}) => {
|
|
12290
|
+
const predefinedFilter = queryChannelsResponse?.predefined_filter;
|
|
12291
|
+
if (!predefinedFilter) {
|
|
12292
|
+
return {};
|
|
12293
|
+
}
|
|
12294
|
+
return {
|
|
12295
|
+
responseFilters: predefinedFilter.filter,
|
|
12296
|
+
responseSort: predefinedFilter.sort !== void 0 ? mapPredefinedFilterSortToChannelSort(predefinedFilter.sort) : sort
|
|
12297
|
+
};
|
|
12298
|
+
};
|
|
12299
|
+
var getResponseFiltersAndSort = (pagination) => ({
|
|
12300
|
+
filters: pagination.responseFilters ?? pagination.filters,
|
|
12301
|
+
sort: pagination.responseSort ?? pagination.sort
|
|
12302
|
+
});
|
|
12303
|
+
var omitResponsePaginationParams = (pagination) => {
|
|
12304
|
+
const paginationWithoutResponseParams = { ...pagination };
|
|
12305
|
+
delete paginationWithoutResponseParams.responseFilters;
|
|
12306
|
+
delete paginationWithoutResponseParams.responseSort;
|
|
12307
|
+
return paginationWithoutResponseParams;
|
|
12308
|
+
};
|
|
12309
|
+
var isQueryChannelsResponseWithChannels = (response) => !Array.isArray(response);
|
|
12283
12310
|
var ChannelManager = class extends WithSubscriptions {
|
|
12284
12311
|
constructor({
|
|
12285
12312
|
client,
|
|
@@ -12339,22 +12366,34 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12339
12366
|
...options
|
|
12340
12367
|
};
|
|
12341
12368
|
try {
|
|
12342
|
-
const
|
|
12369
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
12343
12370
|
filters,
|
|
12344
12371
|
sort,
|
|
12345
12372
|
options,
|
|
12346
|
-
stateOptions
|
|
12373
|
+
{ ...stateOptions, withResponse: true }
|
|
12347
12374
|
);
|
|
12375
|
+
const channels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
|
|
12348
12376
|
const newOffset = offset + (channels?.length ?? 0);
|
|
12349
12377
|
const newOptions = { ...options, offset: newOffset };
|
|
12350
12378
|
const { pagination } = this.state.getLatestValue();
|
|
12379
|
+
const responsePaginationParams = getResponsePaginationParams({
|
|
12380
|
+
queryChannelsResponse: isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse : void 0,
|
|
12381
|
+
sort
|
|
12382
|
+
});
|
|
12383
|
+
const paginationWithoutResponseParams = omitResponsePaginationParams(pagination);
|
|
12351
12384
|
this.state.partialNext({
|
|
12352
12385
|
channels,
|
|
12353
12386
|
pagination: {
|
|
12354
|
-
|
|
12387
|
+
// Drop response derived filter/sort from the previous query before applying
|
|
12388
|
+
// the current response. Non predefined queries do not return this metadata,
|
|
12389
|
+
// so keeping the old values would make later WS mutations use stale
|
|
12390
|
+
// predefined filter semantics. Also the predefined_filter might change, producing
|
|
12391
|
+
// a different combination as well so we always need to first clean up.
|
|
12392
|
+
...paginationWithoutResponseParams,
|
|
12355
12393
|
hasNext: (channels?.length ?? 0) >= (limit ?? 1),
|
|
12356
12394
|
isLoading: false,
|
|
12357
|
-
options: newOptions
|
|
12395
|
+
options: newOptions,
|
|
12396
|
+
...responsePaginationParams
|
|
12358
12397
|
},
|
|
12359
12398
|
initialized: true,
|
|
12360
12399
|
error: void 0
|
|
@@ -12406,7 +12445,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12406
12445
|
this.state.next((currentState) => ({
|
|
12407
12446
|
...currentState,
|
|
12408
12447
|
pagination: {
|
|
12409
|
-
...currentState.pagination,
|
|
12448
|
+
...omitResponsePaginationParams(currentState.pagination),
|
|
12410
12449
|
isLoading: true,
|
|
12411
12450
|
isLoadingNext: false,
|
|
12412
12451
|
filters,
|
|
@@ -12466,12 +12505,13 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12466
12505
|
this.state.partialNext({
|
|
12467
12506
|
pagination: { ...pagination, isLoading: false, isLoadingNext: true }
|
|
12468
12507
|
});
|
|
12469
|
-
const
|
|
12508
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
12470
12509
|
filters,
|
|
12471
12510
|
sort,
|
|
12472
12511
|
options,
|
|
12473
12512
|
this.stateOptions
|
|
12474
12513
|
);
|
|
12514
|
+
const nextChannels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
|
|
12475
12515
|
const { channels } = this.state.getLatestValue();
|
|
12476
12516
|
const newOffset = offset + (nextChannels?.length ?? 0);
|
|
12477
12517
|
const newOptions = { ...options, offset: newOffset };
|
|
@@ -12519,7 +12559,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12519
12559
|
if (!channels) {
|
|
12520
12560
|
return;
|
|
12521
12561
|
}
|
|
12522
|
-
const { sort } = pagination
|
|
12562
|
+
const { sort } = getResponseFiltersAndSort(pagination);
|
|
12523
12563
|
this.setChannels(
|
|
12524
12564
|
promoteChannel({
|
|
12525
12565
|
channels,
|
|
@@ -12549,7 +12589,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12549
12589
|
if (!channels) {
|
|
12550
12590
|
return;
|
|
12551
12591
|
}
|
|
12552
|
-
const { filters, sort } = pagination
|
|
12592
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12553
12593
|
const channelType = event.channel_type;
|
|
12554
12594
|
const channelId = event.channel_id;
|
|
12555
12595
|
if (!channelType || !channelId) {
|
|
@@ -12592,7 +12632,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12592
12632
|
type
|
|
12593
12633
|
});
|
|
12594
12634
|
const { channels, pagination } = this.state.getLatestValue();
|
|
12595
|
-
const { filters, sort } = pagination
|
|
12635
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12596
12636
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
12597
12637
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
12598
12638
|
if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["notification.message_new"]) {
|
|
@@ -12617,7 +12657,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12617
12657
|
type: event.channel_type
|
|
12618
12658
|
});
|
|
12619
12659
|
const { channels, pagination } = this.state.getLatestValue();
|
|
12620
|
-
const {
|
|
12660
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12621
12661
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
12622
12662
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
12623
12663
|
if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["channel.visible"]) {
|
|
@@ -12634,7 +12674,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12634
12674
|
this.notificationRemovedFromChannelHandler = this.channelDeletedHandler;
|
|
12635
12675
|
this.memberUpdatedHandler = (event) => {
|
|
12636
12676
|
const { pagination, channels } = this.state.getLatestValue();
|
|
12637
|
-
const { filters, sort } = pagination;
|
|
12677
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12638
12678
|
if (!event.member?.user || event.member.user.id !== this.client.userID || !event.channel_type || !event.channel_id) {
|
|
12639
12679
|
return;
|
|
12640
12680
|
}
|
|
@@ -14373,16 +14413,22 @@ var StreamChat = class _StreamChat {
|
|
|
14373
14413
|
);
|
|
14374
14414
|
}
|
|
14375
14415
|
/**
|
|
14376
|
-
*
|
|
14416
|
+
* queryChannelsRequestWithResponse - Queries channels and returns the full API response
|
|
14417
|
+
* including top-level metadata such as `predefined_filter`.
|
|
14418
|
+
*
|
|
14419
|
+
* This exists as a compatibility bridge, as changing `queryChannelsRequest()` to return
|
|
14420
|
+
* `QueryChannelsAPIResponse` would be a breaking change because it currently returns
|
|
14421
|
+
* only the channel list. In the next major release, the request/response APIs should
|
|
14422
|
+
* be consolidated so callers can access the full response through the primary API.
|
|
14377
14423
|
*
|
|
14378
14424
|
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
14379
14425
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
14380
14426
|
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
14381
14427
|
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
14382
14428
|
*
|
|
14383
|
-
* @return {Promise<
|
|
14429
|
+
* @return {Promise<QueryChannelsAPIResponse>} full search channels response
|
|
14384
14430
|
*/
|
|
14385
|
-
async
|
|
14431
|
+
async queryChannelsRequestWithResponse(filterConditions, sort = [], options = {}) {
|
|
14386
14432
|
const defaultOptions = {
|
|
14387
14433
|
state: true,
|
|
14388
14434
|
watch: true,
|
|
@@ -14407,27 +14453,38 @@ var StreamChat = class _StreamChat {
|
|
|
14407
14453
|
...defaultOptions,
|
|
14408
14454
|
...restOptions
|
|
14409
14455
|
};
|
|
14410
|
-
|
|
14411
|
-
this.baseURL + "/channels",
|
|
14412
|
-
payload
|
|
14413
|
-
);
|
|
14414
|
-
return data.channels;
|
|
14456
|
+
return await this.post(this.baseURL + "/channels", payload);
|
|
14415
14457
|
}
|
|
14416
14458
|
/**
|
|
14417
|
-
*
|
|
14459
|
+
* queryChannelsRequest - Queries channels and returns the raw channel response list.
|
|
14460
|
+
*
|
|
14461
|
+
* This preserves the historical return shape for backwards compatibility. Use
|
|
14462
|
+
* `queryChannelsRequestWithResponse()` when response level metadata such as
|
|
14463
|
+
* `predefined_filter` is needed. In the next major release these APIs should be
|
|
14464
|
+
* consolidated into a single full-response API.
|
|
14418
14465
|
*
|
|
14419
|
-
* @param {ChannelFilters} filterConditions object MongoDB style filters
|
|
14466
|
+
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
14420
14467
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
14421
14468
|
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
14422
|
-
* @param {ChannelOptions} [options] Options object
|
|
14423
|
-
* @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
|
|
14424
|
-
* - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
|
|
14425
|
-
* - stateOptions.skipHydration - Skips returning the channels as instances of the Channel class and rather returns the raw query response.
|
|
14469
|
+
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
14426
14470
|
*
|
|
14427
|
-
* @return {Promise<Array<
|
|
14471
|
+
* @return {Promise<Array<ChannelAPIResponse>>} search channels response
|
|
14428
14472
|
*/
|
|
14473
|
+
async queryChannelsRequest(filterConditions, sort = [], options = {}) {
|
|
14474
|
+
const data = await this.queryChannelsRequestWithResponse(
|
|
14475
|
+
filterConditions,
|
|
14476
|
+
sort,
|
|
14477
|
+
options
|
|
14478
|
+
);
|
|
14479
|
+
return data.channels;
|
|
14480
|
+
}
|
|
14429
14481
|
async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
|
|
14430
|
-
const
|
|
14482
|
+
const queryChannelsResponse = await this.queryChannelsRequestWithResponse(
|
|
14483
|
+
filterConditions,
|
|
14484
|
+
sort,
|
|
14485
|
+
options
|
|
14486
|
+
);
|
|
14487
|
+
const channels = queryChannelsResponse.channels;
|
|
14431
14488
|
this.dispatchEvent({
|
|
14432
14489
|
type: "channels.queried",
|
|
14433
14490
|
queriedChannels: {
|
|
@@ -14441,7 +14498,14 @@ var StreamChat = class _StreamChat {
|
|
|
14441
14498
|
isLatestMessagesSet: true
|
|
14442
14499
|
});
|
|
14443
14500
|
}
|
|
14444
|
-
|
|
14501
|
+
const hydratedChannels = this.hydrateActiveChannels(channels, stateOptions, options);
|
|
14502
|
+
if (stateOptions.withResponse) {
|
|
14503
|
+
return {
|
|
14504
|
+
...queryChannelsResponse,
|
|
14505
|
+
channels: hydratedChannels
|
|
14506
|
+
};
|
|
14507
|
+
}
|
|
14508
|
+
return hydratedChannels;
|
|
14445
14509
|
}
|
|
14446
14510
|
/**
|
|
14447
14511
|
* queryReactions - Query reactions
|
|
@@ -15566,7 +15630,7 @@ var StreamChat = class _StreamChat {
|
|
|
15566
15630
|
if (this.userAgent) {
|
|
15567
15631
|
return this.userAgent;
|
|
15568
15632
|
}
|
|
15569
|
-
const version = "9.44.
|
|
15633
|
+
const version = "9.44.2";
|
|
15570
15634
|
const clientBundle = "browser-esm";
|
|
15571
15635
|
let userAgentString = "";
|
|
15572
15636
|
if (this.sdkIdentifier) {
|