stream-chat 8.51.0 → 8.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.
@@ -1,16 +1,19 @@
1
1
  import { UserResponse, ExtendableGenerics, DefaultGenerics } from './types';
2
+ import { StreamChat } from './client';
2
3
 
3
4
  /**
4
5
  * ClientState - A container class for the client state.
5
6
  */
6
7
  export class ClientState<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
8
+ private client: StreamChat<StreamChatGenerics>;
7
9
  users: {
8
10
  [key: string]: UserResponse<StreamChatGenerics>;
9
11
  };
10
12
  userChannelReferences: { [key: string]: { [key: string]: boolean } };
11
- constructor() {
13
+ constructor({ client }: { client: StreamChat<StreamChatGenerics> }) {
12
14
  // show the status for a certain user...
13
15
  // ie online, offline etc
16
+ this.client = client;
14
17
  this.users = {};
15
18
  // store which channels contain references to the specified user...
16
19
  this.userChannelReferences = {};
@@ -23,13 +26,13 @@ export class ClientState<StreamChatGenerics extends ExtendableGenerics = Default
23
26
  }
24
27
 
25
28
  updateUser(user?: UserResponse<StreamChatGenerics>) {
26
- if (user != null) {
29
+ if (user != null && this.client._cacheEnabled()) {
27
30
  this.users[user.id] = user;
28
31
  }
29
32
  }
30
33
 
31
34
  updateUserReference(user: UserResponse<StreamChatGenerics>, channelID: string) {
32
- if (user == null) {
35
+ if (user == null || !this.client._cacheEnabled()) {
33
36
  return;
34
37
  }
35
38
  this.updateUser(user);
@@ -101,6 +101,9 @@ export class PollManager<SCG extends ExtendableGenerics = DefaultGenerics> {
101
101
  };
102
102
 
103
103
  private setOrOverwriteInCache = (pollResponse: PollResponse<SCG>, overwriteState?: boolean) => {
104
+ if (!this.client._cacheEnabled()) {
105
+ return;
106
+ }
104
107
  const pollFromCache = this.fromState(pollResponse.id);
105
108
  if (!pollFromCache) {
106
109
  const poll = new Poll<SCG>({ client: this.client, poll: pollResponse });
package/src/types.ts CHANGED
@@ -77,6 +77,11 @@ export type APIResponse = {
77
77
  duration: string;
78
78
  };
79
79
 
80
+ export type TranslateResponse = {
81
+ language: string;
82
+ translated_text: string;
83
+ };
84
+
80
85
  export type AppSettingsAPIResponse<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> = APIResponse & {
81
86
  app?: {
82
87
  // TODO
@@ -1176,6 +1181,15 @@ export type StreamChatOptions = AxiosRequestConfig & {
1176
1181
  baseURL?: string;
1177
1182
  browser?: boolean;
1178
1183
  device?: BaseDeviceFields;
1184
+ /**
1185
+ * Disables the hydration of all caches within the JS Client. This includes this.activeChannels,
1186
+ * this.polls.pollCache and this.config.
1187
+ * It is mainly meant to be used for integrations where stream-chat is used as a server-side service
1188
+ * interacting with Stream's REST API, not depending on any state and purely serving as a wrapper
1189
+ * around HTTP requests. Using this property on either the client side or a backend implementation
1190
+ * that also relies on WS events will break these functionalities, so please use carefully.
1191
+ */
1192
+ disableCache?: boolean;
1179
1193
  enableInsights?: boolean;
1180
1194
  /** experimental feature, please contact support if you want this feature enabled for you */
1181
1195
  enableWSFallback?: boolean;
@@ -1198,8 +1212,10 @@ export type StreamChatOptions = AxiosRequestConfig & {
1198
1212
  */
1199
1213
  recoverStateOnReconnect?: boolean;
1200
1214
  warmUp?: boolean;
1201
- // Set the instance of StableWSConnection on chat client. Its purely for testing purpose and should
1202
- // not be used in production apps.
1215
+ /**
1216
+ * Set the instance of StableWSConnection on chat client. Its purely for testing purpose and should
1217
+ * not be used in production apps.
1218
+ */
1203
1219
  wsConnection?: StableWSConnection;
1204
1220
  };
1205
1221