stream-chat 8.40.7 → 8.40.9

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.
@@ -388,18 +388,17 @@ var findIndexInSortedArray = function findIndexInSortedArray(_ref) {
388
388
  middle = Math.round((left + right) / 2);
389
389
  };
390
390
 
391
- var actualNeedle = selectValueToCompare(needle);
392
- recalculateMiddle();
391
+ var comparableNeedle = selectValueToCompare(needle);
393
392
 
394
393
  while (left <= right) {
395
- // if (actualNeedle === selectValueToCompare(sortedArray[middle])) return middle;
396
- if (sortDirection === 'ascending' && actualNeedle < selectValueToCompare(sortedArray[middle]) || sortDirection === 'descending' && actualNeedle > selectValueToCompare(sortedArray[middle])) {
394
+ recalculateMiddle();
395
+ var comparableMiddle = selectValueToCompare(sortedArray[middle]); // if (comparableNeedle === comparableMiddle) return middle;
396
+
397
+ if (sortDirection === 'ascending' && comparableNeedle < comparableMiddle || sortDirection === 'descending' && comparableNeedle > comparableMiddle) {
397
398
  right = middle - 1;
398
399
  } else {
399
400
  left = middle + 1;
400
401
  }
401
-
402
- recalculateMiddle();
403
402
  }
404
403
 
405
404
  return left;
@@ -441,7 +440,7 @@ function addToMessageList(messages, newMessage) {
441
440
 
442
441
  var insertionIndex = findIndexInSortedArray({
443
442
  needle: newMessage,
444
- sortedArray: messages,
443
+ sortedArray: newMessages,
445
444
  sortDirection: 'ascending',
446
445
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
447
446
  selectValueToCompare: function selectValueToCompare(m) {
@@ -7339,7 +7338,6 @@ var Thread = /*#__PURE__*/function () {
7339
7338
  function Thread(_ref) {
7340
7339
  var _this = this,
7341
7340
  _threadData$channel$m,
7342
- _threadData$read,
7343
7341
  _threadData$reply_cou;
7344
7342
 
7345
7343
  var client = _ref.client,
@@ -7467,7 +7465,7 @@ var Thread = /*#__PURE__*/function () {
7467
7465
 
7468
7466
  _this.unsubscribeFunctions.add(_this.subscribeRepliesRead());
7469
7467
 
7470
- _this.unsubscribeFunctions.add(_this.subscribeReplyDeleted());
7468
+ _this.unsubscribeFunctions.add(_this.subscribeMessageDeleted());
7471
7469
 
7472
7470
  _this.unsubscribeFunctions.add(_this.subscribeMessageUpdated());
7473
7471
  });
@@ -7599,19 +7597,26 @@ var Thread = /*#__PURE__*/function () {
7599
7597
  }).unsubscribe;
7600
7598
  });
7601
7599
 
7602
- _defineProperty(this, "subscribeReplyDeleted", function () {
7600
+ _defineProperty(this, "subscribeMessageDeleted", function () {
7603
7601
  return _this.client.on('message.deleted', function (event) {
7604
- var _event$message2;
7602
+ if (!event.message) return; // Deleted message is a reply of this thread
7603
+
7604
+ if (event.message.parent_id === _this.id) {
7605
+ if (event.hard_delete) {
7606
+ _this.deleteReplyLocally({
7607
+ message: event.message
7608
+ });
7609
+ } else {
7610
+ // Handle soft delete (updates deleted_at timestamp)
7611
+ _this.upsertReplyLocally({
7612
+ message: event.message
7613
+ });
7614
+ }
7615
+ } // Deleted message is parent message of this thread
7605
7616
 
7606
- if (((_event$message2 = event.message) === null || _event$message2 === void 0 ? void 0 : _event$message2.parent_id) !== _this.id) return;
7607
7617
 
7608
- if (event.hard_delete) {
7609
- _this.deleteReplyLocally({
7610
- message: event.message
7611
- });
7612
- } else {
7613
- // Handle soft delete (updates deleted_at timestamp)
7614
- _this.upsertReplyLocally({
7618
+ if (event.message.id === _this.id) {
7619
+ _this.updateParentMessageLocally({
7615
7620
  message: event.message
7616
7621
  });
7617
7622
  }
@@ -7619,7 +7624,8 @@ var Thread = /*#__PURE__*/function () {
7619
7624
  });
7620
7625
 
7621
7626
  _defineProperty(this, "subscribeMessageUpdated", function () {
7622
- var unsubscribeFunctions = ['message.updated', 'reaction.new', 'reaction.deleted'].map(function (eventType) {
7627
+ var eventTypes = ['message.updated', 'reaction.new', 'reaction.deleted', 'reaction.updated'];
7628
+ var unsubscribeFunctions = eventTypes.map(function (eventType) {
7623
7629
  return _this.client.on(eventType, function (event) {
7624
7630
  if (event.message) {
7625
7631
  _this.updateParentMessageOrReplyLocally(event.message);
@@ -7697,7 +7703,9 @@ var Thread = /*#__PURE__*/function () {
7697
7703
  });
7698
7704
  });
7699
7705
 
7700
- _defineProperty(this, "updateParentMessageLocally", function (message) {
7706
+ _defineProperty(this, "updateParentMessageLocally", function (_ref9) {
7707
+ var message = _ref9.message;
7708
+
7701
7709
  if (message.id !== _this.id) {
7702
7710
  throw new Error('Message does not belong to this thread');
7703
7711
  }
@@ -7706,19 +7714,11 @@ var Thread = /*#__PURE__*/function () {
7706
7714
  var _message$reply_count;
7707
7715
 
7708
7716
  var formattedMessage = formatMessage(message);
7709
-
7710
- var newData = _objectSpread$3(_objectSpread$3({}, current), {}, {
7717
+ return _objectSpread$3(_objectSpread$3({}, current), {}, {
7711
7718
  deletedAt: formattedMessage.deleted_at,
7712
7719
  parentMessage: formattedMessage,
7713
7720
  replyCount: (_message$reply_count = message.reply_count) !== null && _message$reply_count !== void 0 ? _message$reply_count : current.replyCount
7714
- }); // update channel on channelData change (unlikely but handled anyway)
7715
-
7716
-
7717
- if (message.channel) {
7718
- newData['channel'] = _this.client.channel(message.channel.type, message.channel.id, message.channel);
7719
- }
7720
-
7721
- return newData;
7721
+ });
7722
7722
  });
7723
7723
  });
7724
7724
 
@@ -7730,13 +7730,15 @@ var Thread = /*#__PURE__*/function () {
7730
7730
  }
7731
7731
 
7732
7732
  if (!message.parent_id && message.id === _this.id) {
7733
- _this.updateParentMessageLocally(message);
7733
+ _this.updateParentMessageLocally({
7734
+ message: message
7735
+ });
7734
7736
  }
7735
7737
  });
7736
7738
 
7737
7739
  _defineProperty(this, "markAsRead", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
7738
- var _ref10,
7739
- _ref10$force,
7740
+ var _ref11,
7741
+ _ref11$force,
7740
7742
  force,
7741
7743
  _args2 = arguments;
7742
7744
 
@@ -7744,7 +7746,7 @@ var Thread = /*#__PURE__*/function () {
7744
7746
  while (1) {
7745
7747
  switch (_context2.prev = _context2.next) {
7746
7748
  case 0:
7747
- _ref10 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref10$force = _ref10.force, force = _ref10$force === void 0 ? false : _ref10$force;
7749
+ _ref11 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref11$force = _ref11.force, force = _ref11$force === void 0 ? false : _ref11$force;
7748
7750
 
7749
7751
  if (!(_this.ownUnreadCount === 0 && !force)) {
7750
7752
  _context2.next = 3;
@@ -7777,13 +7779,13 @@ var Thread = /*#__PURE__*/function () {
7777
7779
  }));
7778
7780
 
7779
7781
  _defineProperty(this, "queryReplies", function () {
7780
- var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7782
+ var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7781
7783
 
7782
- var _ref11$limit = _ref11.limit,
7783
- limit = _ref11$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref11$limit,
7784
- _ref11$sort = _ref11.sort,
7785
- sort = _ref11$sort === void 0 ? DEFAULT_SORT : _ref11$sort,
7786
- otherOptions = _objectWithoutProperties(_ref11, _excluded$1);
7784
+ var _ref12$limit = _ref12.limit,
7785
+ limit = _ref12$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref12$limit,
7786
+ _ref12$sort = _ref12.sort,
7787
+ sort = _ref12$sort === void 0 ? DEFAULT_SORT : _ref12$sort,
7788
+ otherOptions = _objectWithoutProperties(_ref12, _excluded$1);
7787
7789
 
7788
7790
  return _this.channel.getReplies(_this.id, _objectSpread$3({
7789
7791
  limit: limit
@@ -7791,31 +7793,31 @@ var Thread = /*#__PURE__*/function () {
7791
7793
  });
7792
7794
 
7793
7795
  _defineProperty(this, "loadNextPage", function () {
7794
- var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7795
- _ref12$limit = _ref12.limit,
7796
- limit = _ref12$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref12$limit;
7796
+ var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7797
+ _ref13$limit = _ref13.limit,
7798
+ limit = _ref13$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref13$limit;
7797
7799
 
7798
7800
  return _this.loadPage(limit);
7799
7801
  });
7800
7802
 
7801
7803
  _defineProperty(this, "loadPrevPage", function () {
7802
- var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7803
- _ref13$limit = _ref13.limit,
7804
- limit = _ref13$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref13$limit;
7804
+ var _ref14 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7805
+ _ref14$limit = _ref14.limit,
7806
+ limit = _ref14$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref14$limit;
7805
7807
 
7806
7808
  return _this.loadPage(-limit);
7807
7809
  });
7808
7810
 
7809
7811
  _defineProperty(this, "loadPage", /*#__PURE__*/function () {
7810
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(count) {
7811
- var _this$state$getLatest4, pagination, _ref15, _ref16, loadingKey, cursorKey, insertionMethodKey, queryOptions, limit, _replies$at$id, _replies$at, data, replies, maybeNextCursor;
7812
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(count) {
7813
+ var _this$state$getLatest4, pagination, _ref16, _ref17, loadingKey, cursorKey, insertionMethodKey, queryOptions, limit, _replies$at$id, _replies$at, data, replies, maybeNextCursor;
7812
7814
 
7813
7815
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
7814
7816
  while (1) {
7815
7817
  switch (_context3.prev = _context3.next) {
7816
7818
  case 0:
7817
7819
  _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
7818
- _ref15 = count > 0 ? ['isLoadingNext', 'nextCursor', 'push'] : ['isLoadingPrev', 'prevCursor', 'unshift'], _ref16 = _slicedToArray(_ref15, 3), loadingKey = _ref16[0], cursorKey = _ref16[1], insertionMethodKey = _ref16[2];
7820
+ _ref16 = count > 0 ? ['isLoadingNext', 'nextCursor', 'push'] : ['isLoadingPrev', 'prevCursor', 'unshift'], _ref17 = _slicedToArray(_ref16, 3), loadingKey = _ref17[0], cursorKey = _ref17[1], insertionMethodKey = _ref17[2];
7819
7821
 
7820
7822
  if (!(pagination[loadingKey] || pagination[cursorKey] === null)) {
7821
7823
  _context3.next = 4;
@@ -7886,7 +7888,7 @@ var Thread = /*#__PURE__*/function () {
7886
7888
  }));
7887
7889
 
7888
7890
  return function (_x) {
7889
- return _ref14.apply(this, arguments);
7891
+ return _ref15.apply(this, arguments);
7890
7892
  };
7891
7893
  }());
7892
7894
 
@@ -7894,8 +7896,17 @@ var Thread = /*#__PURE__*/function () {
7894
7896
  name: threadData.channel.name
7895
7897
  });
7896
7898
 
7897
- _channel._hydrateMembers((_threadData$channel$m = threadData.channel.members) !== null && _threadData$channel$m !== void 0 ? _threadData$channel$m : []);
7899
+ _channel._hydrateMembers((_threadData$channel$m = threadData.channel.members) !== null && _threadData$channel$m !== void 0 ? _threadData$channel$m : []); // For when read object is undefined and due to that unreadMessageCount for
7900
+ // the current user isn't being incremented on message.new
7898
7901
 
7902
+
7903
+ var placeholderReadResponse = client.userID ? [{
7904
+ user: {
7905
+ id: client.userID
7906
+ },
7907
+ unread_messages: 0,
7908
+ last_read: new Date().toISOString()
7909
+ }] : [];
7899
7910
  this.state = new StateStore({
7900
7911
  active: false,
7901
7912
  channel: _channel,
@@ -7906,7 +7917,7 @@ var Thread = /*#__PURE__*/function () {
7906
7917
  pagination: repliesPaginationFromInitialThread(threadData),
7907
7918
  parentMessage: formatMessage(threadData.parent_message),
7908
7919
  participants: threadData.thread_participants,
7909
- read: formatReadState((_threadData$read = threadData.read) !== null && _threadData$read !== void 0 ? _threadData$read : []),
7920
+ read: formatReadState(!threadData.read || threadData.read.length === 0 ? placeholderReadResponse : threadData.read),
7910
7921
  replies: threadData.latest_replies.map(formatMessage),
7911
7922
  replyCount: (_threadData$reply_cou = threadData.reply_count) !== null && _threadData$reply_cou !== void 0 ? _threadData$reply_cou : 0,
7912
7923
  updatedAt: threadData.updated_at ? new Date(threadData.updated_at) : null
@@ -13330,7 +13341,7 @@ var StreamChat = /*#__PURE__*/function () {
13330
13341
  }, {
13331
13342
  key: "getUserAgent",
13332
13343
  value: function getUserAgent() {
13333
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.40.7");
13344
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.40.9");
13334
13345
  }
13335
13346
  }, {
13336
13347
  key: "setUserAgent",