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.
@@ -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,
@@ -12543,22 +12570,34 @@ var ChannelManager = class extends WithSubscriptions {
12543
12570
  ...options
12544
12571
  };
12545
12572
  try {
12546
- const channels = await this.queryChannelsRequest(
12573
+ const queryChannelsResponse = await this.queryChannelsRequest(
12547
12574
  filters,
12548
12575
  sort,
12549
12576
  options,
12550
- stateOptions
12577
+ { ...stateOptions, withResponse: true }
12551
12578
  );
12579
+ const channels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
12552
12580
  const newOffset = offset + (channels?.length ?? 0);
12553
12581
  const newOptions = { ...options, offset: newOffset };
12554
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);
12555
12588
  this.state.partialNext({
12556
12589
  channels,
12557
12590
  pagination: {
12558
- ...pagination,
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,
12559
12597
  hasNext: (channels?.length ?? 0) >= (limit ?? 1),
12560
12598
  isLoading: false,
12561
- options: newOptions
12599
+ options: newOptions,
12600
+ ...responsePaginationParams
12562
12601
  },
12563
12602
  initialized: true,
12564
12603
  error: void 0
@@ -12610,7 +12649,7 @@ var ChannelManager = class extends WithSubscriptions {
12610
12649
  this.state.next((currentState) => ({
12611
12650
  ...currentState,
12612
12651
  pagination: {
12613
- ...currentState.pagination,
12652
+ ...omitResponsePaginationParams(currentState.pagination),
12614
12653
  isLoading: true,
12615
12654
  isLoadingNext: false,
12616
12655
  filters,
@@ -12670,12 +12709,13 @@ var ChannelManager = class extends WithSubscriptions {
12670
12709
  this.state.partialNext({
12671
12710
  pagination: { ...pagination, isLoading: false, isLoadingNext: true }
12672
12711
  });
12673
- const nextChannels = await this.queryChannelsRequest(
12712
+ const queryChannelsResponse = await this.queryChannelsRequest(
12674
12713
  filters,
12675
12714
  sort,
12676
12715
  options,
12677
12716
  this.stateOptions
12678
12717
  );
12718
+ const nextChannels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
12679
12719
  const { channels } = this.state.getLatestValue();
12680
12720
  const newOffset = offset + (nextChannels?.length ?? 0);
12681
12721
  const newOptions = { ...options, offset: newOffset };
@@ -12723,7 +12763,7 @@ var ChannelManager = class extends WithSubscriptions {
12723
12763
  if (!channels) {
12724
12764
  return;
12725
12765
  }
12726
- const { sort } = pagination ?? {};
12766
+ const { sort } = getResponseFiltersAndSort(pagination);
12727
12767
  this.setChannels(
12728
12768
  promoteChannel({
12729
12769
  channels,
@@ -12753,7 +12793,7 @@ var ChannelManager = class extends WithSubscriptions {
12753
12793
  if (!channels) {
12754
12794
  return;
12755
12795
  }
12756
- const { filters, sort } = pagination ?? {};
12796
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12757
12797
  const channelType = event.channel_type;
12758
12798
  const channelId = event.channel_id;
12759
12799
  if (!channelType || !channelId) {
@@ -12796,7 +12836,7 @@ var ChannelManager = class extends WithSubscriptions {
12796
12836
  type
12797
12837
  });
12798
12838
  const { channels, pagination } = this.state.getLatestValue();
12799
- const { filters, sort } = pagination ?? {};
12839
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12800
12840
  const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
12801
12841
  const isTargetChannelArchived = isChannelArchived(channel);
12802
12842
  if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["notification.message_new"]) {
@@ -12821,7 +12861,7 @@ var ChannelManager = class extends WithSubscriptions {
12821
12861
  type: event.channel_type
12822
12862
  });
12823
12863
  const { channels, pagination } = this.state.getLatestValue();
12824
- const { sort, filters } = pagination ?? {};
12864
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12825
12865
  const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
12826
12866
  const isTargetChannelArchived = isChannelArchived(channel);
12827
12867
  if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["channel.visible"]) {
@@ -12838,7 +12878,7 @@ var ChannelManager = class extends WithSubscriptions {
12838
12878
  this.notificationRemovedFromChannelHandler = this.channelDeletedHandler;
12839
12879
  this.memberUpdatedHandler = (event) => {
12840
12880
  const { pagination, channels } = this.state.getLatestValue();
12841
- const { filters, sort } = pagination;
12881
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12842
12882
  if (!event.member?.user || event.member.user.id !== this.client.userID || !event.channel_type || !event.channel_id) {
12843
12883
  return;
12844
12884
  }
@@ -14577,16 +14617,22 @@ var StreamChat = class _StreamChat {
14577
14617
  );
14578
14618
  }
14579
14619
  /**
14580
- * queryChannelsRequest - Queries channels and returns the raw response
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.
14581
14627
  *
14582
14628
  * @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
14583
14629
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
14584
14630
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
14585
14631
  * @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
14586
14632
  *
14587
- * @return {Promise<Array<ChannelAPIResponse>>} search channels response
14633
+ * @return {Promise<QueryChannelsAPIResponse>} full search channels response
14588
14634
  */
14589
- async queryChannelsRequest(filterConditions, sort = [], options = {}) {
14635
+ async queryChannelsRequestWithResponse(filterConditions, sort = [], options = {}) {
14590
14636
  const defaultOptions = {
14591
14637
  state: true,
14592
14638
  watch: true,
@@ -14611,27 +14657,38 @@ var StreamChat = class _StreamChat {
14611
14657
  ...defaultOptions,
14612
14658
  ...restOptions
14613
14659
  };
14614
- const data = await this.post(
14615
- this.baseURL + "/channels",
14616
- payload
14617
- );
14618
- return data.channels;
14660
+ return await this.post(this.baseURL + "/channels", payload);
14619
14661
  }
14620
14662
  /**
14621
- * queryChannels - Query channels
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.
14622
14669
  *
14623
- * @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.
14624
14671
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
14625
14672
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
14626
- * @param {ChannelOptions} [options] Options object
14627
- * @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
14628
- * - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
14629
- * - 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.
14630
14674
  *
14631
- * @return {Promise<Array<Channel>>} search channels response
14675
+ * @return {Promise<Array<ChannelAPIResponse>>} search channels response
14632
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
+ }
14633
14685
  async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
14634
- const channels = await this.queryChannelsRequest(filterConditions, sort, options);
14686
+ const queryChannelsResponse = await this.queryChannelsRequestWithResponse(
14687
+ filterConditions,
14688
+ sort,
14689
+ options
14690
+ );
14691
+ const channels = queryChannelsResponse.channels;
14635
14692
  this.dispatchEvent({
14636
14693
  type: "channels.queried",
14637
14694
  queriedChannels: {
@@ -14645,7 +14702,14 @@ var StreamChat = class _StreamChat {
14645
14702
  isLatestMessagesSet: true
14646
14703
  });
14647
14704
  }
14648
- return this.hydrateActiveChannels(channels, stateOptions, options);
14705
+ const hydratedChannels = this.hydrateActiveChannels(channels, stateOptions, options);
14706
+ if (stateOptions.withResponse) {
14707
+ return {
14708
+ ...queryChannelsResponse,
14709
+ channels: hydratedChannels
14710
+ };
14711
+ }
14712
+ return hydratedChannels;
14649
14713
  }
14650
14714
  /**
14651
14715
  * queryReactions - Query reactions
@@ -15770,7 +15834,7 @@ var StreamChat = class _StreamChat {
15770
15834
  if (this.userAgent) {
15771
15835
  return this.userAgent;
15772
15836
  }
15773
- const version = "9.44.1";
15837
+ const version = "9.44.2";
15774
15838
  const clientBundle = "browser-cjs";
15775
15839
  let userAgentString = "";
15776
15840
  if (this.sdkIdentifier) {