stream-chat 9.52.0 → 9.52.1

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.
@@ -364,6 +364,22 @@ function logChatPromiseExecution(promise, name) {
364
364
  console.warn(`failed to do ${name}, ran into error: `, error);
365
365
  });
366
366
  }
367
+ var noopLogger = () => null;
368
+ var logError = (logger, error, event) => {
369
+ const message = "Unhandled error in event listener";
370
+ logger("error", message, { error, event });
371
+ if (logger === noopLogger) console.error(message, error, event);
372
+ };
373
+ var invokeEventListener = (listener, event, logger) => {
374
+ try {
375
+ const result = listener(event);
376
+ if (result && typeof result.then === "function") {
377
+ Promise.resolve(result).catch((error) => logError(logger, error, event));
378
+ }
379
+ } catch (error) {
380
+ logError(logger, error, event);
381
+ }
382
+ };
367
383
  var sleep = (m) => new Promise((r) => setTimeout(r, m));
368
384
  function isFunction(value) {
369
385
  return typeof value === "function" || value instanceof Function || Object.prototype.toString.call(value) === "[object Function]";
@@ -411,7 +427,6 @@ var channelHasReadEvents = (channel) => {
411
427
  return !(Array.isArray(ownCapabilities) && !ownCapabilities.includes("read-events"));
412
428
  };
413
429
  var channelTracksReadLocally = (channel) => !channelHasReadEvents(channel) && !!channel?.getClient().options.isLocalUnreadCountEnabled;
414
- var userHasReadReceipts = (client) => client.user?.privacy_settings?.read_receipts?.enabled ?? true;
415
430
  function addFileToFormData(uri, name, contentType) {
416
431
  const data = new FormData();
417
432
  if (isReadableStream(uri) || isBuffer(uri) || isFileWebAPI(uri) || isBlobWebAPI(uri)) {
@@ -8964,7 +8979,6 @@ var MessageDeliveryReporter = class _MessageDeliveryReporter {
8964
8979
  * @param options
8965
8980
  */
8966
8981
  this.markRead = async (collection, options) => {
8967
- if (!userHasReadReceipts(this.client)) return null;
8968
8982
  let result = null;
8969
8983
  if (isChannel(collection)) {
8970
8984
  result = await collection.markAsReadRequest(options);
@@ -8974,7 +8988,7 @@ var MessageDeliveryReporter = class _MessageDeliveryReporter {
8974
8988
  thread_id: collection.id
8975
8989
  });
8976
8990
  }
8977
- this.removeCandidateFor(collection);
8991
+ if (result) this.removeCandidateFor(collection);
8978
8992
  return result;
8979
8993
  };
8980
8994
  /**
@@ -9359,18 +9373,14 @@ var Channel = class {
9359
9373
  return await this.query(defaultOptions, "latest");
9360
9374
  };
9361
9375
  this._callChannelListeners = (event) => {
9362
- const channel = this;
9363
- const listeners = [];
9364
- if (channel.listeners.all) {
9365
- listeners.push(...channel.listeners.all);
9366
- }
9367
- if (channel.listeners[event.type]) {
9368
- listeners.push(...channel.listeners[event.type]);
9369
- }
9376
+ const listeners = [
9377
+ ...this.listeners.all ?? [],
9378
+ ...this.listeners[event.type] ?? []
9379
+ ];
9380
+ const { logger } = this._client;
9370
9381
  for (const listener of listeners) {
9371
- if (typeof listener !== "string") {
9372
- listener(event);
9373
- }
9382
+ if (typeof listener === "string") continue;
9383
+ invokeEventListener(listener, event, logger);
9374
9384
  }
9375
9385
  };
9376
9386
  /**
@@ -10284,14 +10294,15 @@ var Channel = class {
10284
10294
  return await this.getClient().messageDeliveryReporter.markRead(this, data);
10285
10295
  }
10286
10296
  /**
10287
- * markReadRequest - Send the mark read event for this user, only works if the `read_events` setting is enabled
10297
+ * markReadRequest - Send the mark read event for this user, only works if the `read_events` setting is
10298
+ * enabled and the user holds the `read-events` capability on this channel
10288
10299
  *
10289
10300
  * @param {MarkReadOptions} data
10290
10301
  * @return {Promise<EventAPIResponse | null>} Description
10291
10302
  */
10292
10303
  async markAsReadRequest(data = {}) {
10293
10304
  this._checkInitialized();
10294
- if (!this.getConfig()?.read_events && !this.getClient()._isUsingServerAuth()) {
10305
+ if (!this.getClient()._isUsingServerAuth() && (!this.getConfig()?.read_events || !channelHasReadEvents(this))) {
10295
10306
  return null;
10296
10307
  }
10297
10308
  return await this.getClient().post(this._channelURL() + "/read", {
@@ -10299,14 +10310,15 @@ var Channel = class {
10299
10310
  });
10300
10311
  }
10301
10312
  /**
10302
- * markUnread - Mark the channel as unread from messageID, only works if the `read_events` setting is enabled
10313
+ * markUnread - Mark the channel as unread from messageID, only works if the `read_events` setting is
10314
+ * enabled and the user holds the `read-events` capability on this channel
10303
10315
  *
10304
10316
  * @param {MarkUnreadOptions} data
10305
10317
  * @return {APIResponse} An API response
10306
10318
  */
10307
10319
  async markUnread(data) {
10308
10320
  this._checkInitialized();
10309
- if (!this.getConfig()?.read_events && !this.getClient()._isUsingServerAuth()) {
10321
+ if (!this.getClient()._isUsingServerAuth() && (!this.getConfig()?.read_events || !channelHasReadEvents(this))) {
10310
10322
  return Promise.resolve(null);
10311
10323
  }
10312
10324
  return await this.getClient().post(this._channelURL() + "/unread", {
@@ -14768,16 +14780,12 @@ var StreamChat = class _StreamChat {
14768
14780
  }
14769
14781
  };
14770
14782
  this._callClientListeners = (event) => {
14771
- const client = this;
14772
- const listeners = [];
14773
- if (client.listeners.all) {
14774
- listeners.push(...client.listeners.all);
14775
- }
14776
- if (client.listeners[event.type]) {
14777
- listeners.push(...client.listeners[event.type]);
14778
- }
14783
+ const listeners = [
14784
+ ...this.listeners.all ?? [],
14785
+ ...this.listeners[event.type] ?? []
14786
+ ];
14779
14787
  for (const listener of listeners) {
14780
- listener(event);
14788
+ invokeEventListener(listener, event, this.logger);
14781
14789
  }
14782
14790
  };
14783
14791
  this.recoverState = async () => {
@@ -14931,7 +14939,7 @@ var StreamChat = class _StreamChat {
14931
14939
  return this.userAgent;
14932
14940
  }
14933
14941
  if (!this.cachedUserAgent) {
14934
- const version = "9.52.0";
14942
+ const version = "9.52.1";
14935
14943
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
14936
14944
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
14937
14945
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -15020,7 +15028,7 @@ var StreamChat = class _StreamChat {
15020
15028
  this.defaultWSTimeoutWithFallback = 6 * 1e3;
15021
15029
  this.defaultWSTimeout = 15 * 1e3;
15022
15030
  this.axiosInstance.defaults.paramsSerializer = axiosParamsSerializer;
15023
- this.logger = isFunction(inputOptions.logger) ? inputOptions.logger : () => null;
15031
+ this.logger = isFunction(inputOptions.logger) ? inputOptions.logger : noopLogger;
15024
15032
  this.recoverStateOnReconnect = this.options.recoverStateOnReconnect;
15025
15033
  this.threads = new ThreadManager({ client: this });
15026
15034
  this.polls = new PollManager({ client: this });