stream-chat 8.47.0 → 8.48.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.
@@ -578,6 +578,7 @@ function formatMessage(message) {
578
578
  var findIndexInSortedArray = function findIndexInSortedArray(_ref) {
579
579
  var needle = _ref.needle,
580
580
  sortedArray = _ref.sortedArray,
581
+ selectKey = _ref.selectKey,
581
582
  _ref$selectValueToCom = _ref.selectValueToCompare,
582
583
  selectValueToCompare = _ref$selectValueToCom === void 0 ? function (e) {
583
584
  return e;
@@ -597,13 +598,27 @@ var findIndexInSortedArray = function findIndexInSortedArray(_ref) {
597
598
 
598
599
  while (left <= right) {
599
600
  recalculateMiddle();
600
- var comparableMiddle = selectValueToCompare(sortedArray[middle]); // if (comparableNeedle === comparableMiddle) return middle;
601
+ var comparableMiddle = selectValueToCompare(sortedArray[middle]);
601
602
 
602
- if (sortDirection === 'ascending' && comparableNeedle < comparableMiddle || sortDirection === 'descending' && comparableNeedle > comparableMiddle) {
603
+ if (sortDirection === 'ascending' && comparableNeedle < comparableMiddle || sortDirection === 'descending' && comparableNeedle >= comparableMiddle) {
603
604
  right = middle - 1;
604
605
  } else {
605
606
  left = middle + 1;
606
607
  }
608
+ } // In case there are several array elements with the same comparable value, search around the insertion
609
+ // point to possibly find an element with the same key. If found, prefer it.
610
+ // This, for example, prevents duplication of messages with the same creation date.
611
+
612
+
613
+ if (selectKey) {
614
+ var needleKey = selectKey(needle);
615
+ var step = sortDirection === 'ascending' ? -1 : +1;
616
+
617
+ for (var i = left + step; 0 <= i && i < sortedArray.length && selectValueToCompare(sortedArray[i]) === comparableNeedle; i += step) {
618
+ if (selectKey(sortedArray[i]) === needleKey) {
619
+ return i;
620
+ }
621
+ }
607
622
  }
608
623
 
609
624
  return left;
@@ -650,19 +665,15 @@ function addToMessageList(messages, newMessage) {
650
665
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
651
666
  selectValueToCompare: function selectValueToCompare(m) {
652
667
  return m[sortBy].getTime();
668
+ },
669
+ selectKey: function selectKey(m) {
670
+ return m.id;
653
671
  }
654
672
  }); // message already exists and not filtered with timestampChanged, update and return
655
673
 
656
- if (!timestampChanged && newMessage.id) {
657
- if (newMessages[insertionIndex] && newMessage.id === newMessages[insertionIndex].id) {
658
- newMessages[insertionIndex] = newMessage;
659
- return newMessages;
660
- }
661
-
662
- if (newMessages[insertionIndex - 1] && newMessage.id === newMessages[insertionIndex - 1].id) {
663
- newMessages[insertionIndex - 1] = newMessage;
664
- return newMessages;
665
- }
674
+ if (!timestampChanged && newMessage.id && newMessages[insertionIndex] && newMessage.id === newMessages[insertionIndex].id) {
675
+ newMessages[insertionIndex] = newMessage;
676
+ return newMessages;
666
677
  } // do not add updated or deleted messages to the list if they already exist or come with a timestamp change
667
678
 
668
679
 
@@ -7885,7 +7896,7 @@ var Thread = /*#__PURE__*/function () {
7885
7896
  });
7886
7897
 
7887
7898
  _defineProperty(this, "deleteReplyLocally", function (_ref5) {
7888
- var _replies$index, _replies;
7899
+ var _replies$index;
7889
7900
 
7890
7901
  var message = _ref5.message;
7891
7902
 
@@ -7898,17 +7909,19 @@ var Thread = /*#__PURE__*/function () {
7898
7909
  sortDirection: 'ascending',
7899
7910
  selectValueToCompare: function selectValueToCompare(reply) {
7900
7911
  return reply.created_at.getTime();
7912
+ },
7913
+ selectKey: function selectKey(reply) {
7914
+ return reply.id;
7901
7915
  }
7902
7916
  });
7903
- var actualIndex = ((_replies$index = replies[index]) === null || _replies$index === void 0 ? void 0 : _replies$index.id) === message.id ? index : ((_replies = replies[index - 1]) === null || _replies === void 0 ? void 0 : _replies.id) === message.id ? index - 1 : null;
7904
7917
 
7905
- if (actualIndex === null) {
7918
+ if (((_replies$index = replies[index]) === null || _replies$index === void 0 ? void 0 : _replies$index.id) !== message.id) {
7906
7919
  return;
7907
7920
  }
7908
7921
 
7909
7922
  var updatedReplies = _toConsumableArray(replies);
7910
7923
 
7911
- updatedReplies.splice(actualIndex, 1);
7924
+ updatedReplies.splice(index, 1);
7912
7925
 
7913
7926
  _this.state.partialNext({
7914
7927
  replies: updatedReplies
@@ -8751,6 +8764,88 @@ var Moderation = /*#__PURE__*/function () {
8751
8764
 
8752
8765
  return check;
8753
8766
  }()
8767
+ /**
8768
+ *
8769
+ * @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
8770
+ * @param {string} entityID string ID of the entity to be checked. This is mainly for tracking purposes
8771
+ * @param {string} entityCreatorID string ID of the entity creator
8772
+ * @param {object} moderationPayload object Content to be checked for moderation. E.g., { texts: ['text1', 'text2'], images: ['image1', 'image2']}
8773
+ * @param {Array} moderationPayload.texts array Array of texts to be checked for moderation
8774
+ * @param {Array} moderationPayload.images array Array of images to be checked for moderation
8775
+ * @param {Array} moderationPayload.videos array Array of videos to be checked for moderation
8776
+ * @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the entity
8777
+ * @returns
8778
+ */
8779
+
8780
+ }, {
8781
+ key: "addCustomFlags",
8782
+ value: function () {
8783
+ var _addCustomFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(entityType, entityID, entityCreatorID, moderationPayload, flags) {
8784
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
8785
+ while (1) {
8786
+ switch (_context14.prev = _context14.next) {
8787
+ case 0:
8788
+ _context14.next = 2;
8789
+ return this.client.post(this.client.baseURL + "/api/v2/moderation/custom_check", {
8790
+ entity_type: entityType,
8791
+ entity_id: entityID,
8792
+ entity_creator_id: entityCreatorID,
8793
+ moderation_payload: moderationPayload,
8794
+ flags: flags
8795
+ });
8796
+
8797
+ case 2:
8798
+ return _context14.abrupt("return", _context14.sent);
8799
+
8800
+ case 3:
8801
+ case "end":
8802
+ return _context14.stop();
8803
+ }
8804
+ }
8805
+ }, _callee14, this);
8806
+ }));
8807
+
8808
+ function addCustomFlags(_x25, _x26, _x27, _x28, _x29) {
8809
+ return _addCustomFlags.apply(this, arguments);
8810
+ }
8811
+
8812
+ return addCustomFlags;
8813
+ }()
8814
+ /**
8815
+ * Add custom flags to a message
8816
+ * @param {string} messageID Message ID to be flagged
8817
+ * @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the message
8818
+ * @returns
8819
+ */
8820
+
8821
+ }, {
8822
+ key: "addCustomMessageFlags",
8823
+ value: function () {
8824
+ var _addCustomMessageFlags = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(messageID, flags) {
8825
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
8826
+ while (1) {
8827
+ switch (_context15.prev = _context15.next) {
8828
+ case 0:
8829
+ _context15.next = 2;
8830
+ return this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
8831
+
8832
+ case 2:
8833
+ return _context15.abrupt("return", _context15.sent);
8834
+
8835
+ case 3:
8836
+ case "end":
8837
+ return _context15.stop();
8838
+ }
8839
+ }
8840
+ }, _callee15, this);
8841
+ }));
8842
+
8843
+ function addCustomMessageFlags(_x30, _x31) {
8844
+ return _addCustomMessageFlags.apply(this, arguments);
8845
+ }
8846
+
8847
+ return addCustomMessageFlags;
8848
+ }()
8754
8849
  }]);
8755
8850
 
8756
8851
  return Moderation;
@@ -14738,7 +14833,7 @@ var StreamChat = /*#__PURE__*/function () {
14738
14833
  }, {
14739
14834
  key: "getUserAgent",
14740
14835
  value: function getUserAgent() {
14741
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.47.0");
14836
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.48.0");
14742
14837
  }
14743
14838
  }, {
14744
14839
  key: "setUserAgent",