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.
@@ -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,
@@ -12480,12 +12507,13 @@ var ChannelManager = class extends WithSubscriptions {
12480
12507
  });
12481
12508
  const {
12482
12509
  channels,
12483
- pagination: { filters, sort }
12510
+ pagination: { filters, options, sort }
12484
12511
  } = this.state.getLatestValue();
12485
12512
  this.client.offlineDb?.executeQuerySafely(
12486
12513
  (db) => db.upsertCidsForQuery({
12487
12514
  cids: channels.map((channel) => channel.cid),
12488
12515
  filters,
12516
+ options,
12489
12517
  sort
12490
12518
  }),
12491
12519
  { method: "upsertCidsForQuery" }
@@ -12515,22 +12543,34 @@ var ChannelManager = class extends WithSubscriptions {
12515
12543
  ...options
12516
12544
  };
12517
12545
  try {
12518
- const channels = await this.queryChannelsRequest(
12546
+ const queryChannelsResponse = await this.queryChannelsRequest(
12519
12547
  filters,
12520
12548
  sort,
12521
12549
  options,
12522
- stateOptions
12550
+ { ...stateOptions, withResponse: true }
12523
12551
  );
12552
+ const channels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
12524
12553
  const newOffset = offset + (channels?.length ?? 0);
12525
12554
  const newOptions = { ...options, offset: newOffset };
12526
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);
12527
12561
  this.state.partialNext({
12528
12562
  channels,
12529
12563
  pagination: {
12530
- ...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,
12531
12570
  hasNext: (channels?.length ?? 0) >= (limit ?? 1),
12532
12571
  isLoading: false,
12533
- options: newOptions
12572
+ options: newOptions,
12573
+ ...responsePaginationParams
12534
12574
  },
12535
12575
  initialized: true,
12536
12576
  error: void 0
@@ -12539,6 +12579,7 @@ var ChannelManager = class extends WithSubscriptions {
12539
12579
  (db) => db.upsertCidsForQuery({
12540
12580
  cids: channels.map((channel) => channel.cid),
12541
12581
  filters: pagination.filters,
12582
+ options,
12542
12583
  sort: pagination.sort
12543
12584
  }),
12544
12585
  { method: "upsertCidsForQuery" }
@@ -12581,7 +12622,7 @@ var ChannelManager = class extends WithSubscriptions {
12581
12622
  this.state.next((currentState) => ({
12582
12623
  ...currentState,
12583
12624
  pagination: {
12584
- ...currentState.pagination,
12625
+ ...omitResponsePaginationParams(currentState.pagination),
12585
12626
  isLoading: true,
12586
12627
  isLoadingNext: false,
12587
12628
  filters,
@@ -12595,6 +12636,7 @@ var ChannelManager = class extends WithSubscriptions {
12595
12636
  const channelsFromDB = await this.client.offlineDb.getChannelsForQuery({
12596
12637
  userId: this.client.user.id,
12597
12638
  filters,
12639
+ options,
12598
12640
  sort
12599
12641
  });
12600
12642
  if (channelsFromDB) {
@@ -12640,12 +12682,13 @@ var ChannelManager = class extends WithSubscriptions {
12640
12682
  this.state.partialNext({
12641
12683
  pagination: { ...pagination, isLoading: false, isLoadingNext: true }
12642
12684
  });
12643
- const nextChannels = await this.queryChannelsRequest(
12685
+ const queryChannelsResponse = await this.queryChannelsRequest(
12644
12686
  filters,
12645
12687
  sort,
12646
12688
  options,
12647
12689
  this.stateOptions
12648
12690
  );
12691
+ const nextChannels = isQueryChannelsResponseWithChannels(queryChannelsResponse) ? queryChannelsResponse.channels : queryChannelsResponse;
12649
12692
  const { channels } = this.state.getLatestValue();
12650
12693
  const newOffset = offset + (nextChannels?.length ?? 0);
12651
12694
  const newOptions = { ...options, offset: newOffset };
@@ -12693,7 +12736,7 @@ var ChannelManager = class extends WithSubscriptions {
12693
12736
  if (!channels) {
12694
12737
  return;
12695
12738
  }
12696
- const { sort } = pagination ?? {};
12739
+ const { sort } = getResponseFiltersAndSort(pagination);
12697
12740
  this.setChannels(
12698
12741
  promoteChannel({
12699
12742
  channels,
@@ -12723,7 +12766,7 @@ var ChannelManager = class extends WithSubscriptions {
12723
12766
  if (!channels) {
12724
12767
  return;
12725
12768
  }
12726
- const { filters, sort } = pagination ?? {};
12769
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12727
12770
  const channelType = event.channel_type;
12728
12771
  const channelId = event.channel_id;
12729
12772
  if (!channelType || !channelId) {
@@ -12766,7 +12809,7 @@ var ChannelManager = class extends WithSubscriptions {
12766
12809
  type
12767
12810
  });
12768
12811
  const { channels, pagination } = this.state.getLatestValue();
12769
- const { filters, sort } = pagination ?? {};
12812
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12770
12813
  const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
12771
12814
  const isTargetChannelArchived = isChannelArchived(channel);
12772
12815
  if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["notification.message_new"]) {
@@ -12791,7 +12834,7 @@ var ChannelManager = class extends WithSubscriptions {
12791
12834
  type: event.channel_type
12792
12835
  });
12793
12836
  const { channels, pagination } = this.state.getLatestValue();
12794
- const { sort, filters } = pagination ?? {};
12837
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12795
12838
  const considerArchivedChannels = shouldConsiderArchivedChannels(filters);
12796
12839
  const isTargetChannelArchived = isChannelArchived(channel);
12797
12840
  if (!channels || considerArchivedChannels && isTargetChannelArchived && !filters.archived || considerArchivedChannels && !isTargetChannelArchived && filters.archived || !this.options.allowNotLoadedChannelPromotionForEvent?.["channel.visible"]) {
@@ -12808,7 +12851,7 @@ var ChannelManager = class extends WithSubscriptions {
12808
12851
  this.notificationRemovedFromChannelHandler = this.channelDeletedHandler;
12809
12852
  this.memberUpdatedHandler = (event) => {
12810
12853
  const { pagination, channels } = this.state.getLatestValue();
12811
- const { filters, sort } = pagination;
12854
+ const { filters, sort } = getResponseFiltersAndSort(pagination);
12812
12855
  if (!event.member?.user || event.member.user.id !== this.client.userID || !event.channel_type || !event.channel_id) {
12813
12856
  return;
12814
12857
  }
@@ -14547,16 +14590,22 @@ var StreamChat = class _StreamChat {
14547
14590
  );
14548
14591
  }
14549
14592
  /**
14550
- * 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.
14551
14600
  *
14552
14601
  * @param {ChannelFilters} filterConditions object MongoDB style filters. Can be empty object when using predefined_filter in options.
14553
14602
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
14554
14603
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
14555
14604
  * @param {ChannelOptions} [options] Options object. Can include predefined_filter, filter_values, and sort_values for using predefined filters.
14556
14605
  *
14557
- * @return {Promise<Array<ChannelAPIResponse>>} search channels response
14606
+ * @return {Promise<QueryChannelsAPIResponse>} full search channels response
14558
14607
  */
14559
- async queryChannelsRequest(filterConditions, sort = [], options = {}) {
14608
+ async queryChannelsRequestWithResponse(filterConditions, sort = [], options = {}) {
14560
14609
  const defaultOptions = {
14561
14610
  state: true,
14562
14611
  watch: true,
@@ -14581,27 +14630,38 @@ var StreamChat = class _StreamChat {
14581
14630
  ...defaultOptions,
14582
14631
  ...restOptions
14583
14632
  };
14584
- const data = await this.post(
14585
- this.baseURL + "/channels",
14586
- payload
14587
- );
14588
- return data.channels;
14633
+ return await this.post(this.baseURL + "/channels", payload);
14589
14634
  }
14590
14635
  /**
14591
- * 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.
14592
14642
  *
14593
- * @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.
14594
14644
  * @param {ChannelSort} [sort] Sort options, for instance {created_at: -1}.
14595
14645
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{last_updated: -1}, {created_at: 1}]
14596
- * @param {ChannelOptions} [options] Options object
14597
- * @param {ChannelStateOptions} [stateOptions] State options object. These options will only be used for state management and won't be sent in the request.
14598
- * - stateOptions.skipInitialization - Skips the initialization of the state for the channels matching the ids in the list.
14599
- * - 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.
14600
14647
  *
14601
- * @return {Promise<Array<Channel>>} search channels response
14648
+ * @return {Promise<Array<ChannelAPIResponse>>} search channels response
14602
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
+ }
14603
14658
  async queryChannels(filterConditions, sort = [], options = {}, stateOptions = {}) {
14604
- 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;
14605
14665
  this.dispatchEvent({
14606
14666
  type: "channels.queried",
14607
14667
  queriedChannels: {
@@ -14615,7 +14675,14 @@ var StreamChat = class _StreamChat {
14615
14675
  isLatestMessagesSet: true
14616
14676
  });
14617
14677
  }
14618
- 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;
14619
14686
  }
14620
14687
  /**
14621
14688
  * queryReactions - Query reactions
@@ -15740,7 +15807,7 @@ var StreamChat = class _StreamChat {
15740
15807
  if (this.userAgent) {
15741
15808
  return this.userAgent;
15742
15809
  }
15743
- const version = "9.44.0";
15810
+ const version = "9.44.2";
15744
15811
  const clientBundle = "node-cjs";
15745
15812
  let userAgentString = "";
15746
15813
  if (this.sdkIdentifier) {