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.
@@ -4392,110 +4392,6 @@ var BaseSearchSourceSync = class extends BaseSearchSourceBase {
4392
4392
  }
4393
4393
  };
4394
4394
 
4395
- // src/search/SearchController.ts
4396
- var SearchController = class {
4397
- constructor({ config, sources } = {}) {
4398
- this.addSource = (source) => {
4399
- this.state.partialNext({
4400
- sources: [...this.sources, source]
4401
- });
4402
- };
4403
- this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
4404
- this.removeSource = (sourceType) => {
4405
- const newSources = this.sources.filter((s) => s.type !== sourceType);
4406
- if (newSources.length === this.sources.length) return;
4407
- this.state.partialNext({ sources: newSources });
4408
- };
4409
- this.activateSource = (sourceType) => {
4410
- const source = this.getSource(sourceType);
4411
- if (!source || source.isActive) return;
4412
- if (this.config.keepSingleActiveSource) {
4413
- this.sources.forEach((s) => {
4414
- if (s.type !== sourceType) {
4415
- s.deactivate();
4416
- }
4417
- });
4418
- }
4419
- source.activate();
4420
- this.state.partialNext({ sources: [...this.sources] });
4421
- };
4422
- this.deactivateSource = (sourceType) => {
4423
- const source = this.getSource(sourceType);
4424
- if (!source?.isActive) return;
4425
- if (this.activeSources.length === 1) return;
4426
- source.deactivate();
4427
- this.state.partialNext({ sources: [...this.sources] });
4428
- };
4429
- this.activate = () => {
4430
- if (!this.activeSources.length) {
4431
- const sourcesToActivate = this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources;
4432
- sourcesToActivate.forEach((s) => s.activate());
4433
- }
4434
- if (this.isActive) return;
4435
- this.state.partialNext({ isActive: true });
4436
- };
4437
- this.search = async (searchQuery) => {
4438
- const searchedSources = this.activeSources;
4439
- this.state.partialNext({
4440
- searchQuery
4441
- });
4442
- await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
4443
- };
4444
- this.cancelSearchQueries = () => {
4445
- this.activeSources.forEach((s) => s.cancelScheduledQuery());
4446
- };
4447
- this.clear = () => {
4448
- this.cancelSearchQueries();
4449
- this.sources.forEach(
4450
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4451
- );
4452
- this.state.next((current) => ({
4453
- ...current,
4454
- isActive: true,
4455
- queriesInProgress: [],
4456
- searchQuery: ""
4457
- }));
4458
- };
4459
- this.exit = () => {
4460
- this.cancelSearchQueries();
4461
- this.sources.forEach(
4462
- (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4463
- );
4464
- this.state.next((current) => ({
4465
- ...current,
4466
- isActive: false,
4467
- queriesInProgress: [],
4468
- searchQuery: ""
4469
- }));
4470
- };
4471
- this.state = new StateStore({
4472
- isActive: false,
4473
- searchQuery: "",
4474
- sources: sources ?? []
4475
- });
4476
- this._internalState = new StateStore({});
4477
- this.config = { keepSingleActiveSource: true, ...config };
4478
- }
4479
- get hasNext() {
4480
- return this.sources.some((source) => source.hasNext);
4481
- }
4482
- get sources() {
4483
- return this.state.getLatestValue().sources;
4484
- }
4485
- get activeSources() {
4486
- return this.state.getLatestValue().sources.filter((s) => s.isActive);
4487
- }
4488
- get isActive() {
4489
- return this.state.getLatestValue().isActive;
4490
- }
4491
- get searchQuery() {
4492
- return this.state.getLatestValue().searchQuery;
4493
- }
4494
- get searchSourceTypes() {
4495
- return this.sources.map((s) => s.type);
4496
- }
4497
- };
4498
-
4499
4395
  // src/pagination/BasePaginator.ts
4500
4396
  var DEFAULT_PAGINATION_OPTIONS = {
4501
4397
  debounceMs: 300,
@@ -4764,6 +4660,152 @@ var UserGroupPaginator = class extends BasePaginator {
4764
4660
  }
4765
4661
  };
4766
4662
 
4663
+ // src/search/ChannelMemberSearchSource.ts
4664
+ var ChannelMemberSearchSource = class extends BaseSearchSource {
4665
+ constructor(channel, options, filterBuilderOptions = {}) {
4666
+ super(options);
4667
+ this.type = "members";
4668
+ this.canExecuteQuery = (newSearchString) => {
4669
+ const hasNewSearchQuery = typeof newSearchString !== "undefined";
4670
+ return this.isActive && !this.isLoading && (this.hasNext || hasNewSearchQuery);
4671
+ };
4672
+ this.channel = channel;
4673
+ this.filterBuilder = new FilterBuilder({
4674
+ initialFilterConfig: {
4675
+ default: {
4676
+ enabled: true,
4677
+ generate: ({ searchQuery }) => searchQuery ? {
4678
+ $or: [
4679
+ { name: { $autocomplete: searchQuery } },
4680
+ { id: { $eq: searchQuery } }
4681
+ ]
4682
+ } : null
4683
+ }
4684
+ },
4685
+ ...filterBuilderOptions
4686
+ });
4687
+ }
4688
+ async query(searchQuery) {
4689
+ const filters = this.filterBuilder.buildFilters({
4690
+ baseFilters: this.filters,
4691
+ context: {
4692
+ searchQuery
4693
+ }
4694
+ });
4695
+ const sort = this.sort ?? [];
4696
+ const options = { ...this.searchOptions, limit: this.pageSize, offset: this.offset };
4697
+ const { members } = await this.channel.queryMembers(filters ?? {}, sort, options);
4698
+ return { items: members };
4699
+ }
4700
+ filterQueryResults(items) {
4701
+ return items;
4702
+ }
4703
+ };
4704
+
4705
+ // src/search/SearchController.ts
4706
+ var SearchController = class {
4707
+ constructor({ config, sources } = {}) {
4708
+ this.addSource = (source) => {
4709
+ this.state.partialNext({
4710
+ sources: [...this.sources, source]
4711
+ });
4712
+ };
4713
+ this.getSource = (sourceType) => this.sources.find((s) => s.type === sourceType);
4714
+ this.removeSource = (sourceType) => {
4715
+ const newSources = this.sources.filter((s) => s.type !== sourceType);
4716
+ if (newSources.length === this.sources.length) return;
4717
+ this.state.partialNext({ sources: newSources });
4718
+ };
4719
+ this.activateSource = (sourceType) => {
4720
+ const source = this.getSource(sourceType);
4721
+ if (!source || source.isActive) return;
4722
+ if (this.config.keepSingleActiveSource) {
4723
+ this.sources.forEach((s) => {
4724
+ if (s.type !== sourceType) {
4725
+ s.deactivate();
4726
+ }
4727
+ });
4728
+ }
4729
+ source.activate();
4730
+ this.state.partialNext({ sources: [...this.sources] });
4731
+ };
4732
+ this.deactivateSource = (sourceType) => {
4733
+ const source = this.getSource(sourceType);
4734
+ if (!source?.isActive) return;
4735
+ if (this.activeSources.length === 1) return;
4736
+ source.deactivate();
4737
+ this.state.partialNext({ sources: [...this.sources] });
4738
+ };
4739
+ this.activate = () => {
4740
+ if (!this.activeSources.length) {
4741
+ const sourcesToActivate = this.config.keepSingleActiveSource ? this.sources.slice(0, 1) : this.sources;
4742
+ sourcesToActivate.forEach((s) => s.activate());
4743
+ }
4744
+ if (this.isActive) return;
4745
+ this.state.partialNext({ isActive: true });
4746
+ };
4747
+ this.search = async (searchQuery) => {
4748
+ const searchedSources = this.activeSources;
4749
+ this.state.partialNext({
4750
+ searchQuery
4751
+ });
4752
+ await Promise.all(searchedSources.map((source) => source.search(searchQuery)));
4753
+ };
4754
+ this.cancelSearchQueries = () => {
4755
+ this.activeSources.forEach((s) => s.cancelScheduledQuery());
4756
+ };
4757
+ this.clear = () => {
4758
+ this.cancelSearchQueries();
4759
+ this.sources.forEach(
4760
+ (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4761
+ );
4762
+ this.state.next((current) => ({
4763
+ ...current,
4764
+ isActive: true,
4765
+ queriesInProgress: [],
4766
+ searchQuery: ""
4767
+ }));
4768
+ };
4769
+ this.exit = () => {
4770
+ this.cancelSearchQueries();
4771
+ this.sources.forEach(
4772
+ (source) => source.state.next({ ...source.initialState, isActive: source.isActive })
4773
+ );
4774
+ this.state.next((current) => ({
4775
+ ...current,
4776
+ isActive: false,
4777
+ queriesInProgress: [],
4778
+ searchQuery: ""
4779
+ }));
4780
+ };
4781
+ this.state = new StateStore({
4782
+ isActive: false,
4783
+ searchQuery: "",
4784
+ sources: sources ?? []
4785
+ });
4786
+ this._internalState = new StateStore({});
4787
+ this.config = { keepSingleActiveSource: true, ...config };
4788
+ }
4789
+ get hasNext() {
4790
+ return this.sources.some((source) => source.hasNext);
4791
+ }
4792
+ get sources() {
4793
+ return this.state.getLatestValue().sources;
4794
+ }
4795
+ get activeSources() {
4796
+ return this.state.getLatestValue().sources.filter((s) => s.isActive);
4797
+ }
4798
+ get isActive() {
4799
+ return this.state.getLatestValue().isActive;
4800
+ }
4801
+ get searchQuery() {
4802
+ return this.state.getLatestValue().searchQuery;
4803
+ }
4804
+ get searchSourceTypes() {
4805
+ return this.sources.map((s) => s.type);
4806
+ }
4807
+ };
4808
+
4767
4809
  // src/search/UserSearchSource.ts
4768
4810
  var UserSearchSource = class extends BaseSearchSource {
4769
4811
  constructor(client, options, filterBuilderOptions = {}) {
@@ -4870,7 +4912,7 @@ var MessageSearchSource = class extends BaseSearchSource {
4870
4912
  });
4871
4913
  }
4872
4914
  async query(searchQuery) {
4873
- if (!this.client.userID || !searchQuery || this.next === null) return { items: [] };
4915
+ if (!this.client.userID || this.next === null) return { items: [] };
4874
4916
  const channelFilters = this.messageSearchChannelFilterBuilder.buildFilters({
4875
4917
  baseFilters: {
4876
4918
  ...this.client.userID ? { members: { $in: [this.client.userID] } } : {},
@@ -13899,6 +13941,69 @@ var getPendingTaskChannelData = (cid) => {
13899
13941
  };
13900
13942
  };
13901
13943
 
13944
+ // src/utils/FixedSizeQueueCache.ts
13945
+ var FixedSizeQueueCache = class {
13946
+ constructor(size, options) {
13947
+ if (!size) throw new Error("Size must be greater than 0");
13948
+ this.keys = [];
13949
+ this.size = size;
13950
+ this.map = /* @__PURE__ */ new Map();
13951
+ this.dispose = options?.dispose ?? null;
13952
+ }
13953
+ /**
13954
+ * Adds a new or moves the existing reference to the front of the queue
13955
+ * @param key
13956
+ * @param value
13957
+ */
13958
+ add(key, value) {
13959
+ const index = this.keys.indexOf(key);
13960
+ if (index > -1) {
13961
+ this.keys.splice(this.keys.indexOf(key), 1);
13962
+ } else if (this.keys.length >= this.size) {
13963
+ const itemKey = this.keys.shift();
13964
+ if (itemKey) {
13965
+ const item = this.peek(itemKey);
13966
+ if (item) {
13967
+ this.dispose?.(itemKey, item);
13968
+ }
13969
+ this.map.delete(itemKey);
13970
+ }
13971
+ }
13972
+ this.keys.push(key);
13973
+ this.map.set(key, value);
13974
+ }
13975
+ /**
13976
+ * Retrieves the value by key.
13977
+ * @param key
13978
+ */
13979
+ peek(key) {
13980
+ const value = this.map.get(key);
13981
+ return value;
13982
+ }
13983
+ /**
13984
+ * Retrieves the value and moves it to the front of the queue.
13985
+ * @param key
13986
+ */
13987
+ get(key) {
13988
+ const foundItem = this.peek(key);
13989
+ if (foundItem && this.keys.indexOf(key) !== this.size - 1) {
13990
+ this.keys.splice(this.keys.indexOf(key), 1);
13991
+ this.keys.push(key);
13992
+ }
13993
+ return foundItem;
13994
+ }
13995
+ /**
13996
+ * Clears queue entirely and disposes of each item individually.
13997
+ */
13998
+ clear() {
13999
+ if (this.dispose) {
14000
+ this.map.forEach((entry, key) => this.dispose?.(key, entry));
14001
+ }
14002
+ this.map.clear();
14003
+ this.keys = [];
14004
+ }
14005
+ };
14006
+
13902
14007
  // src/client.ts
13903
14008
  function isString2(x) {
13904
14009
  return typeof x === "string" || x instanceof String;
@@ -14105,6 +14210,7 @@ var StreamChat = class _StreamChat {
14105
14210
  this.state = new ClientState({ client: this });
14106
14211
  this.threads.resetState();
14107
14212
  this.uploadManager.reset();
14213
+ this.messageComposerCache.clear();
14108
14214
  closePromise.finally(() => {
14109
14215
  this.tokenManager.reset();
14110
14216
  }).catch((err) => console.error(err));
@@ -14556,6 +14662,7 @@ var StreamChat = class _StreamChat {
14556
14662
  this.polls = new PollManager({ client: this });
14557
14663
  this.reminders = new ReminderManager({ client: this });
14558
14664
  this.messageDeliveryReporter = new MessageDeliveryReporter({ client: this });
14665
+ this.messageComposerCache = new FixedSizeQueueCache(64);
14559
14666
  }
14560
14667
  static getInstance(key, secretOrOptions, options) {
14561
14668
  if (!_StreamChat._instance) {
@@ -16428,7 +16535,7 @@ var StreamChat = class _StreamChat {
16428
16535
  if (this.userAgent) {
16429
16536
  return this.userAgent;
16430
16537
  }
16431
- const version = "9.45.5";
16538
+ const version = "9.46.0";
16432
16539
  const clientBundle = "browser-esm";
16433
16540
  let userAgentString = "";
16434
16541
  if (this.sdkIdentifier) {
@@ -19026,59 +19133,6 @@ var _LiveLocationManager = class _LiveLocationManager extends WithSubscriptions
19026
19133
  };
19027
19134
  _LiveLocationManager.symbol = Symbol(_LiveLocationManager.name);
19028
19135
  var LiveLocationManager = _LiveLocationManager;
19029
-
19030
- // src/utils/FixedSizeQueueCache.ts
19031
- var FixedSizeQueueCache = class {
19032
- constructor(size, options) {
19033
- if (!size) throw new Error("Size must be greater than 0");
19034
- this.keys = [];
19035
- this.size = size;
19036
- this.map = /* @__PURE__ */ new Map();
19037
- this.dispose = options?.dispose ?? null;
19038
- }
19039
- /**
19040
- * Adds a new or moves the existing reference to the front of the queue
19041
- * @param key
19042
- * @param value
19043
- */
19044
- add(key, value) {
19045
- const index = this.keys.indexOf(key);
19046
- if (index > -1) {
19047
- this.keys.splice(this.keys.indexOf(key), 1);
19048
- } else if (this.keys.length >= this.size) {
19049
- const itemKey = this.keys.shift();
19050
- if (itemKey) {
19051
- const item = this.peek(itemKey);
19052
- if (item) {
19053
- this.dispose?.(itemKey, item);
19054
- }
19055
- this.map.delete(itemKey);
19056
- }
19057
- }
19058
- this.keys.push(key);
19059
- this.map.set(key, value);
19060
- }
19061
- /**
19062
- * Retrieves the value by key.
19063
- * @param key
19064
- */
19065
- peek(key) {
19066
- const value = this.map.get(key);
19067
- return value;
19068
- }
19069
- /**
19070
- * Retrieves the value and moves it to the front of the queue.
19071
- * @param key
19072
- */
19073
- get(key) {
19074
- const foundItem = this.peek(key);
19075
- if (foundItem && this.keys.indexOf(key) !== this.size - 1) {
19076
- this.keys.splice(this.keys.indexOf(key), 1);
19077
- this.keys.push(key);
19078
- }
19079
- return foundItem;
19080
- }
19081
- };
19082
19136
  export {
19083
19137
  AbstractOfflineDB,
19084
19138
  Allow,
@@ -19097,6 +19151,7 @@ export {
19097
19151
  Channel,
19098
19152
  ChannelBatchUpdater,
19099
19153
  ChannelManager,
19154
+ ChannelMemberSearchSource,
19100
19155
  ChannelSearchSource,
19101
19156
  ChannelState,
19102
19157
  CheckSignature,