stream-chat 9.45.5 → 9.46.0

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.
@@ -74,6 +74,7 @@ __export(index_exports, {
74
74
  Channel: () => Channel,
75
75
  ChannelBatchUpdater: () => ChannelBatchUpdater,
76
76
  ChannelManager: () => ChannelManager,
77
+ ChannelMemberSearchSource: () => ChannelMemberSearchSource,
77
78
  ChannelSearchSource: () => ChannelSearchSource,
78
79
  ChannelState: () => ChannelState,
79
80
  CheckSignature: () => CheckSignature,
@@ -4605,110 +4606,6 @@ var BaseSearchSourceSync = class extends BaseSearchSourceBase {
4605
4606
  }
4606
4607
  };
4607
4608
 
4608
- // src/search/SearchController.ts
4609
- var SearchController = class {
4610
- constructor({ config, sources } = {}) {
4611
- this.addSource = (source) => {
4612
- this.state.partialNext({
4613
- sources: [...this.sources, source]
4614
- });
4615
- };
4616
- this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
4617
- this.removeSource = (sourceType) => {
4618
- const newSources = this.sources.filter((s) => s.type !== sourceType);
4619
- if (newSources.length === this.sources.length) return;
4620
- this.state.partialNext({ sources: newSources });
4621
- };
4622
- this.activateSource = (sourceType) => {
4623
- const source = this.getSource(sourceType);
4624
- if (!source || source.isActive) return;
4625
- if (this.config.keepSingleActiveSource) {
4626
- this.sources.forEach((s) => {
4627
- if (s.type !== sourceType) {
4628
- s.deactivate();
4629
- }
4630
- });
4631
- }
4632
- source.activate();
4633
- this.state.partialNext({ sources: [...this.sources] });
4634
- };
4635
- this.deactivateSource = (sourceType) => {
4636
- const source = this.getSource(sourceType);
4637
- if (!source?.isActive) return;
4638
- if (this.activeSources.length === 1) return;
4639
- source.deactivate();
4640
- this.state.partialNext({ sources: [...this.sources] });
4641
- };
4642
- this.activate = () => {
4643
- if (!this.activeSources.length) {
4644
- const sourcesToActivate = this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources;
4645
- sourcesToActivate.forEach((s) => s.activate());
4646
- }
4647
- if (this.isActive) return;
4648
- this.state.partialNext({ isActive: true });
4649
- };
4650
- this.search = async (searchQuery) => {
4651
- const searchedSources = this.activeSources;
4652
- this.state.partialNext({
4653
- searchQuery
4654
- });
4655
- await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
4656
- };
4657
- this.cancelSearchQueries = () => {
4658
- this.activeSources.forEach((s) => s.cancelScheduledQuery());
4659
- };
4660
- this.clear = () => {
4661
- this.cancelSearchQueries();
4662
- this.sources.forEach(
4663
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4664
- );
4665
- this.state.next((current) => ({
4666
- ...current,
4667
- isActive: true,
4668
- queriesInProgress: [],
4669
- searchQuery: ""
4670
- }));
4671
- };
4672
- this.exit = () => {
4673
- this.cancelSearchQueries();
4674
- this.sources.forEach(
4675
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4676
- );
4677
- this.state.next((current) => ({
4678
- ...current,
4679
- isActive: false,
4680
- queriesInProgress: [],
4681
- searchQuery: ""
4682
- }));
4683
- };
4684
- this.state = new StateStore({
4685
- isActive: false,
4686
- searchQuery: "",
4687
- sources: sources ?? []
4688
- });
4689
- this._internalState = new StateStore({});
4690
- this.config = { keepSingleActiveSource: true, ...config };
4691
- }
4692
- get hasNext() {
4693
- return this.sources.some((source) => source.hasNext);
4694
- }
4695
- get sources() {
4696
- return this.state.getLatestValue().sources;
4697
- }
4698
- get activeSources() {
4699
- return this.state.getLatestValue().sources.filter((s) => s.isActive);
4700
- }
4701
- get isActive() {
4702
- return this.state.getLatestValue().isActive;
4703
- }
4704
- get searchQuery() {
4705
- return this.state.getLatestValue().searchQuery;
4706
- }
4707
- get searchSourceTypes() {
4708
- return this.sources.map((s) => s.type);
4709
- }
4710
- };
4711
-
4712
4609
  // src/pagination/BasePaginator.ts
4713
4610
  var DEFAULT_PAGINATION_OPTIONS = {
4714
4611
  debounceMs: 300,
@@ -4977,6 +4874,152 @@ var UserGroupPaginator = class extends BasePaginator {
4977
4874
  }
4978
4875
  };
4979
4876
 
4877
+ // src/search/ChannelMemberSearchSource.ts
4878
+ var ChannelMemberSearchSource = class extends BaseSearchSource {
4879
+ constructor(channel, options, filterBuilderOptions = {}) {
4880
+ super(options);
4881
+ this.type = "members";
4882
+ this.canExecuteQuery = (newSearchString) => {
4883
+ const hasNewSearchQuery = typeof newSearchString !== "undefined";
4884
+ return this.isActive && !this.isLoading && (this.hasNext || hasNewSearchQuery);
4885
+ };
4886
+ this.channel = channel;
4887
+ this.filterBuilder = new FilterBuilder({
4888
+ initialFilterConfig: {
4889
+ default: {
4890
+ enabled: true,
4891
+ generate: ({ searchQuery }) => searchQuery ? {
4892
+ $or: [
4893
+ { name: { $autocomplete: searchQuery } },
4894
+ { id: { $eq: searchQuery } }
4895
+ ]
4896
+ } : null
4897
+ }
4898
+ },
4899
+ ...filterBuilderOptions
4900
+ });
4901
+ }
4902
+ async query(searchQuery) {
4903
+ const filters = this.filterBuilder.buildFilters({
4904
+ baseFilters: this.filters,
4905
+ context: {
4906
+ searchQuery
4907
+ }
4908
+ });
4909
+ const sort = this.sort ?? [];
4910
+ const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
4911
+ const { members } = await this.channel.queryMembers(filters ?? {}, sort, options);
4912
+ return { items: members };
4913
+ }
4914
+ filterQueryResults(items) {
4915
+ return items;
4916
+ }
4917
+ };
4918
+
4919
+ // src/search/SearchController.ts
4920
+ var SearchController = class {
4921
+ constructor({ config, sources } = {}) {
4922
+ this.addSource = (source) => {
4923
+ this.state.partialNext({
4924
+ sources: [...this.sources, source]
4925
+ });
4926
+ };
4927
+ this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
4928
+ this.removeSource = (sourceType) => {
4929
+ const newSources = this.sources.filter((s) => s.type !== sourceType);
4930
+ if (newSources.length === this.sources.length) return;
4931
+ this.state.partialNext({ sources: newSources });
4932
+ };
4933
+ this.activateSource = (sourceType) => {
4934
+ const source = this.getSource(sourceType);
4935
+ if (!source || source.isActive) return;
4936
+ if (this.config.keepSingleActiveSource) {
4937
+ this.sources.forEach((s) => {
4938
+ if (s.type !== sourceType) {
4939
+ s.deactivate();
4940
+ }
4941
+ });
4942
+ }
4943
+ source.activate();
4944
+ this.state.partialNext({ sources: [...this.sources] });
4945
+ };
4946
+ this.deactivateSource = (sourceType) => {
4947
+ const source = this.getSource(sourceType);
4948
+ if (!source?.isActive) return;
4949
+ if (this.activeSources.length === 1) return;
4950
+ source.deactivate();
4951
+ this.state.partialNext({ sources: [...this.sources] });
4952
+ };
4953
+ this.activate = () => {
4954
+ if (!this.activeSources.length) {
4955
+ const sourcesToActivate = this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources;
4956
+ sourcesToActivate.forEach((s) => s.activate());
4957
+ }
4958
+ if (this.isActive) return;
4959
+ this.state.partialNext({ isActive: true });
4960
+ };
4961
+ this.search = async (searchQuery) => {
4962
+ const searchedSources = this.activeSources;
4963
+ this.state.partialNext({
4964
+ searchQuery
4965
+ });
4966
+ await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
4967
+ };
4968
+ this.cancelSearchQueries = () => {
4969
+ this.activeSources.forEach((s) => s.cancelScheduledQuery());
4970
+ };
4971
+ this.clear = () => {
4972
+ this.cancelSearchQueries();
4973
+ this.sources.forEach(
4974
+ (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4975
+ );
4976
+ this.state.next((current) => ({
4977
+ ...current,
4978
+ isActive: true,
4979
+ queriesInProgress: [],
4980
+ searchQuery: ""
4981
+ }));
4982
+ };
4983
+ this.exit = () => {
4984
+ this.cancelSearchQueries();
4985
+ this.sources.forEach(
4986
+ (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4987
+ );
4988
+ this.state.next((current) => ({
4989
+ ...current,
4990
+ isActive: false,
4991
+ queriesInProgress: [],
4992
+ searchQuery: ""
4993
+ }));
4994
+ };
4995
+ this.state = new StateStore({
4996
+ isActive: false,
4997
+ searchQuery: "",
4998
+ sources: sources ?? []
4999
+ });
5000
+ this._internalState = new StateStore({});
5001
+ this.config = { keepSingleActiveSource: true, ...config };
5002
+ }
5003
+ get hasNext() {
5004
+ return this.sources.some((source) => source.hasNext);
5005
+ }
5006
+ get sources() {
5007
+ return this.state.getLatestValue().sources;
5008
+ }
5009
+ get activeSources() {
5010
+ return this.state.getLatestValue().sources.filter((s) => s.isActive);
5011
+ }
5012
+ get isActive() {
5013
+ return this.state.getLatestValue().isActive;
5014
+ }
5015
+ get searchQuery() {
5016
+ return this.state.getLatestValue().searchQuery;
5017
+ }
5018
+ get searchSourceTypes() {
5019
+ return this.sources.map((s) => s.type);
5020
+ }
5021
+ };
5022
+
4980
5023
  // src/search/UserSearchSource.ts
4981
5024
  var UserSearchSource = class extends BaseSearchSource {
4982
5025
  constructor(client, options, filterBuilderOptions = {}) {
@@ -5083,7 +5126,7 @@ var MessageSearchSource = class extends BaseSearchSource {
5083
5126
  });
5084
5127
  }
5085
5128
  async query(searchQuery) {
5086
- if (!this.client.userID || !searchQuery || this.next === null) return { items: [] };
5129
+ if (!this.client.userID || this.next === null) return { items: [] };
5087
5130
  const channelFilters = this.messageSearchChannelFilterBuilder.buildFilters({
5088
5131
  baseFilters: {
5089
5132
  ...this.client.userID ? { members: { $in: [this.client.userID] } } : {},
@@ -14112,6 +14155,69 @@ var getPendingTaskChannelData = (cid) => {
14112
14155
  };
14113
14156
  };
14114
14157
 
14158
+ // src/utils/FixedSizeQueueCache.ts
14159
+ var FixedSizeQueueCache = class {
14160
+ constructor(size, options) {
14161
+ if (!size) throw new Error("Size must be greater than 0");
14162
+ this.keys = [];
14163
+ this.size = size;
14164
+ this.map = /* @__PURE__ */ new Map();
14165
+ this.dispose = options?.dispose ?? null;
14166
+ }
14167
+ /**
14168
+ * Adds a new or moves the existing reference to the front of the queue
14169
+ * @param key
14170
+ * @param value
14171
+ */
14172
+ add(key, value) {
14173
+ const index = this.keys.indexOf(key);
14174
+ if (index > -1) {
14175
+ this.keys.splice(this.keys.indexOf(key), 1);
14176
+ } else if (this.keys.length >= this.size) {
14177
+ const itemKey = this.keys.shift();
14178
+ if (itemKey) {
14179
+ const item = this.peek(itemKey);
14180
+ if (item) {
14181
+ this.dispose?.(itemKey, item);
14182
+ }
14183
+ this.map.delete(itemKey);
14184
+ }
14185
+ }
14186
+ this.keys.push(key);
14187
+ this.map.set(key, value);
14188
+ }
14189
+ /**
14190
+ * Retrieves the value by key.
14191
+ * @param key
14192
+ */
14193
+ peek(key) {
14194
+ const value = this.map.get(key);
14195
+ return value;
14196
+ }
14197
+ /**
14198
+ * Retrieves the value and moves it to the front of the queue.
14199
+ * @param key
14200
+ */
14201
+ get(key) {
14202
+ const foundItem = this.peek(key);
14203
+ if (foundItem && this.keys.indexOf(key) !== this.size - 1) {
14204
+ this.keys.splice(this.keys.indexOf(key), 1);
14205
+ this.keys.push(key);
14206
+ }
14207
+ return foundItem;
14208
+ }
14209
+ /**
14210
+ * Clears queue entirely and disposes of each item individually.
14211
+ */
14212
+ clear() {
14213
+ if (this.dispose) {
14214
+ this.map.forEach((entry, key) => this.dispose?.(key, entry));
14215
+ }
14216
+ this.map.clear();
14217
+ this.keys = [];
14218
+ }
14219
+ };
14220
+
14115
14221
  // src/client.ts
14116
14222
  function isString2(x) {
14117
14223
  return typeof x === "string" || x instanceof String;
@@ -14318,6 +14424,7 @@ var StreamChat = class _StreamChat {
14318
14424
  this.state = new ClientState({ client: this });
14319
14425
  this.threads.resetState();
14320
14426
  this.uploadManager.reset();
14427
+ this.messageComposerCache.clear();
14321
14428
  closePromise.finally(() => {
14322
14429
  this.tokenManager.reset();
14323
14430
  }).catch((err) => console.error(err));
@@ -14769,6 +14876,7 @@ var StreamChat = class _StreamChat {
14769
14876
  this.polls = new PollManager({ client: this });
14770
14877
  this.reminders = new ReminderManager({ client: this });
14771
14878
  this.messageDeliveryReporter = new MessageDeliveryReporter({ client: this });
14879
+ this.messageComposerCache = new FixedSizeQueueCache(64);
14772
14880
  }
14773
14881
  static getInstance(key, secretOrOptions, options) {
14774
14882
  if (!_StreamChat._instance) {
@@ -16641,7 +16749,7 @@ var StreamChat = class _StreamChat {
16641
16749
  if (this.userAgent) {
16642
16750
  return this.userAgent;
16643
16751
  }
16644
- const version = "9.45.5";
16752
+ const version = "9.46.0";
16645
16753
  const clientBundle = "browser-cjs";
16646
16754
  let userAgentString = "";
16647
16755
  if (this.sdkIdentifier) {
@@ -19239,57 +19347,4 @@ var _LiveLocationManager = class _LiveLocationManager extends WithSubscriptions
19239
19347
  };
19240
19348
  _LiveLocationManager.symbol = Symbol(_LiveLocationManager.name);
19241
19349
  var LiveLocationManager = _LiveLocationManager;
19242
-
19243
- // src/utils/FixedSizeQueueCache.ts
19244
- var FixedSizeQueueCache = class {
19245
- constructor(size, options) {
19246
- if (!size) throw new Error("Size must be greater than 0");
19247
- this.keys = [];
19248
- this.size = size;
19249
- this.map = /* @__PURE__ */ new Map();
19250
- this.dispose = options?.dispose ?? null;
19251
- }
19252
- /**
19253
- * Adds a new or moves the existing reference to the front of the queue
19254
- * @param key
19255
- * @param value
19256
- */
19257
- add(key, value) {
19258
- const index = this.keys.indexOf(key);
19259
- if (index > -1) {
19260
- this.keys.splice(this.keys.indexOf(key), 1);
19261
- } else if (this.keys.length >= this.size) {
19262
- const itemKey = this.keys.shift();
19263
- if (itemKey) {
19264
- const item = this.peek(itemKey);
19265
- if (item) {
19266
- this.dispose?.(itemKey, item);
19267
- }
19268
- this.map.delete(itemKey);
19269
- }
19270
- }
19271
- this.keys.push(key);
19272
- this.map.set(key, value);
19273
- }
19274
- /**
19275
- * Retrieves the value by key.
19276
- * @param key
19277
- */
19278
- peek(key) {
19279
- const value = this.map.get(key);
19280
- return value;
19281
- }
19282
- /**
19283
- * Retrieves the value and moves it to the front of the queue.
19284
- * @param key
19285
- */
19286
- get(key) {
19287
- const foundItem = this.peek(key);
19288
- if (foundItem && this.keys.indexOf(key) !== this.size - 1) {
19289
- this.keys.splice(this.keys.indexOf(key), 1);
19290
- this.keys.push(key);
19291
- }
19292
- return foundItem;
19293
- }
19294
- };
19295
19350
  //# sourceMappingURL=index.browser.js.map