stream-chat 9.44.0 → 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 +97 -30
- package/dist/cjs/index.browser.js.map +2 -2
- package/dist/cjs/index.node.js +97 -30
- package/dist/cjs/index.node.js.map +2 -2
- package/dist/esm/index.mjs +97 -30
- 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/offline-support/types.d.ts +5 -1
- package/dist/types/types.d.ts +9 -0
- package/package.json +1 -1
- package/src/channel_manager.ts +92 -14
- package/src/client.ts +74 -10
- package/src/offline-support/types.ts +5 -0
- 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,
|
|
@@ -12303,12 +12330,13 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12303
12330
|
});
|
|
12304
12331
|
const {
|
|
12305
12332
|
channels,
|
|
12306
|
-
pagination: { filters, sort }
|
|
12333
|
+
pagination: { filters, options, sort }
|
|
12307
12334
|
} = this.state.getLatestValue();
|
|
12308
12335
|
this.client.offlineDb?.executeQuerySafely(
|
|
12309
12336
|
(db) => db.upsertCidsForQuery({
|
|
12310
12337
|
cids: channels.map((channel) => channel.cid),
|
|
12311
12338
|
filters,
|
|
12339
|
+
options,
|
|
12312
12340
|
sort
|
|
12313
12341
|
}),
|
|
12314
12342
|
{ method: "upsertCidsForQuery" }
|
|
@@ -12338,22 +12366,34 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12338
12366
|
...options
|
|
12339
12367
|
};
|
|
12340
12368
|
try {
|
|
12341
|
-
const
|
|
12369
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
12342
12370
|
filters,
|
|
12343
12371
|
sort,
|
|
12344
12372
|
options,
|
|
12345
|
-
stateOptions
|
|
12373
|
+
{ ...stateOptions, withResponse: true }
|
|
12346
12374
|
);
|
|
12375
|
+
const channels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
|
|
12347
12376
|
const newOffset = offset + (channels?.length ?? 0);
|
|
12348
12377
|
const newOptions = { ...options, offset: newOffset };
|
|
12349
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);
|
|
12350
12384
|
this.state.partialNext({
|
|
12351
12385
|
channels,
|
|
12352
12386
|
pagination: {
|
|
12353
|
-
|
|
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,
|
|
12354
12393
|
hasNext: (channels?.length ?? 0) >= (limit ?? 1),
|
|
12355
12394
|
isLoading: false,
|
|
12356
|
-
options: newOptions
|
|
12395
|
+
options: newOptions,
|
|
12396
|
+
...responsePaginationParams
|
|
12357
12397
|
},
|
|
12358
12398
|
initialized: true,
|
|
12359
12399
|
error: void 0
|
|
@@ -12362,6 +12402,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12362
12402
|
(db) => db.upsertCidsForQuery({
|
|
12363
12403
|
cids: channels.map((channel) => channel.cid),
|
|
12364
12404
|
filters: pagination.filters,
|
|
12405
|
+
options,
|
|
12365
12406
|
sort: pagination.sort
|
|
12366
12407
|
}),
|
|
12367
12408
|
{ method: "upsertCidsForQuery" }
|
|
@@ -12404,7 +12445,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12404
12445
|
this.state.next((currentState) => ({
|
|
12405
12446
|
...currentState,
|
|
12406
12447
|
pagination: {
|
|
12407
|
-
...currentState.pagination,
|
|
12448
|
+
...omitResponsePaginationParams(currentState.pagination),
|
|
12408
12449
|
isLoading: true,
|
|
12409
12450
|
isLoadingNext: false,
|
|
12410
12451
|
filters,
|
|
@@ -12418,6 +12459,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12418
12459
|
const channelsFromDB = await this.client.offlineDb.getChannelsForQuery({
|
|
12419
12460
|
userId: this.client.user.id,
|
|
12420
12461
|
filters,
|
|
12462
|
+
options,
|
|
12421
12463
|
sort
|
|
12422
12464
|
});
|
|
12423
12465
|
if (channelsFromDB) {
|
|
@@ -12463,12 +12505,13 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12463
12505
|
this.state.partialNext({
|
|
12464
12506
|
pagination: { ...pagination, isLoading: false, isLoadingNext: true }
|
|
12465
12507
|
});
|
|
12466
|
-
const
|
|
12508
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
12467
12509
|
filters,
|
|
12468
12510
|
sort,
|
|
12469
12511
|
options,
|
|
12470
12512
|
this.stateOptions
|
|
12471
12513
|
);
|
|
12514
|
+
const nextChannels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
|
|
12472
12515
|
const { channels } = this.state.getLatestValue();
|
|
12473
12516
|
const newOffset = offset + (nextChannels?.length ?? 0);
|
|
12474
12517
|
const newOptions = { ...options, offset: newOffset };
|
|
@@ -12516,7 +12559,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12516
12559
|
if (!channels) {
|
|
12517
12560
|
return;
|
|
12518
12561
|
}
|
|
12519
|
-
const { sort } = pagination
|
|
12562
|
+
const { sort } = getResponseFiltersAndSort(pagination);
|
|
12520
12563
|
this.setChannels(
|
|
12521
12564
|
promoteChannel({
|
|
12522
12565
|
channels,
|
|
@@ -12546,7 +12589,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12546
12589
|
if (!channels) {
|
|
12547
12590
|
return;
|
|
12548
12591
|
}
|
|
12549
|
-
const { filters, sort } = pagination
|
|
12592
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12550
12593
|
const channelType = event.channel_type;
|
|
12551
12594
|
const channelId = event.channel_id;
|
|
12552
12595
|
if (!channelType || !channelId) {
|
|
@@ -12589,7 +12632,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12589
12632
|
type
|
|
12590
12633
|
});
|
|
12591
12634
|
const { channels, pagination } = this.state.getLatestValue();
|
|
12592
|
-
const { filters, sort } = pagination
|
|
12635
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12593
12636
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
12594
12637
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
12595
12638
|
if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["notification.message_new"]) {
|
|
@@ -12614,7 +12657,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12614
12657
|
type: event.channel_type
|
|
12615
12658
|
});
|
|
12616
12659
|
const { channels, pagination } = this.state.getLatestValue();
|
|
12617
|
-
const {
|
|
12660
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12618
12661
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
12619
12662
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
12620
12663
|
if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["channel.visible"]) {
|
|
@@ -12631,7 +12674,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12631
12674
|
this.notificationRemovedFromChannelHandler = this.channelDeletedHandler;
|
|
12632
12675
|
this.memberUpdatedHandler = (event) => {
|
|
12633
12676
|
const { pagination, channels } = this.state.getLatestValue();
|
|
12634
|
-
const { filters, sort } = pagination;
|
|
12677
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12635
12678
|
if (!event.member?.user || event.member.user.id !== this.client.userID || !event.channel_type || !event.channel_id) {
|
|
12636
12679
|
return;
|
|
12637
12680
|
}
|
|
@@ -14370,16 +14413,22 @@ var StreamChat = class _StreamChat {
|
|
|
14370
14413
|
);
|
|
14371
14414
|
}
|
|
14372
14415
|
/**
|
|
14373
|
-
*
|
|
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.
|
|
14374
14423
|
*
|
|
14375
14424
|
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
14376
14425
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
14377
14426
|
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
14378
14427
|
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
14379
14428
|
*
|
|
14380
|
-
* @return {Promise<
|
|
14429
|
+
* @return {Promise<QueryChannelsAPIResponse>} full search channels response
|
|
14381
14430
|
*/
|
|
14382
|
-
async
|
|
14431
|
+
async queryChannelsRequestWithResponse(filterConditions, sort = [], options = {}) {
|
|
14383
14432
|
const defaultOptions = {
|
|
14384
14433
|
state: true,
|
|
14385
14434
|
watch: true,
|
|
@@ -14404,27 +14453,38 @@ var StreamChat = class _StreamChat {
|
|
|
14404
14453
|
...defaultOptions,
|
|
14405
14454
|
...restOptions
|
|
14406
14455
|
};
|
|
14407
|
-
|
|
14408
|
-
this.baseURL + "/channels",
|
|
14409
|
-
payload
|
|
14410
|
-
);
|
|
14411
|
-
return data.channels;
|
|
14456
|
+
return await this.post(this.baseURL + "/channels", payload);
|
|
14412
14457
|
}
|
|
14413
14458
|
/**
|
|
14414
|
-
*
|
|
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.
|
|
14415
14465
|
*
|
|
14416
|
-
* @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.
|
|
14417
14467
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
14418
14468
|
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
14419
|
-
* @param {ChannelOptions} [options] Options object
|
|
14420
|
-
* @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
|
|
14421
|
-
* - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
|
|
14422
|
-
* - 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.
|
|
14423
14470
|
*
|
|
14424
|
-
* @return {Promise<Array<
|
|
14471
|
+
* @return {Promise<Array<ChannelAPIResponse>>} search channels response
|
|
14425
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
|
+
}
|
|
14426
14481
|
async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
|
|
14427
|
-
const
|
|
14482
|
+
const queryChannelsResponse = await this.queryChannelsRequestWithResponse(
|
|
14483
|
+
filterConditions,
|
|
14484
|
+
sort,
|
|
14485
|
+
options
|
|
14486
|
+
);
|
|
14487
|
+
const channels = queryChannelsResponse.channels;
|
|
14428
14488
|
this.dispatchEvent({
|
|
14429
14489
|
type: "channels.queried",
|
|
14430
14490
|
queriedChannels: {
|
|
@@ -14438,7 +14498,14 @@ var StreamChat = class _StreamChat {
|
|
|
14438
14498
|
isLatestMessagesSet: true
|
|
14439
14499
|
});
|
|
14440
14500
|
}
|
|
14441
|
-
|
|
14501
|
+
const hydratedChannels = this.hydrateActiveChannels(channels, stateOptions, options);
|
|
14502
|
+
if (stateOptions.withResponse) {
|
|
14503
|
+
return {
|
|
14504
|
+
...queryChannelsResponse,
|
|
14505
|
+
channels: hydratedChannels
|
|
14506
|
+
};
|
|
14507
|
+
}
|
|
14508
|
+
return hydratedChannels;
|
|
14442
14509
|
}
|
|
14443
14510
|
/**
|
|
14444
14511
|
* queryReactions - Query reactions
|
|
@@ -15563,7 +15630,7 @@ var StreamChat = class _StreamChat {
|
|
|
15563
15630
|
if (this.userAgent) {
|
|
15564
15631
|
return this.userAgent;
|
|
15565
15632
|
}
|
|
15566
|
-
const version = "9.44.
|
|
15633
|
+
const version = "9.44.2";
|
|
15567
15634
|
const clientBundle = "browser-esm";
|
|
15568
15635
|
let userAgentString = "";
|
|
15569
15636
|
if (this.sdkIdentifier) {
|