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
|
@@ -12484,6 +12484,33 @@ var DEFAULT_CHANNEL_MANAGER_OPTIONS = {
|
|
|
12484
12484
|
var DEFAULT_CHANNEL_MANAGER_PAGINATION_OPTIONS = {
|
|
12485
12485
|
offset: 0
|
|
12486
12486
|
};
|
|
12487
|
+
var mapPredefinedFilterSortToChannelSort = (sort) => (sort ?? []).map(({ direction = 1, field }) => ({
|
|
12488
|
+
[field]: direction
|
|
12489
|
+
}));
|
|
12490
|
+
var getResponsePaginationParams = ({
|
|
12491
|
+
queryChannelsResponse,
|
|
12492
|
+
sort
|
|
12493
|
+
}) => {
|
|
12494
|
+
const predefinedFilter = queryChannelsResponse?.predefined_filter;
|
|
12495
|
+
if (!predefinedFilter) {
|
|
12496
|
+
return {};
|
|
12497
|
+
}
|
|
12498
|
+
return {
|
|
12499
|
+
responseFilters: predefinedFilter.filter,
|
|
12500
|
+
responseSort: predefinedFilter.sort !== void 0 ? mapPredefinedFilterSortToChannelSort(predefinedFilter.sort) : sort
|
|
12501
|
+
};
|
|
12502
|
+
};
|
|
12503
|
+
var getResponseFiltersAndSort = (pagination) => ({
|
|
12504
|
+
filters: pagination.responseFilters ?? pagination.filters,
|
|
12505
|
+
sort: pagination.responseSort ?? pagination.sort
|
|
12506
|
+
});
|
|
12507
|
+
var omitResponsePaginationParams = (pagination) => {
|
|
12508
|
+
const paginationWithoutResponseParams = { ...pagination };
|
|
12509
|
+
delete paginationWithoutResponseParams.responseFilters;
|
|
12510
|
+
delete paginationWithoutResponseParams.responseSort;
|
|
12511
|
+
return paginationWithoutResponseParams;
|
|
12512
|
+
};
|
|
12513
|
+
var isQueryChannelsResponseWithChannels = (response) => !Array.isArray(response);
|
|
12487
12514
|
var ChannelManager = class extends WithSubscriptions {
|
|
12488
12515
|
constructor({
|
|
12489
12516
|
client,
|
|
@@ -12507,12 +12534,13 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12507
12534
|
});
|
|
12508
12535
|
const {
|
|
12509
12536
|
channels,
|
|
12510
|
-
pagination: { filters, sort }
|
|
12537
|
+
pagination: { filters, options, sort }
|
|
12511
12538
|
} = this.state.getLatestValue();
|
|
12512
12539
|
this.client.offlineDb?.executeQuerySafely(
|
|
12513
12540
|
(db) => db.upsertCidsForQuery({
|
|
12514
12541
|
cids: channels.map((channel) => channel.cid),
|
|
12515
12542
|
filters,
|
|
12543
|
+
options,
|
|
12516
12544
|
sort
|
|
12517
12545
|
}),
|
|
12518
12546
|
{ method: "upsertCidsForQuery" }
|
|
@@ -12542,22 +12570,34 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12542
12570
|
...options
|
|
12543
12571
|
};
|
|
12544
12572
|
try {
|
|
12545
|
-
const
|
|
12573
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
12546
12574
|
filters,
|
|
12547
12575
|
sort,
|
|
12548
12576
|
options,
|
|
12549
|
-
stateOptions
|
|
12577
|
+
{ ...stateOptions, withResponse: true }
|
|
12550
12578
|
);
|
|
12579
|
+
const channels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
|
|
12551
12580
|
const newOffset = offset + (channels?.length ?? 0);
|
|
12552
12581
|
const newOptions = { ...options, offset: newOffset };
|
|
12553
12582
|
const { pagination } = this.state.getLatestValue();
|
|
12583
|
+
const responsePaginationParams = getResponsePaginationParams({
|
|
12584
|
+
queryChannelsResponse: isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse : void 0,
|
|
12585
|
+
sort
|
|
12586
|
+
});
|
|
12587
|
+
const paginationWithoutResponseParams = omitResponsePaginationParams(pagination);
|
|
12554
12588
|
this.state.partialNext({
|
|
12555
12589
|
channels,
|
|
12556
12590
|
pagination: {
|
|
12557
|
-
|
|
12591
|
+
// Drop response derived filter/sort from the previous query before applying
|
|
12592
|
+
// the current response. Non predefined queries do not return this metadata,
|
|
12593
|
+
// so keeping the old values would make later WS mutations use stale
|
|
12594
|
+
// predefined filter semantics. Also the predefined_filter might change, producing
|
|
12595
|
+
// a different combination as well so we always need to first clean up.
|
|
12596
|
+
...paginationWithoutResponseParams,
|
|
12558
12597
|
hasNext: (channels?.length ?? 0) >= (limit ?? 1),
|
|
12559
12598
|
isLoading: false,
|
|
12560
|
-
options: newOptions
|
|
12599
|
+
options: newOptions,
|
|
12600
|
+
...responsePaginationParams
|
|
12561
12601
|
},
|
|
12562
12602
|
initialized: true,
|
|
12563
12603
|
error: void 0
|
|
@@ -12566,6 +12606,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12566
12606
|
(db) => db.upsertCidsForQuery({
|
|
12567
12607
|
cids: channels.map((channel) => channel.cid),
|
|
12568
12608
|
filters: pagination.filters,
|
|
12609
|
+
options,
|
|
12569
12610
|
sort: pagination.sort
|
|
12570
12611
|
}),
|
|
12571
12612
|
{ method: "upsertCidsForQuery" }
|
|
@@ -12608,7 +12649,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12608
12649
|
this.state.next((currentState) => ({
|
|
12609
12650
|
...currentState,
|
|
12610
12651
|
pagination: {
|
|
12611
|
-
...currentState.pagination,
|
|
12652
|
+
...omitResponsePaginationParams(currentState.pagination),
|
|
12612
12653
|
isLoading: true,
|
|
12613
12654
|
isLoadingNext: false,
|
|
12614
12655
|
filters,
|
|
@@ -12622,6 +12663,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12622
12663
|
const channelsFromDB = await this.client.offlineDb.getChannelsForQuery({
|
|
12623
12664
|
userId: this.client.user.id,
|
|
12624
12665
|
filters,
|
|
12666
|
+
options,
|
|
12625
12667
|
sort
|
|
12626
12668
|
});
|
|
12627
12669
|
if (channelsFromDB) {
|
|
@@ -12667,12 +12709,13 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12667
12709
|
this.state.partialNext({
|
|
12668
12710
|
pagination: { ...pagination, isLoading: false, isLoadingNext: true }
|
|
12669
12711
|
});
|
|
12670
|
-
const
|
|
12712
|
+
const queryChannelsResponse = await this.queryChannelsRequest(
|
|
12671
12713
|
filters,
|
|
12672
12714
|
sort,
|
|
12673
12715
|
options,
|
|
12674
12716
|
this.stateOptions
|
|
12675
12717
|
);
|
|
12718
|
+
const nextChannels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
|
|
12676
12719
|
const { channels } = this.state.getLatestValue();
|
|
12677
12720
|
const newOffset = offset + (nextChannels?.length ?? 0);
|
|
12678
12721
|
const newOptions = { ...options, offset: newOffset };
|
|
@@ -12720,7 +12763,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12720
12763
|
if (!channels) {
|
|
12721
12764
|
return;
|
|
12722
12765
|
}
|
|
12723
|
-
const { sort } = pagination
|
|
12766
|
+
const { sort } = getResponseFiltersAndSort(pagination);
|
|
12724
12767
|
this.setChannels(
|
|
12725
12768
|
promoteChannel({
|
|
12726
12769
|
channels,
|
|
@@ -12750,7 +12793,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12750
12793
|
if (!channels) {
|
|
12751
12794
|
return;
|
|
12752
12795
|
}
|
|
12753
|
-
const { filters, sort } = pagination
|
|
12796
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12754
12797
|
const channelType = event.channel_type;
|
|
12755
12798
|
const channelId = event.channel_id;
|
|
12756
12799
|
if (!channelType || !channelId) {
|
|
@@ -12793,7 +12836,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12793
12836
|
type
|
|
12794
12837
|
});
|
|
12795
12838
|
const { channels, pagination } = this.state.getLatestValue();
|
|
12796
|
-
const { filters, sort } = pagination
|
|
12839
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12797
12840
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
12798
12841
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
12799
12842
|
if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["notification.message_new"]) {
|
|
@@ -12818,7 +12861,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12818
12861
|
type: event.channel_type
|
|
12819
12862
|
});
|
|
12820
12863
|
const { channels, pagination } = this.state.getLatestValue();
|
|
12821
|
-
const {
|
|
12864
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12822
12865
|
const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
|
|
12823
12866
|
const isTargetChannelArchived = isChannelArchived(channel);
|
|
12824
12867
|
if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["channel.visible"]) {
|
|
@@ -12835,7 +12878,7 @@ var ChannelManager = class extends WithSubscriptions {
|
|
|
12835
12878
|
this.notificationRemovedFromChannelHandler = this.channelDeletedHandler;
|
|
12836
12879
|
this.memberUpdatedHandler = (event) => {
|
|
12837
12880
|
const { pagination, channels } = this.state.getLatestValue();
|
|
12838
|
-
const { filters, sort } = pagination;
|
|
12881
|
+
const { filters, sort } = getResponseFiltersAndSort(pagination);
|
|
12839
12882
|
if (!event.member?.user || event.member.user.id !== this.client.userID || !event.channel_type || !event.channel_id) {
|
|
12840
12883
|
return;
|
|
12841
12884
|
}
|
|
@@ -14574,16 +14617,22 @@ var StreamChat = class _StreamChat {
|
|
|
14574
14617
|
);
|
|
14575
14618
|
}
|
|
14576
14619
|
/**
|
|
14577
|
-
*
|
|
14620
|
+
* queryChannelsRequestWithResponse - Queries channels and returns the full API response
|
|
14621
|
+
* including top-level metadata such as `predefined_filter`.
|
|
14622
|
+
*
|
|
14623
|
+
* This exists as a compatibility bridge, as changing `queryChannelsRequest()` to return
|
|
14624
|
+
* `QueryChannelsAPIResponse` would be a breaking change because it currently returns
|
|
14625
|
+
* only the channel list. In the next major release, the request/response APIs should
|
|
14626
|
+
* be consolidated so callers can access the full response through the primary API.
|
|
14578
14627
|
*
|
|
14579
14628
|
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
14580
14629
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
14581
14630
|
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
14582
14631
|
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
14583
14632
|
*
|
|
14584
|
-
* @return {Promise<
|
|
14633
|
+
* @return {Promise<QueryChannelsAPIResponse>} full search channels response
|
|
14585
14634
|
*/
|
|
14586
|
-
async
|
|
14635
|
+
async queryChannelsRequestWithResponse(filterConditions, sort = [], options = {}) {
|
|
14587
14636
|
const defaultOptions = {
|
|
14588
14637
|
state: true,
|
|
14589
14638
|
watch: true,
|
|
@@ -14608,27 +14657,38 @@ var StreamChat = class _StreamChat {
|
|
|
14608
14657
|
...defaultOptions,
|
|
14609
14658
|
...restOptions
|
|
14610
14659
|
};
|
|
14611
|
-
|
|
14612
|
-
this.baseURL + "/channels",
|
|
14613
|
-
payload
|
|
14614
|
-
);
|
|
14615
|
-
return data.channels;
|
|
14660
|
+
return await this.post(this.baseURL + "/channels", payload);
|
|
14616
14661
|
}
|
|
14617
14662
|
/**
|
|
14618
|
-
*
|
|
14663
|
+
* queryChannelsRequest - Queries channels and returns the raw channel response list.
|
|
14664
|
+
*
|
|
14665
|
+
* This preserves the historical return shape for backwards compatibility. Use
|
|
14666
|
+
* `queryChannelsRequestWithResponse()` when response level metadata such as
|
|
14667
|
+
* `predefined_filter` is needed. In the next major release these APIs should be
|
|
14668
|
+
* consolidated into a single full-response API.
|
|
14619
14669
|
*
|
|
14620
|
-
* @param {ChannelFilters} filterConditions object MongoDB style filters
|
|
14670
|
+
* @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
|
|
14621
14671
|
* @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
|
|
14622
14672
|
* When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
|
|
14623
|
-
* @param {ChannelOptions} [options] Options object
|
|
14624
|
-
* @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
|
|
14625
|
-
* - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
|
|
14626
|
-
* - stateOptions.skipHydration - Skips returning the channels as instances of the Channel class and rather returns the raw query response.
|
|
14673
|
+
* @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
|
|
14627
14674
|
*
|
|
14628
|
-
* @return {Promise<Array<
|
|
14675
|
+
* @return {Promise<Array<ChannelAPIResponse>>} search channels response
|
|
14629
14676
|
*/
|
|
14677
|
+
async queryChannelsRequest(filterConditions, sort = [], options = {}) {
|
|
14678
|
+
const data = await this.queryChannelsRequestWithResponse(
|
|
14679
|
+
filterConditions,
|
|
14680
|
+
sort,
|
|
14681
|
+
options
|
|
14682
|
+
);
|
|
14683
|
+
return data.channels;
|
|
14684
|
+
}
|
|
14630
14685
|
async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
|
|
14631
|
-
const
|
|
14686
|
+
const queryChannelsResponse = await this.queryChannelsRequestWithResponse(
|
|
14687
|
+
filterConditions,
|
|
14688
|
+
sort,
|
|
14689
|
+
options
|
|
14690
|
+
);
|
|
14691
|
+
const channels = queryChannelsResponse.channels;
|
|
14632
14692
|
this.dispatchEvent({
|
|
14633
14693
|
type: "channels.queried",
|
|
14634
14694
|
queriedChannels: {
|
|
@@ -14642,7 +14702,14 @@ var StreamChat = class _StreamChat {
|
|
|
14642
14702
|
isLatestMessagesSet: true
|
|
14643
14703
|
});
|
|
14644
14704
|
}
|
|
14645
|
-
|
|
14705
|
+
const hydratedChannels = this.hydrateActiveChannels(channels, stateOptions, options);
|
|
14706
|
+
if (stateOptions.withResponse) {
|
|
14707
|
+
return {
|
|
14708
|
+
...queryChannelsResponse,
|
|
14709
|
+
channels: hydratedChannels
|
|
14710
|
+
};
|
|
14711
|
+
}
|
|
14712
|
+
return hydratedChannels;
|
|
14646
14713
|
}
|
|
14647
14714
|
/**
|
|
14648
14715
|
* queryReactions - Query reactions
|
|
@@ -15767,7 +15834,7 @@ var StreamChat = class _StreamChat {
|
|
|
15767
15834
|
if (this.userAgent) {
|
|
15768
15835
|
return this.userAgent;
|
|
15769
15836
|
}
|
|
15770
|
-
const version = "9.44.
|
|
15837
|
+
const version = "9.44.2";
|
|
15771
15838
|
const clientBundle = "browser-cjs";
|
|
15772
15839
|
let userAgentString = "";
|
|
15773
15840
|
if (this.sdkIdentifier) {
|