stream-chat 9.22.0 → 9.23.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.
@@ -30,6 +30,12 @@ var require_https = __commonJS({
30
30
  }
31
31
  });
32
32
 
33
+ // (disabled):node_modules/jsonwebtoken/index.js
34
+ var require_jsonwebtoken = __commonJS({
35
+ "(disabled):node_modules/jsonwebtoken/index.js"() {
36
+ }
37
+ });
38
+
33
39
  // (disabled):crypto
34
40
  var require_crypto = __commonJS({
35
41
  "(disabled):crypto"() {
@@ -152,11 +158,14 @@ import FormData from "form-data";
152
158
  // src/constants.ts
153
159
  var DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE = 25;
154
160
  var DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE = 100;
155
- var DEFAULT_MESSAGE_SET_PAGINATION = { hasNext: false, hasPrev: false };
161
+ var DEFAULT_MESSAGE_SET_PAGINATION = Object.freeze({
162
+ hasNext: false,
163
+ hasPrev: false
164
+ });
156
165
  var DEFAULT_UPLOAD_SIZE_LIMIT_BYTES = 100 * 1024 * 1024;
157
166
  var API_MAX_FILES_ALLOWED_PER_MESSAGE = 10;
158
167
  var MAX_CHANNEL_MEMBER_COUNT_IN_CHANNEL_QUERY = 100;
159
- var RESERVED_UPDATED_MESSAGE_FIELDS = {
168
+ var RESERVED_UPDATED_MESSAGE_FIELDS = Object.freeze({
160
169
  // Dates should not be converted back to ISO strings as JS looses precision on them (milliseconds)
161
170
  created_at: true,
162
171
  deleted_at: true,
@@ -177,8 +186,8 @@ var RESERVED_UPDATED_MESSAGE_FIELDS = {
177
186
  html: true,
178
187
  __html: true,
179
188
  user: true
180
- };
181
- var LOCAL_MESSAGE_FIELDS = { error: true };
189
+ });
190
+ var LOCAL_MESSAGE_FIELDS = Object.freeze({ error: true });
182
191
  var DEFAULT_QUERY_CHANNELS_RETRY_COUNT = 3;
183
192
  var DEFAULT_QUERY_CHANNELS_MS_BETWEEN_RETRIES = 1e3;
184
193
 
@@ -1114,6 +1123,14 @@ var ChannelState = class {
1114
1123
  get messagePagination() {
1115
1124
  return this.messageSets.find((s) => s.isCurrent)?.pagination || DEFAULT_MESSAGE_SET_PAGINATION;
1116
1125
  }
1126
+ pruneOldest(maxMessages) {
1127
+ const currentIndex = this.messageSets.findIndex((s) => s.isCurrent);
1128
+ if (this.messageSets[currentIndex].isLatest) {
1129
+ const newMessages = this.messageSets[currentIndex].messages;
1130
+ this.messageSets[currentIndex].messages = newMessages.slice(-maxMessages);
1131
+ this.messageSets[currentIndex].pagination.hasPrev = true;
1132
+ }
1133
+ }
1117
1134
  /**
1118
1135
  * addMessageSorted - Add a message to the state
1119
1136
  *
@@ -1534,7 +1551,7 @@ var ChannelState = class {
1534
1551
  messages: [],
1535
1552
  isLatest: true,
1536
1553
  isCurrent: true,
1537
- pagination: DEFAULT_MESSAGE_SET_PAGINATION
1554
+ pagination: { ...DEFAULT_MESSAGE_SET_PAGINATION }
1538
1555
  }
1539
1556
  ];
1540
1557
  }
@@ -1668,7 +1685,7 @@ var ChannelState = class {
1668
1685
  messages: [],
1669
1686
  isCurrent: false,
1670
1687
  isLatest: false,
1671
- pagination: DEFAULT_MESSAGE_SET_PAGINATION
1688
+ pagination: { ...DEFAULT_MESSAGE_SET_PAGINATION }
1672
1689
  });
1673
1690
  targetMessageSetIndex = this.messageSets.length - 1;
1674
1691
  } else {
@@ -1677,7 +1694,7 @@ var ChannelState = class {
1677
1694
  messages: [],
1678
1695
  isCurrent: false,
1679
1696
  isLatest,
1680
- pagination: DEFAULT_MESSAGE_SET_PAGINATION
1697
+ pagination: { ...DEFAULT_MESSAGE_SET_PAGINATION }
1681
1698
  // fixme: it is problematic decide about pagination without having data
1682
1699
  });
1683
1700
  if (isLatest) {
@@ -5388,6 +5405,13 @@ var MentionsSearchSource = class extends BaseSearchSource {
5388
5405
  const { mentionAllAppUsers, textComposerText, transliterate, ...restOptions } = options || {};
5389
5406
  super(restOptions);
5390
5407
  this.type = "mentions";
5408
+ this.toUserSuggestion = (user) => ({
5409
+ ...user,
5410
+ ...getTokenizedSuggestionDisplayName({
5411
+ displayName: user.name || user.id,
5412
+ searchToken: this.searchQuery
5413
+ })
5414
+ });
5391
5415
  this.canExecuteQuery = (newSearchString) => {
5392
5416
  const hasNewSearchQuery = typeof newSearchString !== "undefined";
5393
5417
  return this.isActive && !this.isLoading && (hasNewSearchQuery || this.hasNext);
@@ -5527,15 +5551,7 @@ var MentionsSearchSource = class extends BaseSearchSource {
5527
5551
  users = await this.queryMembers(searchQuery);
5528
5552
  }
5529
5553
  return {
5530
- items: users.map(
5531
- (user) => ({
5532
- ...user,
5533
- ...getTokenizedSuggestionDisplayName({
5534
- displayName: user.name || user.id,
5535
- searchToken: this.searchQuery
5536
- })
5537
- })
5538
- )
5554
+ items: users.map(this.toUserSuggestion)
5539
5555
  };
5540
5556
  }
5541
5557
  filterQueryResults(items) {
@@ -9866,8 +9882,8 @@ var StableWSConnection = class {
9866
9882
  };
9867
9883
 
9868
9884
  // src/signing.ts
9885
+ var import_jsonwebtoken = __toESM(require_jsonwebtoken());
9869
9886
  var import_crypto = __toESM(require_crypto());
9870
- import jwt from "jsonwebtoken";
9871
9887
  function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
9872
9888
  if (typeof userId !== "string") {
9873
9889
  throw new TypeError("userId should be a string");
@@ -9876,7 +9892,7 @@ function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
9876
9892
  user_id: userId,
9877
9893
  ...extraData
9878
9894
  };
9879
- if (jwt == null || jwt.sign == null) {
9895
+ if (import_jsonwebtoken.default == null || import_jsonwebtoken.default.sign == null) {
9880
9896
  throw Error(
9881
9897
  `Unable to find jwt crypto, if you are getting this error is probably because you are trying to generate tokens on browser or React Native (or other environment where crypto functions are not available). Please Note: token should only be generated server-side.`
9882
9898
  );
@@ -9888,7 +9904,7 @@ function JWTUserToken(apiSecret, userId, extraData = {}, jwtOptions = {}) {
9888
9904
  if (payload.iat) {
9889
9905
  opts.noTimestamp = false;
9890
9906
  }
9891
- return jwt.sign(payload, apiSecret, opts);
9907
+ return import_jsonwebtoken.default.sign(payload, apiSecret, opts);
9892
9908
  }
9893
9909
  function JWTServerToken(apiSecret, jwtOptions = {}) {
9894
9910
  const payload = {
@@ -9898,7 +9914,7 @@ function JWTServerToken(apiSecret, jwtOptions = {}) {
9898
9914
  { algorithm: "HS256", noTimestamp: true },
9899
9915
  jwtOptions
9900
9916
  );
9901
- return jwt.sign(payload, apiSecret, opts);
9917
+ return import_jsonwebtoken.default.sign(payload, apiSecret, opts);
9902
9918
  }
9903
9919
  function UserFromToken(token) {
9904
9920
  const fragments = token.split(".");
@@ -14265,7 +14281,10 @@ var StreamChat = class _StreamChat {
14265
14281
  if (options.hardDelete) {
14266
14282
  await this.offlineDb.hardDeleteMessage({ id: messageID });
14267
14283
  } else {
14268
- await this.offlineDb.softDeleteMessage({ id: messageID });
14284
+ await this.offlineDb.softDeleteMessage({
14285
+ id: messageID,
14286
+ deleteForMe: options.deleteForMe
14287
+ });
14269
14288
  }
14270
14289
  return await this.offlineDb.queueTask(
14271
14290
  {
@@ -14439,7 +14458,7 @@ var StreamChat = class _StreamChat {
14439
14458
  if (this.userAgent) {
14440
14459
  return this.userAgent;
14441
14460
  }
14442
- const version = "9.22.0";
14461
+ const version = "9.23.0";
14443
14462
  const clientBundle = "browser-esm";
14444
14463
  let userAgentString = "";
14445
14464
  if (this.sdkIdentifier) {
@@ -16089,12 +16108,16 @@ var AbstractOfflineDB = class {
16089
16108
  event,
16090
16109
  execute = true
16091
16110
  }) => {
16092
- const { message, hard_delete = false } = event;
16111
+ const { message, deleted_for_me, hard_delete = false } = event;
16093
16112
  if (message) {
16094
16113
  const deleteMethod = hard_delete ? this.hardDeleteMessage : this.softDeleteMessage;
16095
16114
  return await this.queriesWithChannelGuard(
16096
16115
  { event, execute },
16097
- async (executeOverride) => await deleteMethod({ id: message.id, execute: executeOverride })
16116
+ async (executeOverride) => await deleteMethod({
16117
+ id: message.id,
16118
+ deleteForMe: deleted_for_me,
16119
+ execute: executeOverride
16120
+ })
16098
16121
  );
16099
16122
  }
16100
16123
  return [];