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/browser.js CHANGED
@@ -603,6 +603,7 @@ function formatMessage(message) {
603
603
  var findIndexInSortedArray = function findIndexInSortedArray(_ref) {
604
604
  var needle = _ref.needle,
605
605
  sortedArray = _ref.sortedArray,
606
+ selectKey = _ref.selectKey,
606
607
  _ref$selectValueToCom = _ref.selectValueToCompare,
607
608
  selectValueToCompare = _ref$selectValueToCom === void 0 ? function (e) {
608
609
  return e;
@@ -622,13 +623,27 @@ var findIndexInSortedArray = function findIndexInSortedArray(_ref) {
622
623
 
623
624
  while (left <= right) {
624
625
  recalculateMiddle();
625
- var comparableMiddle = selectValueToCompare(sortedArray[middle]); // if (comparableNeedle === comparableMiddle) return middle;
626
+ var comparableMiddle = selectValueToCompare(sortedArray[middle]);
626
627
 
627
- if (sortDirection === 'ascending' && comparableNeedle < comparableMiddle || sortDirection === 'descending' && comparableNeedle > comparableMiddle) {
628
+ if (sortDirection === 'ascending' && comparableNeedle < comparableMiddle || sortDirection === 'descending' && comparableNeedle >= comparableMiddle) {
628
629
  right = middle - 1;
629
630
  } else {
630
631
  left = middle + 1;
631
632
  }
633
+ } // In case there are several array elements with the same comparable value, search around the insertion
634
+ // point to possibly find an element with the same key. If found, prefer it.
635
+ // This, for example, prevents duplication of messages with the same creation date.
636
+
637
+
638
+ if (selectKey) {
639
+ var needleKey = selectKey(needle);
640
+ var step = sortDirection === 'ascending' ? -1 : +1;
641
+
642
+ for (var i = left + step; 0 <= i && i < sortedArray.length && selectValueToCompare(sortedArray[i]) === comparableNeedle; i += step) {
643
+ if (selectKey(sortedArray[i]) === needleKey) {
644
+ return i;
645
+ }
646
+ }
632
647
  }
633
648
 
634
649
  return left;
@@ -675,19 +690,15 @@ function addToMessageList(messages, newMessage) {
675
690
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
676
691
  selectValueToCompare: function selectValueToCompare(m) {
677
692
  return m[sortBy].getTime();
693
+ },
694
+ selectKey: function selectKey(m) {
695
+ return m.id;
678
696
  }
679
697
  }); // message already exists and not filtered with timestampChanged, update and return
680
698
 
681
- if (!timestampChanged && newMessage.id) {
682
- if (newMessages[insertionIndex] && newMessage.id === newMessages[insertionIndex].id) {
683
- newMessages[insertionIndex] = newMessage;
684
- return newMessages;
685
- }
686
-
687
- if (newMessages[insertionIndex - 1] && newMessage.id === newMessages[insertionIndex - 1].id) {
688
- newMessages[insertionIndex - 1] = newMessage;
689
- return newMessages;
690
- }
699
+ if (!timestampChanged && newMessage.id && newMessages[insertionIndex] && newMessage.id === newMessages[insertionIndex].id) {
700
+ newMessages[insertionIndex] = newMessage;
701
+ return newMessages;
691
702
  } // do not add updated or deleted messages to the list if they already exist or come with a timestamp change
692
703
 
693
704
 
@@ -7910,7 +7921,7 @@ var Thread = /*#__PURE__*/function () {
7910
7921
  });
7911
7922
 
7912
7923
  _defineProperty__default['default'](this, "deleteReplyLocally", function (_ref5) {
7913
- var _replies$index, _replies;
7924
+ var _replies$index;
7914
7925
 
7915
7926
  var message = _ref5.message;
7916
7927
 
@@ -7923,17 +7934,19 @@ var Thread = /*#__PURE__*/function () {
7923
7934
  sortDirection: 'ascending',
7924
7935
  selectValueToCompare: function selectValueToCompare(reply) {
7925
7936
  return reply.created_at.getTime();
7937
+ },
7938
+ selectKey: function selectKey(reply) {
7939
+ return reply.id;
7926
7940
  }
7927
7941
  });
7928
- 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;
7929
7942
 
7930
- if (actualIndex === null) {
7943
+ if (((_replies$index = replies[index]) === null || _replies$index === void 0 ? void 0 : _replies$index.id) !== message.id) {
7931
7944
  return;
7932
7945
  }
7933
7946
 
7934
7947
  var updatedReplies = _toConsumableArray__default['default'](replies);
7935
7948
 
7936
- updatedReplies.splice(actualIndex, 1);
7949
+ updatedReplies.splice(index, 1);
7937
7950
 
7938
7951
  _this.state.partialNext({
7939
7952
  replies: updatedReplies
@@ -8776,6 +8789,88 @@ var Moderation = /*#__PURE__*/function () {
8776
8789
 
8777
8790
  return check;
8778
8791
  }()
8792
+ /**
8793
+ *
8794
+ * @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
8795
+ * @param {string} entityID string ID of the entity to be checked. This is mainly for tracking purposes
8796
+ * @param {string} entityCreatorID string ID of the entity creator
8797
+ * @param {object} moderationPayload object Content to be checked for moderation. E.g., { texts: ['text1', 'text2'], images: ['image1', 'image2']}
8798
+ * @param {Array} moderationPayload.texts array Array of texts to be checked for moderation
8799
+ * @param {Array} moderationPayload.images array Array of images to be checked for moderation
8800
+ * @param {Array} moderationPayload.videos array Array of videos to be checked for moderation
8801
+ * @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the entity
8802
+ * @returns
8803
+ */
8804
+
8805
+ }, {
8806
+ key: "addCustomFlags",
8807
+ value: function () {
8808
+ var _addCustomFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(entityType, entityID, entityCreatorID, moderationPayload, flags) {
8809
+ return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
8810
+ while (1) {
8811
+ switch (_context14.prev = _context14.next) {
8812
+ case 0:
8813
+ _context14.next = 2;
8814
+ return this.client.post(this.client.baseURL + "/api/v2/moderation/custom_check", {
8815
+ entity_type: entityType,
8816
+ entity_id: entityID,
8817
+ entity_creator_id: entityCreatorID,
8818
+ moderation_payload: moderationPayload,
8819
+ flags: flags
8820
+ });
8821
+
8822
+ case 2:
8823
+ return _context14.abrupt("return", _context14.sent);
8824
+
8825
+ case 3:
8826
+ case "end":
8827
+ return _context14.stop();
8828
+ }
8829
+ }
8830
+ }, _callee14, this);
8831
+ }));
8832
+
8833
+ function addCustomFlags(_x25, _x26, _x27, _x28, _x29) {
8834
+ return _addCustomFlags.apply(this, arguments);
8835
+ }
8836
+
8837
+ return addCustomFlags;
8838
+ }()
8839
+ /**
8840
+ * Add custom flags to a message
8841
+ * @param {string} messageID Message ID to be flagged
8842
+ * @param {Array<CustomCheckFlag>} flags Array of CustomCheckFlag to be passed to flag the message
8843
+ * @returns
8844
+ */
8845
+
8846
+ }, {
8847
+ key: "addCustomMessageFlags",
8848
+ value: function () {
8849
+ var _addCustomMessageFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee15(messageID, flags) {
8850
+ return _regeneratorRuntime__default['default'].wrap(function _callee15$(_context15) {
8851
+ while (1) {
8852
+ switch (_context15.prev = _context15.next) {
8853
+ case 0:
8854
+ _context15.next = 2;
8855
+ return this.addCustomFlags(MODERATION_ENTITY_TYPES.message, messageID, '', {}, flags);
8856
+
8857
+ case 2:
8858
+ return _context15.abrupt("return", _context15.sent);
8859
+
8860
+ case 3:
8861
+ case "end":
8862
+ return _context15.stop();
8863
+ }
8864
+ }
8865
+ }, _callee15, this);
8866
+ }));
8867
+
8868
+ function addCustomMessageFlags(_x30, _x31) {
8869
+ return _addCustomMessageFlags.apply(this, arguments);
8870
+ }
8871
+
8872
+ return addCustomMessageFlags;
8873
+ }()
8779
8874
  }]);
8780
8875
 
8781
8876
  return Moderation;
@@ -14763,7 +14858,7 @@ var StreamChat = /*#__PURE__*/function () {
14763
14858
  }, {
14764
14859
  key: "getUserAgent",
14765
14860
  value: function getUserAgent() {
14766
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.47.0");
14861
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.48.0");
14767
14862
  }
14768
14863
  }, {
14769
14864
  key: "setUserAgent",