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.
@@ -12457,6 +12457,33 @@ var DEFAULT_CHANNEL_MANAGER_OPTIONS = {
12457
12457
  var DEFAULT_CHANNEL_MANAGER_PAGINATION_OPTIONS = {
12458
12458
  offset: 0
12459
12459
  };
12460
+ var mapPredefinedFilterSortToChannelSort = (sort) => (sort ?? []).map(({ direction = 1, field }) => ({
12461
+ [field]: direction
12462
+ }));
12463
+ var getResponsePaginationParams = ({
12464
+ queryChannelsResponse,
12465
+ sort
12466
+ }) => {
12467
+ const predefinedFilter = queryChannelsResponse?.predefined_filter;
12468
+ if (!predefinedFilter) {
12469
+ return {};
12470
+ }
12471
+ return {
12472
+ responseFilters: predefinedFilter.filter,
12473
+ responseSort: predefinedFilter.sort !== void 0 ? mapPredefinedFilterSortToChannelSort(predefinedFilter.sort) : sort
12474
+ };
12475
+ };
12476
+ var getResponseFiltersAndSort = (pagination) => ({
12477
+ filters: pagination.responseFilters ?? pagination.filters,
12478
+ sort: pagination.responseSort ?? pagination.sort
12479
+ });
12480
+ var omitResponsePaginationParams = (pagination) => {
12481
+ const paginationWithoutResponseParams = { ...pagination };
12482
+ delete paginationWithoutResponseParams.responseFilters;
12483
+ delete paginationWithoutResponseParams.responseSort;
12484
+ return paginationWithoutResponseParams;
12485
+ };
12486
+ var isQueryChannelsResponseWithChannels = (response) => !Array.isArray(response);
12460
12487
  var ChannelManager = class extends WithSubscriptions {
12461
12488
  constructor({
12462
12489
  client,
@@ -12516,22 +12543,34 @@ var ChannelManager = class extends WithSubscriptions {
12516
12543
  ...options
12517
12544
  };
12518
12545
  try {
12519
- const channels = await this.queryChannelsRequest(
12546
+ const queryChannelsResponse = await this.queryChannelsRequest(
12520
12547
  filters,
12521
12548
  sort,
12522
12549
  options,
12523
- stateOptions
12550
+ { ...stateOptions, withResponse: true }
12524
12551
  );
12552
+ const channels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
12525
12553
  const newOffset = offset + (channels?.length ?? 0);
12526
12554
  const newOptions = { ...options, offset: newOffset };
12527
12555
  const { pagination } = this.state.getLatestValue();
12556
+ const responsePaginationParams = getResponsePaginationParams({
12557
+ queryChannelsResponse: isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse : void 0,
12558
+ sort
12559
+ });
12560
+ const paginationWithoutResponseParams = omitResponsePaginationParams(pagination);
12528
12561
  this.state.partialNext({
12529
12562
  channels,
12530
12563
  pagination: {
12531
- ...pagination,
12564
+ // Drop response derived filter/sort from the previous query before applying
12565
+ // the current response. Non predefined queries do not return this metadata,
12566
+ // so keeping the old values would make later WS mutations use stale
12567
+ // predefined filter semantics. Also the predefined_filter might change, producing
12568
+ // a different combination as well so we always need to first clean up.
12569
+ ...paginationWithoutResponseParams,
12532
12570
  hasNext: (channels?.length ?? 0) >= (limit ?? 1),
12533
12571
  isLoading: false,
12534
- options: newOptions
12572
+ options: newOptions,
12573
+ ...responsePaginationParams
12535
12574
  },
12536
12575
  initialized: true,
12537
12576
  error: void 0
@@ -12583,7 +12622,7 @@ var ChannelManager = class extends WithSubscriptions {
12583
12622
  this.state.next((currentState) => ({
12584
12623
  ...currentState,
12585
12624
  pagination: {
12586
- ...currentState.pagination,
12625
+ ...omitResponsePaginationParams(currentState.pagination),
12587
12626
  isLoading: true,
12588
12627
  isLoadingNext: false,
12589
12628
  filters,
@@ -12643,12 +12682,13 @@ var ChannelManager = class extends WithSubscriptions {
12643
12682
  this.state.partialNext({
12644
12683
  pagination: { ...pagination, isLoading: false, isLoadingNext: true }
12645
12684
  });
12646
- const nextChannels = await this.queryChannelsRequest(
12685
+ const queryChannelsResponse = await this.queryChannelsRequest(
12647
12686
  filters,
12648
12687
  sort,
12649
12688
  options,
12650
12689
  this.stateOptions
12651
12690
  );
12691
+ const nextChannels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
12652
12692
  const { channels } = this.state.getLatestValue();
12653
12693
  const newOffset = offset + (nextChannels?.length ?? 0);
12654
12694
  const newOptions = { ...options, offset: newOffset };
@@ -12696,7 +12736,7 @@ var ChannelManager = class extends WithSubscriptions {
12696
12736
  if (!channels) {
12697
12737
  return;
12698
12738
  }
12699
- const { sort } = pagination ?? {};
12739
+ const { sort } = getResponseFiltersAndSort(pagination);
12700
12740
  this.setChannels(
12701
12741
  promoteChannel({
12702
12742
  channels,
@@ -12726,7 +12766,7 @@ var ChannelManager = class extends WithSubscriptions {
12726
12766
  if (!channels) {
12727
12767
  return;
12728
12768
  }
12729
- const { filters, sort } = pagination ?? {};
12769
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12730
12770
  const channelType = event.channel_type;
12731
12771
  const channelId = event.channel_id;
12732
12772
  if (!channelType || !channelId) {
@@ -12769,7 +12809,7 @@ var ChannelManager = class extends WithSubscriptions {
12769
12809
  type
12770
12810
  });
12771
12811
  const { channels, pagination } = this.state.getLatestValue();
12772
- const { filters, sort } = pagination ?? {};
12812
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12773
12813
  const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
12774
12814
  const isTargetChannelArchived = isChannelArchived(channel);
12775
12815
  if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["notification.message_new"]) {
@@ -12794,7 +12834,7 @@ var ChannelManager = class extends WithSubscriptions {
12794
12834
  type: event.channel_type
12795
12835
  });
12796
12836
  const { channels, pagination } = this.state.getLatestValue();
12797
- const { sort, filters } = pagination ?? {};
12837
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12798
12838
  const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
12799
12839
  const isTargetChannelArchived = isChannelArchived(channel);
12800
12840
  if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["channel.visible"]) {
@@ -12811,7 +12851,7 @@ var ChannelManager = class extends WithSubscriptions {
12811
12851
  this.notificationRemovedFromChannelHandler = this.channelDeletedHandler;
12812
12852
  this.memberUpdatedHandler = (event) => {
12813
12853
  const { pagination, channels } = this.state.getLatestValue();
12814
- const { filters, sort } = pagination;
12854
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12815
12855
  if (!event.member?.user || event.member.user.id !== this.client.userID || !event.channel_type || !event.channel_id) {
12816
12856
  return;
12817
12857
  }
@@ -14550,16 +14590,22 @@ var StreamChat = class _StreamChat {
14550
14590
  );
14551
14591
  }
14552
14592
  /**
14553
- * queryChannelsRequest - Queries channels and returns the raw response
14593
+ * queryChannelsRequestWithResponse - Queries channels and returns the full API response
14594
+ * including top-level metadata such as `predefined_filter`.
14595
+ *
14596
+ * This exists as a compatibility bridge, as changing `queryChannelsRequest()` to return
14597
+ * `QueryChannelsAPIResponse` would be a breaking change because it currently returns
14598
+ * only the channel list. In the next major release, the request/response APIs should
14599
+ * be consolidated so callers can access the full response through the primary API.
14554
14600
  *
14555
14601
  * @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
14556
14602
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
14557
14603
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
14558
14604
  * @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
14559
14605
  *
14560
- * @return {Promise<Array<ChannelAPIResponse>>} search channels response
14606
+ * @return {Promise<QueryChannelsAPIResponse>} full search channels response
14561
14607
  */
14562
- async queryChannelsRequest(filterConditions, sort = [], options = {}) {
14608
+ async queryChannelsRequestWithResponse(filterConditions, sort = [], options = {}) {
14563
14609
  const defaultOptions = {
14564
14610
  state: true,
14565
14611
  watch: true,
@@ -14584,27 +14630,38 @@ var StreamChat = class _StreamChat {
14584
14630
  ...defaultOptions,
14585
14631
  ...restOptions
14586
14632
  };
14587
- const data = await this.post(
14588
- this.baseURL + "/channels",
14589
- payload
14590
- );
14591
- return data.channels;
14633
+ return await this.post(this.baseURL + "/channels", payload);
14592
14634
  }
14593
14635
  /**
14594
- * queryChannels - Query channels
14636
+ * queryChannelsRequest - Queries channels and returns the raw channel response list.
14637
+ *
14638
+ * This preserves the historical return shape for backwards compatibility. Use
14639
+ * `queryChannelsRequestWithResponse()` when response level metadata such as
14640
+ * `predefined_filter` is needed. In the next major release these APIs should be
14641
+ * consolidated into a single full-response API.
14595
14642
  *
14596
- * @param {ChannelFilters} filterConditions object MongoDB style filters
14643
+ * @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
14597
14644
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
14598
14645
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
14599
- * @param {ChannelOptions} [options] Options object
14600
- * @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
14601
- * - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
14602
- * - stateOptions.skipHydration - Skips returning the channels as instances of the Channel class and rather returns the raw query response.
14646
+ * @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
14603
14647
  *
14604
- * @return {Promise<Array<Channel>>} search channels response
14648
+ * @return {Promise<Array<ChannelAPIResponse>>} search channels response
14605
14649
  */
14650
+ async queryChannelsRequest(filterConditions, sort = [], options = {}) {
14651
+ const data = await this.queryChannelsRequestWithResponse(
14652
+ filterConditions,
14653
+ sort,
14654
+ options
14655
+ );
14656
+ return data.channels;
14657
+ }
14606
14658
  async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
14607
- const channels = await this.queryChannelsRequest(filterConditions, sort, options);
14659
+ const queryChannelsResponse = await this.queryChannelsRequestWithResponse(
14660
+ filterConditions,
14661
+ sort,
14662
+ options
14663
+ );
14664
+ const channels = queryChannelsResponse.channels;
14608
14665
  this.dispatchEvent({
14609
14666
  type: "channels.queried",
14610
14667
  queriedChannels: {
@@ -14618,7 +14675,14 @@ var StreamChat = class _StreamChat {
14618
14675
  isLatestMessagesSet: true
14619
14676
  });
14620
14677
  }
14621
- return this.hydrateActiveChannels(channels, stateOptions, options);
14678
+ const hydratedChannels = this.hydrateActiveChannels(channels, stateOptions, options);
14679
+ if (stateOptions.withResponse) {
14680
+ return {
14681
+ ...queryChannelsResponse,
14682
+ channels: hydratedChannels
14683
+ };
14684
+ }
14685
+ return hydratedChannels;
14622
14686
  }
14623
14687
  /**
14624
14688
  * queryReactions - Query reactions
@@ -15743,7 +15807,7 @@ var StreamChat = class _StreamChat {
15743
15807
  if (this.userAgent) {
15744
15808
  return this.userAgent;
15745
15809
  }
15746
- const version = "9.44.1";
15810
+ const version = "9.44.2";
15747
15811
  const clientBundle = "node-cjs";
15748
15812
  let userAgentString = "";
15749
15813
  if (this.sdkIdentifier) {