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