stream-chat 9.22.1 → 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.
@@ -318,11 +318,14 @@ var import_form_data = __toESM(require("form-data"));
318
318
  // src/constants.ts
319
319
  var DEFAULT_QUERY_CHANNELS_MESSAGE_LIST_PAGE_SIZE = 25;
320
320
  var DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE = 100;
321
- var DEFAULT_MESSAGE_SET_PAGINATION = { hasNext: false, hasPrev: false };
321
+ var DEFAULT_MESSAGE_SET_PAGINATION = Object.freeze({
322
+ hasNext: false,
323
+ hasPrev: false
324
+ });
322
325
  var DEFAULT_UPLOAD_SIZE_LIMIT_BYTES = 100 * 1024 * 1024;
323
326
  var API_MAX_FILES_ALLOWED_PER_MESSAGE = 10;
324
327
  var MAX_CHANNEL_MEMBER_COUNT_IN_CHANNEL_QUERY = 100;
325
- var RESERVED_UPDATED_MESSAGE_FIELDS = {
328
+ var RESERVED_UPDATED_MESSAGE_FIELDS = Object.freeze({
326
329
  // Dates should not be converted back to ISO strings as JS looses precision on them (milliseconds)
327
330
  created_at: true,
328
331
  deleted_at: true,
@@ -343,8 +346,8 @@ var RESERVED_UPDATED_MESSAGE_FIELDS = {
343
346
  html: true,
344
347
  __html: true,
345
348
  user: true
346
- };
347
- var LOCAL_MESSAGE_FIELDS = { error: true };
349
+ });
350
+ var LOCAL_MESSAGE_FIELDS = Object.freeze({ error: true });
348
351
  var DEFAULT_QUERY_CHANNELS_RETRY_COUNT = 3;
349
352
  var DEFAULT_QUERY_CHANNELS_MS_BETWEEN_RETRIES = 1e3;
350
353
 
@@ -1280,6 +1283,14 @@ var ChannelState = class {
1280
1283
  get messagePagination() {
1281
1284
  return this.messageSets.find((s) => s.isCurrent)?.pagination || DEFAULT_MESSAGE_SET_PAGINATION;
1282
1285
  }
1286
+ pruneOldest(maxMessages) {
1287
+ const currentIndex = this.messageSets.findIndex((s) => s.isCurrent);
1288
+ if (this.messageSets[currentIndex].isLatest) {
1289
+ const newMessages = this.messageSets[currentIndex].messages;
1290
+ this.messageSets[currentIndex].messages = newMessages.slice(-maxMessages);
1291
+ this.messageSets[currentIndex].pagination.hasPrev = true;
1292
+ }
1293
+ }
1283
1294
  /**
1284
1295
  * addMessageSorted - Add a message to the state
1285
1296
  *
@@ -1700,7 +1711,7 @@ var ChannelState = class {
1700
1711
  messages: [],
1701
1712
  isLatest: true,
1702
1713
  isCurrent: true,
1703
- pagination: DEFAULT_MESSAGE_SET_PAGINATION
1714
+ pagination: { ...DEFAULT_MESSAGE_SET_PAGINATION }
1704
1715
  }
1705
1716
  ];
1706
1717
  }
@@ -1834,7 +1845,7 @@ var ChannelState = class {
1834
1845
  messages: [],
1835
1846
  isCurrent: false,
1836
1847
  isLatest: false,
1837
- pagination: DEFAULT_MESSAGE_SET_PAGINATION
1848
+ pagination: { ...DEFAULT_MESSAGE_SET_PAGINATION }
1838
1849
  });
1839
1850
  targetMessageSetIndex = this.messageSets.length - 1;
1840
1851
  } else {
@@ -1843,7 +1854,7 @@ var ChannelState = class {
1843
1854
  messages: [],
1844
1855
  isCurrent: false,
1845
1856
  isLatest,
1846
- pagination: DEFAULT_MESSAGE_SET_PAGINATION
1857
+ pagination: { ...DEFAULT_MESSAGE_SET_PAGINATION }
1847
1858
  // fixme: it is problematic decide about pagination without having data
1848
1859
  });
1849
1860
  if (isLatest) {
@@ -5554,6 +5565,13 @@ var MentionsSearchSource = class extends BaseSearchSource {
5554
5565
  const { mentionAllAppUsers, textComposerText, transliterate, ...restOptions } = options || {};
5555
5566
  super(restOptions);
5556
5567
  this.type = "mentions";
5568
+ this.toUserSuggestion = (user) => ({
5569
+ ...user,
5570
+ ...getTokenizedSuggestionDisplayName({
5571
+ displayName: user.name || user.id,
5572
+ searchToken: this.searchQuery
5573
+ })
5574
+ });
5557
5575
  this.canExecuteQuery = (newSearchString) => {
5558
5576
  const hasNewSearchQuery = typeof newSearchString !== "undefined";
5559
5577
  return this.isActive && !this.isLoading && (hasNewSearchQuery || this.hasNext);
@@ -5693,15 +5711,7 @@ var MentionsSearchSource = class extends BaseSearchSource {
5693
5711
  users = await this.queryMembers(searchQuery);
5694
5712
  }
5695
5713
  return {
5696
- items: users.map(
5697
- (user) => ({
5698
- ...user,
5699
- ...getTokenizedSuggestionDisplayName({
5700
- displayName: user.name || user.id,
5701
- searchToken: this.searchQuery
5702
- })
5703
- })
5704
- )
5714
+ items: users.map(this.toUserSuggestion)
5705
5715
  };
5706
5716
  }
5707
5717
  filterQueryResults(items) {
@@ -14431,7 +14441,10 @@ var StreamChat = class _StreamChat {
14431
14441
  if (options.hardDelete) {
14432
14442
  await this.offlineDb.hardDeleteMessage({ id: messageID });
14433
14443
  } else {
14434
- await this.offlineDb.softDeleteMessage({ id: messageID });
14444
+ await this.offlineDb.softDeleteMessage({
14445
+ id: messageID,
14446
+ deleteForMe: options.deleteForMe
14447
+ });
14435
14448
  }
14436
14449
  return await this.offlineDb.queueTask(
14437
14450
  {
@@ -14605,7 +14618,7 @@ var StreamChat = class _StreamChat {
14605
14618
  if (this.userAgent) {
14606
14619
  return this.userAgent;
14607
14620
  }
14608
- const version = "9.22.1";
14621
+ const version = "9.23.0";
14609
14622
  const clientBundle = "node-cjs";
14610
14623
  let userAgentString = "";
14611
14624
  if (this.sdkIdentifier) {
@@ -16255,12 +16268,16 @@ var AbstractOfflineDB = class {
16255
16268
  event,
16256
16269
  execute = true
16257
16270
  }) => {
16258
- const { message, hard_delete = false } = event;
16271
+ const { message, deleted_for_me, hard_delete = false } = event;
16259
16272
  if (message) {
16260
16273
  const deleteMethod = hard_delete ? this.hardDeleteMessage : this.softDeleteMessage;
16261
16274
  return await this.queriesWithChannelGuard(
16262
16275
  { event, execute },
16263
- async (executeOverride) => await deleteMethod({ id: message.id, execute: executeOverride })
16276
+ async (executeOverride) => await deleteMethod({
16277
+ id: message.id,
16278
+ deleteForMe: deleted_for_me,
16279
+ execute: executeOverride
16280
+ })
16264
16281
  );
16265
16282
  }
16266
16283
  return [];