stream-chat 9.54.0 → 9.54.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.
@@ -8280,10 +8280,13 @@ var Thread = class extends WithSubscriptions {
8280
8280
  }));
8281
8281
  }
8282
8282
  };
8283
- const channel = client.channel(threadData.channel.type, threadData.channel.id, {
8284
- // @ts-expect-error name is a "custom" property
8285
- name: threadData.channel.name
8286
- });
8283
+ const channelResponse = threadData.channel;
8284
+ const channelData = { name: channelResponse.name };
8285
+ const channel = client.channel(
8286
+ threadData.channel.type,
8287
+ threadData.channel.id,
8288
+ channelData
8289
+ );
8287
8290
  channel._hydrateMembers({
8288
8291
  members: threadData.channel.members ?? [],
8289
8292
  overrideCurrentState: false
@@ -11683,6 +11686,10 @@ var StableWSConnection = class {
11683
11686
  if (data.type === "health.check") {
11684
11687
  this.scheduleNextPing();
11685
11688
  }
11689
+ if (data?.type === "connection.error" && data?.error?.code === chatCodes.TOKEN_EXPIRED) {
11690
+ this._log("onmessage() - server reported that the token expired", { wsID });
11691
+ this.tokenExpiredByServer = true;
11692
+ }
11686
11693
  this.client.dispatchEvent(data);
11687
11694
  this.scheduleConnectionCheck();
11688
11695
  };
@@ -11706,7 +11713,7 @@ var StableWSConnection = class {
11706
11713
  this.isConnecting = false;
11707
11714
  this.rejectPromise?.(this._errorFromWSEvent(event));
11708
11715
  this._log(`onclose() - WS connection closed. Calling reconnect ...`, { event });
11709
- this._reconnect();
11716
+ this._reconnectAfterFailure();
11710
11717
  }
11711
11718
  };
11712
11719
  this.onerror = (wsID, event) => {
@@ -11717,7 +11724,7 @@ var StableWSConnection = class {
11717
11724
  this.isConnecting = false;
11718
11725
  this.rejectPromise?.(this._errorFromWSEvent(event));
11719
11726
  this._log(`onerror() - WS connection resulted into error`, { event });
11720
- this._reconnect();
11727
+ this._reconnectAfterFailure();
11721
11728
  };
11722
11729
  /**
11723
11730
  * _setHealth - Sets the connection to healthy or unhealthy.
@@ -11770,6 +11777,7 @@ var StableWSConnection = class {
11770
11777
  */
11771
11778
  this._setupConnectionPromise = () => {
11772
11779
  this.isResolved = false;
11780
+ this.tokenExpiredByServer = false;
11773
11781
  this.connectionOpen = new Promise((resolve, reject) => {
11774
11782
  this.resolvePromise = resolve;
11775
11783
  this.rejectPromise = reject;
@@ -11817,6 +11825,7 @@ var StableWSConnection = class {
11817
11825
  this.isHealthy = false;
11818
11826
  this.wsID = 1;
11819
11827
  this.lastEvent = null;
11828
+ this.tokenExpiredByServer = false;
11820
11829
  this.pingInterval = 25 * 1e3;
11821
11830
  this.connectionCheckTimeout = this.pingInterval + 10 * 1e3;
11822
11831
  addConnectionEventListeners(this.onlineStatusChanged);
@@ -11915,6 +11924,7 @@ var StableWSConnection = class {
11915
11924
  this.wsID += 1;
11916
11925
  this.isConnecting = false;
11917
11926
  this.isDisconnected = true;
11927
+ this.tokenExpiredByServer = false;
11918
11928
  if (this.healthCheckTimeoutRef) {
11919
11929
  clearInterval(this.healthCheckTimeoutRef);
11920
11930
  }
@@ -12047,6 +12057,10 @@ var StableWSConnection = class {
12047
12057
  this._destroyCurrentWSConnection();
12048
12058
  if (options.refreshToken) {
12049
12059
  await this.client.tokenManager.loadToken();
12060
+ if (this.isConnecting || this.isHealthy) {
12061
+ this._log("_reconnect() - Abort (4) since already connecting or healthy");
12062
+ return;
12063
+ }
12050
12064
  }
12051
12065
  try {
12052
12066
  await this._connect();
@@ -12070,6 +12084,21 @@ var StableWSConnection = class {
12070
12084
  }
12071
12085
  this._log("_reconnect() - == END ==");
12072
12086
  }
12087
+ /**
12088
+ * _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
12089
+ * reported that the token expired, the token is refreshed before reconnecting.
12090
+ * Static tokens cannot be refreshed and reconnect as before.
12091
+ */
12092
+ _reconnectAfterFailure() {
12093
+ if (this.tokenExpiredByServer && !this.client.tokenManager.isStatic()) {
12094
+ this._log(
12095
+ "_reconnectAfterFailure() - token expired, so going to reload token and reconnect"
12096
+ );
12097
+ this._reconnect({ refreshToken: true });
12098
+ return;
12099
+ }
12100
+ this._reconnect();
12101
+ }
12073
12102
  /**
12074
12103
  * _destroyCurrentWSConnection - Removes the current WS connection
12075
12104
  *
@@ -13432,7 +13461,15 @@ var Poll = class {
13432
13461
  if (!isPollUpdatedEvent(event)) return;
13433
13462
  const { id, ...pollData } = extractPollData(event.poll);
13434
13463
  if (pollData.is_closed) this.closeConfirmed = true;
13435
- this.state.partialNext({ ...pollData, lastActivityAt: new Date(event.created_at) });
13464
+ this.state.partialNext({
13465
+ ...pollData,
13466
+ // Server-owned translations, which `extractPollData` (an update request) leaves out. Copied
13467
+ // even when absent: the event carries the whole poll, and a change made under channel-only
13468
+ // translation drops the stale ones.
13469
+ description_i18n: event.poll.description_i18n,
13470
+ lastActivityAt: new Date(event.created_at),
13471
+ name_i18n: event.poll.name_i18n
13472
+ });
13436
13473
  this.upsertOfflineDb();
13437
13474
  };
13438
13475
  this.handlePollClosed = (event) => {
@@ -15425,7 +15462,7 @@ var StreamChat = class _StreamChat {
15425
15462
  return this.userAgent;
15426
15463
  }
15427
15464
  if (!this.cachedUserAgent) {
15428
- const version = "9.54.0";
15465
+ const version = "9.54.1";
15429
15466
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
15430
15467
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
15431
15468
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -17014,7 +17051,7 @@ var StreamChat = class _StreamChat {
17014
17051
  * @param {string} messageId
17015
17052
  * @param {string} language
17016
17053
  *
17017
- * @return {MessageResponse} Response that includes the message
17054
+ * @return {APIResponse & { message: MessageResponse }} Response that includes the translated message
17018
17055
  */
17019
17056
  async translateMessage(messageId, language) {
17020
17057
  return await this.post(