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.
@@ -8311,10 +8311,13 @@ var Thread = class extends WithSubscriptions {
8311
8311
  }));
8312
8312
  }
8313
8313
  };
8314
- const channel = client.channel(threadData.channel.type, threadData.channel.id, {
8315
- // @ts-expect-error name is a "custom" property
8316
- name: threadData.channel.name
8317
- });
8314
+ const channelResponse = threadData.channel;
8315
+ const channelData = { name: channelResponse.name };
8316
+ const channel = client.channel(
8317
+ threadData.channel.type,
8318
+ threadData.channel.id,
8319
+ channelData
8320
+ );
8318
8321
  channel._hydrateMembers({
8319
8322
  members: threadData.channel.members ?? [],
8320
8323
  overrideCurrentState: false
@@ -11714,6 +11717,10 @@ var StableWSConnection = class {
11714
11717
  if (data.type === "health.check") {
11715
11718
  this.scheduleNextPing();
11716
11719
  }
11720
+ if (data?.type === "connection.error" && data?.error?.code === chatCodes.TOKEN_EXPIRED) {
11721
+ this._log("onmessage() - server reported that the token expired", { wsID });
11722
+ this.tokenExpiredByServer = true;
11723
+ }
11717
11724
  this.client.dispatchEvent(data);
11718
11725
  this.scheduleConnectionCheck();
11719
11726
  };
@@ -11737,7 +11744,7 @@ var StableWSConnection = class {
11737
11744
  this.isConnecting = false;
11738
11745
  this.rejectPromise?.(this._errorFromWSEvent(event));
11739
11746
  this._log(`onclose() - WS connection closed. Calling reconnect ...`, { event });
11740
- this._reconnect();
11747
+ this._reconnectAfterFailure();
11741
11748
  }
11742
11749
  };
11743
11750
  this.onerror = (wsID, event) => {
@@ -11748,7 +11755,7 @@ var StableWSConnection = class {
11748
11755
  this.isConnecting = false;
11749
11756
  this.rejectPromise?.(this._errorFromWSEvent(event));
11750
11757
  this._log(`onerror() - WS connection resulted into error`, { event });
11751
- this._reconnect();
11758
+ this._reconnectAfterFailure();
11752
11759
  };
11753
11760
  /**
11754
11761
  * _setHealth - Sets the connection to healthy or unhealthy.
@@ -11801,6 +11808,7 @@ var StableWSConnection = class {
11801
11808
  */
11802
11809
  this._setupConnectionPromise = () => {
11803
11810
  this.isResolved = false;
11811
+ this.tokenExpiredByServer = false;
11804
11812
  this.connectionOpen = new Promise((resolve, reject) => {
11805
11813
  this.resolvePromise = resolve;
11806
11814
  this.rejectPromise = reject;
@@ -11848,6 +11856,7 @@ var StableWSConnection = class {
11848
11856
  this.isHealthy = false;
11849
11857
  this.wsID = 1;
11850
11858
  this.lastEvent = null;
11859
+ this.tokenExpiredByServer = false;
11851
11860
  this.pingInterval = 25 * 1e3;
11852
11861
  this.connectionCheckTimeout = this.pingInterval + 10 * 1e3;
11853
11862
  addConnectionEventListeners(this.onlineStatusChanged);
@@ -11946,6 +11955,7 @@ var StableWSConnection = class {
11946
11955
  this.wsID += 1;
11947
11956
  this.isConnecting = false;
11948
11957
  this.isDisconnected = true;
11958
+ this.tokenExpiredByServer = false;
11949
11959
  if (this.healthCheckTimeoutRef) {
11950
11960
  clearInterval(this.healthCheckTimeoutRef);
11951
11961
  }
@@ -12078,6 +12088,10 @@ var StableWSConnection = class {
12078
12088
  this._destroyCurrentWSConnection();
12079
12089
  if (options.refreshToken) {
12080
12090
  await this.client.tokenManager.loadToken();
12091
+ if (this.isConnecting || this.isHealthy) {
12092
+ this._log("_reconnect() - Abort (4) since already connecting or healthy");
12093
+ return;
12094
+ }
12081
12095
  }
12082
12096
  try {
12083
12097
  await this._connect();
@@ -12101,6 +12115,21 @@ var StableWSConnection = class {
12101
12115
  }
12102
12116
  this._log("_reconnect() - == END ==");
12103
12117
  }
12118
+ /**
12119
+ * _reconnectAfterFailure - Reconnects after the socket closed or failed. If the server
12120
+ * reported that the token expired, the token is refreshed before reconnecting.
12121
+ * Static tokens cannot be refreshed and reconnect as before.
12122
+ */
12123
+ _reconnectAfterFailure() {
12124
+ if (this.tokenExpiredByServer && !this.client.tokenManager.isStatic()) {
12125
+ this._log(
12126
+ "_reconnectAfterFailure() - token expired, so going to reload token and reconnect"
12127
+ );
12128
+ this._reconnect({ refreshToken: true });
12129
+ return;
12130
+ }
12131
+ this._reconnect();
12132
+ }
12104
12133
  /**
12105
12134
  * _destroyCurrentWSConnection - Removes the current WS connection
12106
12135
  *
@@ -13463,7 +13492,15 @@ var Poll = class {
13463
13492
  if (!isPollUpdatedEvent(event)) return;
13464
13493
  const { id, ...pollData } = extractPollData(event.poll);
13465
13494
  if (pollData.is_closed) this.closeConfirmed = true;
13466
- this.state.partialNext({ ...pollData, lastActivityAt: new Date(event.created_at) });
13495
+ this.state.partialNext({
13496
+ ...pollData,
13497
+ // Server-owned translations, which `extractPollData` (an update request) leaves out. Copied
13498
+ // even when absent: the event carries the whole poll, and a change made under channel-only
13499
+ // translation drops the stale ones.
13500
+ description_i18n: event.poll.description_i18n,
13501
+ lastActivityAt: new Date(event.created_at),
13502
+ name_i18n: event.poll.name_i18n
13503
+ });
13467
13504
  this.upsertOfflineDb();
13468
13505
  };
13469
13506
  this.handlePollClosed = (event) => {
@@ -15456,7 +15493,7 @@ var StreamChat = class _StreamChat {
15456
15493
  return this.userAgent;
15457
15494
  }
15458
15495
  if (!this.cachedUserAgent) {
15459
- const version = "9.54.0";
15496
+ const version = "9.54.1";
15460
15497
  const { name: sdkName, version: sdkVersion } = this.sdkIdentifier ?? {};
15461
15498
  const { name: appName, version: appVersion } = this.appIdentifier ?? {};
15462
15499
  const { os, model: deviceModel } = this.deviceIdentifier ?? {};
@@ -17045,7 +17082,7 @@ var StreamChat = class _StreamChat {
17045
17082
  * @param {string} messageId
17046
17083
  * @param {string} language
17047
17084
  *
17048
- * @return {MessageResponse} Response that includes the message
17085
+ * @return {APIResponse & { message: MessageResponse }} Response that includes the translated message
17049
17086
  */
17050
17087
  async translateMessage(messageId, language) {
17051
17088
  return await this.post(