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.
package/dist/index.js CHANGED
@@ -417,18 +417,17 @@ var findIndexInSortedArray = function findIndexInSortedArray(_ref) {
417
417
  middle = Math.round((left + right) / 2);
418
418
  };
419
419
 
420
- var actualNeedle = selectValueToCompare(needle);
421
- recalculateMiddle();
420
+ var comparableNeedle = selectValueToCompare(needle);
422
421
 
423
422
  while (left <= right) {
424
- // if (actualNeedle === selectValueToCompare(sortedArray[middle])) return middle;
425
- if (sortDirection === 'ascending' && actualNeedle < selectValueToCompare(sortedArray[middle]) || sortDirection === 'descending' && actualNeedle > selectValueToCompare(sortedArray[middle])) {
423
+ recalculateMiddle();
424
+ var comparableMiddle = selectValueToCompare(sortedArray[middle]); // if (comparableNeedle === comparableMiddle) return middle;
425
+
426
+ if (sortDirection === 'ascending' && comparableNeedle < comparableMiddle || sortDirection === 'descending' && comparableNeedle > comparableMiddle) {
426
427
  right = middle - 1;
427
428
  } else {
428
429
  left = middle + 1;
429
430
  }
430
-
431
- recalculateMiddle();
432
431
  }
433
432
 
434
433
  return left;
@@ -470,7 +469,7 @@ function addToMessageList(messages, newMessage) {
470
469
 
471
470
  var insertionIndex = findIndexInSortedArray({
472
471
  needle: newMessage,
473
- sortedArray: messages,
472
+ sortedArray: newMessages,
474
473
  sortDirection: 'ascending',
475
474
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
476
475
  selectValueToCompare: function selectValueToCompare(m) {
@@ -7370,7 +7369,6 @@ var Thread = /*#__PURE__*/function () {
7370
7369
  function Thread(_ref) {
7371
7370
  var _this = this,
7372
7371
  _threadData$channel$m,
7373
- _threadData$read,
7374
7372
  _threadData$reply_cou;
7375
7373
 
7376
7374
  var client = _ref.client,
@@ -7498,7 +7496,7 @@ var Thread = /*#__PURE__*/function () {
7498
7496
 
7499
7497
  _this.unsubscribeFunctions.add(_this.subscribeRepliesRead());
7500
7498
 
7501
- _this.unsubscribeFunctions.add(_this.subscribeReplyDeleted());
7499
+ _this.unsubscribeFunctions.add(_this.subscribeMessageDeleted());
7502
7500
 
7503
7501
  _this.unsubscribeFunctions.add(_this.subscribeMessageUpdated());
7504
7502
  });
@@ -7630,19 +7628,26 @@ var Thread = /*#__PURE__*/function () {
7630
7628
  }).unsubscribe;
7631
7629
  });
7632
7630
 
7633
- _defineProperty__default['default'](this, "subscribeReplyDeleted", function () {
7631
+ _defineProperty__default['default'](this, "subscribeMessageDeleted", function () {
7634
7632
  return _this.client.on('message.deleted', function (event) {
7635
- var _event$message2;
7633
+ if (!event.message) return; // Deleted message is a reply of this thread
7634
+
7635
+ if (event.message.parent_id === _this.id) {
7636
+ if (event.hard_delete) {
7637
+ _this.deleteReplyLocally({
7638
+ message: event.message
7639
+ });
7640
+ } else {
7641
+ // Handle soft delete (updates deleted_at timestamp)
7642
+ _this.upsertReplyLocally({
7643
+ message: event.message
7644
+ });
7645
+ }
7646
+ } // Deleted message is parent message of this thread
7636
7647
 
7637
- if (((_event$message2 = event.message) === null || _event$message2 === void 0 ? void 0 : _event$message2.parent_id) !== _this.id) return;
7638
7648
 
7639
- if (event.hard_delete) {
7640
- _this.deleteReplyLocally({
7641
- message: event.message
7642
- });
7643
- } else {
7644
- // Handle soft delete (updates deleted_at timestamp)
7645
- _this.upsertReplyLocally({
7649
+ if (event.message.id === _this.id) {
7650
+ _this.updateParentMessageLocally({
7646
7651
  message: event.message
7647
7652
  });
7648
7653
  }
@@ -7650,7 +7655,8 @@ var Thread = /*#__PURE__*/function () {
7650
7655
  });
7651
7656
 
7652
7657
  _defineProperty__default['default'](this, "subscribeMessageUpdated", function () {
7653
- var unsubscribeFunctions = ['message.updated', 'reaction.new', 'reaction.deleted'].map(function (eventType) {
7658
+ var eventTypes = ['message.updated', 'reaction.new', 'reaction.deleted', 'reaction.updated'];
7659
+ var unsubscribeFunctions = eventTypes.map(function (eventType) {
7654
7660
  return _this.client.on(eventType, function (event) {
7655
7661
  if (event.message) {
7656
7662
  _this.updateParentMessageOrReplyLocally(event.message);
@@ -7728,7 +7734,9 @@ var Thread = /*#__PURE__*/function () {
7728
7734
  });
7729
7735
  });
7730
7736
 
7731
- _defineProperty__default['default'](this, "updateParentMessageLocally", function (message) {
7737
+ _defineProperty__default['default'](this, "updateParentMessageLocally", function (_ref9) {
7738
+ var message = _ref9.message;
7739
+
7732
7740
  if (message.id !== _this.id) {
7733
7741
  throw new Error('Message does not belong to this thread');
7734
7742
  }
@@ -7737,19 +7745,11 @@ var Thread = /*#__PURE__*/function () {
7737
7745
  var _message$reply_count;
7738
7746
 
7739
7747
  var formattedMessage = formatMessage(message);
7740
-
7741
- var newData = _objectSpread$3(_objectSpread$3({}, current), {}, {
7748
+ return _objectSpread$3(_objectSpread$3({}, current), {}, {
7742
7749
  deletedAt: formattedMessage.deleted_at,
7743
7750
  parentMessage: formattedMessage,
7744
7751
  replyCount: (_message$reply_count = message.reply_count) !== null && _message$reply_count !== void 0 ? _message$reply_count : current.replyCount
7745
- }); // update channel on channelData change (unlikely but handled anyway)
7746
-
7747
-
7748
- if (message.channel) {
7749
- newData['channel'] = _this.client.channel(message.channel.type, message.channel.id, message.channel);
7750
- }
7751
-
7752
- return newData;
7752
+ });
7753
7753
  });
7754
7754
  });
7755
7755
 
@@ -7761,13 +7761,15 @@ var Thread = /*#__PURE__*/function () {
7761
7761
  }
7762
7762
 
7763
7763
  if (!message.parent_id && message.id === _this.id) {
7764
- _this.updateParentMessageLocally(message);
7764
+ _this.updateParentMessageLocally({
7765
+ message: message
7766
+ });
7765
7767
  }
7766
7768
  });
7767
7769
 
7768
7770
  _defineProperty__default['default'](this, "markAsRead", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
7769
- var _ref10,
7770
- _ref10$force,
7771
+ var _ref11,
7772
+ _ref11$force,
7771
7773
  force,
7772
7774
  _args2 = arguments;
7773
7775
 
@@ -7775,7 +7777,7 @@ var Thread = /*#__PURE__*/function () {
7775
7777
  while (1) {
7776
7778
  switch (_context2.prev = _context2.next) {
7777
7779
  case 0:
7778
- _ref10 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref10$force = _ref10.force, force = _ref10$force === void 0 ? false : _ref10$force;
7780
+ _ref11 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref11$force = _ref11.force, force = _ref11$force === void 0 ? false : _ref11$force;
7779
7781
 
7780
7782
  if (!(_this.ownUnreadCount === 0 && !force)) {
7781
7783
  _context2.next = 3;
@@ -7808,13 +7810,13 @@ var Thread = /*#__PURE__*/function () {
7808
7810
  }));
7809
7811
 
7810
7812
  _defineProperty__default['default'](this, "queryReplies", function () {
7811
- var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7813
+ var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7812
7814
 
7813
- var _ref11$limit = _ref11.limit,
7814
- limit = _ref11$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref11$limit,
7815
- _ref11$sort = _ref11.sort,
7816
- sort = _ref11$sort === void 0 ? DEFAULT_SORT : _ref11$sort,
7817
- otherOptions = _objectWithoutProperties__default['default'](_ref11, _excluded$1);
7815
+ var _ref12$limit = _ref12.limit,
7816
+ limit = _ref12$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref12$limit,
7817
+ _ref12$sort = _ref12.sort,
7818
+ sort = _ref12$sort === void 0 ? DEFAULT_SORT : _ref12$sort,
7819
+ otherOptions = _objectWithoutProperties__default['default'](_ref12, _excluded$1);
7818
7820
 
7819
7821
  return _this.channel.getReplies(_this.id, _objectSpread$3({
7820
7822
  limit: limit
@@ -7822,31 +7824,31 @@ var Thread = /*#__PURE__*/function () {
7822
7824
  });
7823
7825
 
7824
7826
  _defineProperty__default['default'](this, "loadNextPage", function () {
7825
- var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7826
- _ref12$limit = _ref12.limit,
7827
- limit = _ref12$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref12$limit;
7827
+ var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7828
+ _ref13$limit = _ref13.limit,
7829
+ limit = _ref13$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref13$limit;
7828
7830
 
7829
7831
  return _this.loadPage(limit);
7830
7832
  });
7831
7833
 
7832
7834
  _defineProperty__default['default'](this, "loadPrevPage", function () {
7833
- var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7834
- _ref13$limit = _ref13.limit,
7835
- limit = _ref13$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref13$limit;
7835
+ var _ref14 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7836
+ _ref14$limit = _ref14.limit,
7837
+ limit = _ref14$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref14$limit;
7836
7838
 
7837
7839
  return _this.loadPage(-limit);
7838
7840
  });
7839
7841
 
7840
7842
  _defineProperty__default['default'](this, "loadPage", /*#__PURE__*/function () {
7841
- var _ref14 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(count) {
7842
- var _this$state$getLatest4, pagination, _ref15, _ref16, loadingKey, cursorKey, insertionMethodKey, queryOptions, limit, _replies$at$id, _replies$at, data, replies, maybeNextCursor;
7843
+ var _ref15 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(count) {
7844
+ var _this$state$getLatest4, pagination, _ref16, _ref17, loadingKey, cursorKey, insertionMethodKey, queryOptions, limit, _replies$at$id, _replies$at, data, replies, maybeNextCursor;
7843
7845
 
7844
7846
  return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
7845
7847
  while (1) {
7846
7848
  switch (_context3.prev = _context3.next) {
7847
7849
  case 0:
7848
7850
  _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
7849
- _ref15 = count > 0 ? ['isLoadingNext', 'nextCursor', 'push'] : ['isLoadingPrev', 'prevCursor', 'unshift'], _ref16 = _slicedToArray__default['default'](_ref15, 3), loadingKey = _ref16[0], cursorKey = _ref16[1], insertionMethodKey = _ref16[2];
7851
+ _ref16 = count > 0 ? ['isLoadingNext', 'nextCursor', 'push'] : ['isLoadingPrev', 'prevCursor', 'unshift'], _ref17 = _slicedToArray__default['default'](_ref16, 3), loadingKey = _ref17[0], cursorKey = _ref17[1], insertionMethodKey = _ref17[2];
7850
7852
 
7851
7853
  if (!(pagination[loadingKey] || pagination[cursorKey] === null)) {
7852
7854
  _context3.next = 4;
@@ -7917,7 +7919,7 @@ var Thread = /*#__PURE__*/function () {
7917
7919
  }));
7918
7920
 
7919
7921
  return function (_x) {
7920
- return _ref14.apply(this, arguments);
7922
+ return _ref15.apply(this, arguments);
7921
7923
  };
7922
7924
  }());
7923
7925
 
@@ -7925,8 +7927,17 @@ var Thread = /*#__PURE__*/function () {
7925
7927
  name: threadData.channel.name
7926
7928
  });
7927
7929
 
7928
- _channel._hydrateMembers((_threadData$channel$m = threadData.channel.members) !== null && _threadData$channel$m !== void 0 ? _threadData$channel$m : []);
7930
+ _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
7931
+ // the current user isn't being incremented on message.new
7929
7932
 
7933
+
7934
+ var placeholderReadResponse = client.userID ? [{
7935
+ user: {
7936
+ id: client.userID
7937
+ },
7938
+ unread_messages: 0,
7939
+ last_read: new Date().toISOString()
7940
+ }] : [];
7930
7941
  this.state = new StateStore({
7931
7942
  active: false,
7932
7943
  channel: _channel,
@@ -7937,7 +7948,7 @@ var Thread = /*#__PURE__*/function () {
7937
7948
  pagination: repliesPaginationFromInitialThread(threadData),
7938
7949
  parentMessage: formatMessage(threadData.parent_message),
7939
7950
  participants: threadData.thread_participants,
7940
- read: formatReadState((_threadData$read = threadData.read) !== null && _threadData$read !== void 0 ? _threadData$read : []),
7951
+ read: formatReadState(!threadData.read || threadData.read.length === 0 ? placeholderReadResponse : threadData.read),
7941
7952
  replies: threadData.latest_replies.map(formatMessage),
7942
7953
  replyCount: (_threadData$reply_cou = threadData.reply_count) !== null && _threadData$reply_cou !== void 0 ? _threadData$reply_cou : 0,
7943
7954
  updatedAt: threadData.updated_at ? new Date(threadData.updated_at) : null
@@ -13361,7 +13372,7 @@ var StreamChat = /*#__PURE__*/function () {
13361
13372
  }, {
13362
13373
  key: "getUserAgent",
13363
13374
  value: function getUserAgent() {
13364
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.40.7");
13375
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.40.9");
13365
13376
  }
13366
13377
  }, {
13367
13378
  key: "setUserAgent",