stream-chat 8.39.0 → 8.40.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.
@@ -93,9 +93,9 @@ var decodeBase64 = function decodeBase64(s) {
93
93
 
94
94
  var https = null;
95
95
 
96
- function ownKeys$9(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
96
+ function ownKeys$b(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
97
97
 
98
- function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
98
+ function _objectSpread$b(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$b(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$b(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
99
99
 
100
100
  function _createForOfIteratorHelper$4(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$4(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
101
101
 
@@ -349,89 +349,120 @@ var axiosParamsSerializer = function axiosParamsSerializer(params) {
349
349
  return newParams.join('&');
350
350
  };
351
351
  /**
352
- * formatMessage - Takes the message object. Parses the dates, sets __html
353
- * and sets the status to received if missing. Returns a message object
354
- *
355
- * @param {MessageResponse<StreamChatGenerics>} message a message object
352
+ * Takes the message object, parses the dates, sets `__html`
353
+ * and sets the status to `received` if missing; returns a new message object.
356
354
  *
355
+ * @param {MessageResponse<StreamChatGenerics>} message `MessageResponse` object
357
356
  */
358
357
 
359
358
  function formatMessage(message) {
360
- return _objectSpread$9(_objectSpread$9({}, message), {}, {
359
+ return _objectSpread$b(_objectSpread$b({}, message), {}, {
361
360
  /**
362
361
  * @deprecated please use `html`
363
362
  */
364
363
  __html: message.html,
365
- // parse the date..
364
+ // parse the dates
366
365
  pinned_at: message.pinned_at ? new Date(message.pinned_at) : null,
367
366
  created_at: message.created_at ? new Date(message.created_at) : new Date(),
368
367
  updated_at: message.updated_at ? new Date(message.updated_at) : new Date(),
368
+ deleted_at: message.deleted_at ? new Date(message.deleted_at) : null,
369
369
  status: message.status || 'received',
370
370
  reaction_groups: maybeGetReactionGroupsFallback(message.reaction_groups, message.reaction_counts, message.reaction_scores)
371
371
  });
372
372
  }
373
- function addToMessageList(messages, message) {
373
+ var findIndexInSortedArray = function findIndexInSortedArray(_ref) {
374
+ var needle = _ref.needle,
375
+ sortedArray = _ref.sortedArray,
376
+ _ref$selectValueToCom = _ref.selectValueToCompare,
377
+ selectValueToCompare = _ref$selectValueToCom === void 0 ? function (e) {
378
+ return e;
379
+ } : _ref$selectValueToCom,
380
+ _ref$sortDirection = _ref.sortDirection,
381
+ sortDirection = _ref$sortDirection === void 0 ? 'ascending' : _ref$sortDirection;
382
+ if (!sortedArray.length) return 0;
383
+ var left = 0;
384
+ var right = sortedArray.length - 1;
385
+ var middle = 0;
386
+
387
+ var recalculateMiddle = function recalculateMiddle() {
388
+ middle = Math.round((left + right) / 2);
389
+ };
390
+
391
+ var actualNeedle = selectValueToCompare(needle);
392
+ recalculateMiddle();
393
+
394
+ 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])) {
397
+ right = middle - 1;
398
+ } else {
399
+ left = middle + 1;
400
+ }
401
+
402
+ recalculateMiddle();
403
+ }
404
+
405
+ return left;
406
+ };
407
+ function addToMessageList(messages, newMessage) {
374
408
  var timestampChanged = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
375
409
  var sortBy = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'created_at';
376
410
  var addIfDoesNotExist = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
377
411
  var addMessageToList = addIfDoesNotExist || timestampChanged;
378
- var messageArr = messages; // if created_at has changed, message should be filtered and re-inserted in correct order
412
+
413
+ var newMessages = _toConsumableArray(messages); // if created_at has changed, message should be filtered and re-inserted in correct order
379
414
  // slow op but usually this only happens for a message inserted to state before actual response with correct timestamp
380
415
 
416
+
381
417
  if (timestampChanged) {
382
- messageArr = messageArr.filter(function (msg) {
383
- return !(msg.id && message.id === msg.id);
418
+ newMessages = newMessages.filter(function (message) {
419
+ return !(message.id && newMessage.id === message.id);
384
420
  });
385
- } // Get array length after filtering
421
+ } // for empty list just concat and return unless it's an update or deletion
386
422
 
387
423
 
388
- var messageArrayLength = messageArr.length; // for empty list just concat and return unless it's an update or deletion
424
+ if (!newMessages.length && addMessageToList) {
425
+ return newMessages.concat(newMessage);
426
+ } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
389
427
 
390
- if (messageArrayLength === 0 && addMessageToList) {
391
- return messageArr.concat(message);
392
- } else if (messageArrayLength === 0) {
393
- return _toConsumableArray(messageArr);
394
- }
395
428
 
396
- var messageTime = message[sortBy].getTime();
397
- var messageIsNewest = messageArr[messageArrayLength - 1][sortBy].getTime() < messageTime; // if message is newer than last item in the list concat and return unless it's an update or deletion
429
+ var messageTime = newMessage[sortBy].getTime(); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
430
+
431
+ var messageIsNewest = newMessages.at(-1)[sortBy].getTime() < messageTime; // if message is newer than last item in the list concat and return unless it's an update or deletion
398
432
 
399
433
  if (messageIsNewest && addMessageToList) {
400
- return messageArr.concat(message);
401
- } else if (messageIsNewest) {
402
- return _toConsumableArray(messageArr);
434
+ return newMessages.concat(newMessage);
403
435
  } // find the closest index to push the new message
404
436
 
405
437
 
406
- var left = 0;
407
- var middle = 0;
408
- var right = messageArrayLength - 1;
409
-
410
- while (left <= right) {
411
- middle = Math.floor((right + left) / 2);
412
- if (messageArr[middle][sortBy].getTime() <= messageTime) left = middle + 1;else right = middle - 1;
413
- } // message already exists and not filtered due to timestampChanged, update and return
414
-
438
+ var insertionIndex = findIndexInSortedArray({
439
+ needle: newMessage,
440
+ sortedArray: messages,
441
+ sortDirection: 'ascending',
442
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
443
+ selectValueToCompare: function selectValueToCompare(m) {
444
+ return m[sortBy].getTime();
445
+ }
446
+ }); // message already exists and not filtered with timestampChanged, update and return
415
447
 
416
- if (!timestampChanged && message.id) {
417
- if (messageArr[left] && message.id === messageArr[left].id) {
418
- messageArr[left] = message;
419
- return _toConsumableArray(messageArr);
448
+ if (!timestampChanged && newMessage.id) {
449
+ if (newMessages[insertionIndex] && newMessage.id === newMessages[insertionIndex].id) {
450
+ newMessages[insertionIndex] = newMessage;
451
+ return newMessages;
420
452
  }
421
453
 
422
- if (messageArr[left - 1] && message.id === messageArr[left - 1].id) {
423
- messageArr[left - 1] = message;
424
- return _toConsumableArray(messageArr);
454
+ if (newMessages[insertionIndex - 1] && newMessage.id === newMessages[insertionIndex - 1].id) {
455
+ newMessages[insertionIndex - 1] = newMessage;
456
+ return newMessages;
425
457
  }
426
- } // Do not add updated or deleted messages to the list if they do not already exist
427
- // or have a timestamp change.
458
+ } // do not add updated or deleted messages to the list if they already exist or come with a timestamp change
428
459
 
429
460
 
430
461
  if (addMessageToList) {
431
- messageArr.splice(left, 0, message);
462
+ newMessages.splice(insertionIndex, 0, newMessage);
432
463
  }
433
464
 
434
- return _toConsumableArray(messageArr);
465
+ return newMessages;
435
466
  }
436
467
 
437
468
  function maybeGetReactionGroupsFallback(groups, counts, scores) {
@@ -454,8 +485,46 @@ function maybeGetReactionGroupsFallback(groups, counts, scores) {
454
485
  }
455
486
 
456
487
  return null;
457
- }
488
+ } // works exactly the same as lodash.throttle
489
+
490
+
491
+ var throttle = function throttle(fn) {
492
+ var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
493
+
494
+ var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
495
+ _ref2$leading = _ref2.leading,
496
+ leading = _ref2$leading === void 0 ? true : _ref2$leading,
497
+ _ref2$trailing = _ref2.trailing,
498
+ trailing = _ref2$trailing === void 0 ? false : _ref2$trailing;
499
+
500
+ var runningTimeout = null;
501
+ var storedArgs = null;
502
+ return function () {
503
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
504
+ args[_key] = arguments[_key];
505
+ }
506
+
507
+ if (runningTimeout) {
508
+ if (trailing) storedArgs = args;
509
+ return;
510
+ }
511
+
512
+ if (leading) fn.apply(void 0, args);
513
+
514
+ var timeoutHandler = function timeoutHandler() {
515
+ if (storedArgs) {
516
+ fn.apply(void 0, _toConsumableArray(storedArgs));
517
+ storedArgs = null;
518
+ runningTimeout = setTimeout(timeoutHandler, timeout);
519
+ return;
520
+ }
521
+
522
+ runningTimeout = null;
523
+ };
458
524
 
525
+ runningTimeout = setTimeout(timeoutHandler, timeout);
526
+ };
527
+ };
459
528
  function binarySearchByDateEqualOrNearestGreater(array, targetDate) {
460
529
  var left = 0;
461
530
  var right = array.length - 1;
@@ -483,13 +552,13 @@ function binarySearchByDateEqualOrNearestGreater(array, targetDate) {
483
552
  return left;
484
553
  }
485
554
 
486
- var messagePaginationCreatedAtAround = function messagePaginationCreatedAtAround(_ref) {
487
- var parentSet = _ref.parentSet,
488
- requestedPageSize = _ref.requestedPageSize,
489
- returnedPage = _ref.returnedPage,
490
- messagePaginationOptions = _ref.messagePaginationOptions;
555
+ var messagePaginationCreatedAtAround = function messagePaginationCreatedAtAround(_ref3) {
556
+ var parentSet = _ref3.parentSet,
557
+ requestedPageSize = _ref3.requestedPageSize,
558
+ returnedPage = _ref3.returnedPage,
559
+ messagePaginationOptions = _ref3.messagePaginationOptions;
491
560
 
492
- var newPagination = _objectSpread$9({}, parentSet.pagination);
561
+ var newPagination = _objectSpread$b({}, parentSet.pagination);
493
562
 
494
563
  if (!(messagePaginationOptions !== null && messagePaginationOptions !== void 0 && messagePaginationOptions.created_at_around)) return newPagination;
495
564
  var hasPrev;
@@ -497,9 +566,9 @@ var messagePaginationCreatedAtAround = function messagePaginationCreatedAtAround
497
566
  var updateHasPrev;
498
567
  var updateHasNext;
499
568
  var createdAtAroundDate = new Date(messagePaginationOptions.created_at_around);
500
- var _ref2 = [returnedPage[0], returnedPage.slice(-1)[0]],
501
- firstPageMsg = _ref2[0],
502
- lastPageMsg = _ref2[1]; // expect ASC order (from oldest to newest)
569
+ var _ref4 = [returnedPage[0], returnedPage.slice(-1)[0]],
570
+ firstPageMsg = _ref4[0],
571
+ lastPageMsg = _ref4[1]; // expect ASC order (from oldest to newest)
503
572
 
504
573
  var wholePageHasNewerMessages = !!(firstPageMsg !== null && firstPageMsg !== void 0 && firstPageMsg.created_at) && new Date(firstPageMsg.created_at) > createdAtAroundDate;
505
574
  var wholePageHasOlderMessages = !!(lastPageMsg !== null && lastPageMsg !== void 0 && lastPageMsg.created_at) && new Date(lastPageMsg.created_at) < createdAtAroundDate;
@@ -546,25 +615,25 @@ var messagePaginationCreatedAtAround = function messagePaginationCreatedAtAround
546
615
  return newPagination;
547
616
  };
548
617
 
549
- var messagePaginationIdAround = function messagePaginationIdAround(_ref3) {
618
+ var messagePaginationIdAround = function messagePaginationIdAround(_ref5) {
550
619
  var _parentSet$messages$2, _parentSet$messages$s2;
551
620
 
552
- var parentSet = _ref3.parentSet,
553
- requestedPageSize = _ref3.requestedPageSize,
554
- returnedPage = _ref3.returnedPage,
555
- messagePaginationOptions = _ref3.messagePaginationOptions;
621
+ var parentSet = _ref5.parentSet,
622
+ requestedPageSize = _ref5.requestedPageSize,
623
+ returnedPage = _ref5.returnedPage,
624
+ messagePaginationOptions = _ref5.messagePaginationOptions;
556
625
 
557
- var newPagination = _objectSpread$9({}, parentSet.pagination);
626
+ var newPagination = _objectSpread$b({}, parentSet.pagination);
558
627
 
559
- var _ref4 = messagePaginationOptions || {},
560
- id_around = _ref4.id_around;
628
+ var _ref6 = messagePaginationOptions || {},
629
+ id_around = _ref6.id_around;
561
630
 
562
631
  if (!id_around) return newPagination;
563
632
  var hasPrev;
564
633
  var hasNext;
565
- var _ref5 = [returnedPage[0], returnedPage.slice(-1)[0]],
566
- firstPageMsg = _ref5[0],
567
- lastPageMsg = _ref5[1];
634
+ var _ref7 = [returnedPage[0], returnedPage.slice(-1)[0]],
635
+ firstPageMsg = _ref7[0],
636
+ lastPageMsg = _ref7[1];
568
637
  var firstPageMsgIsFirstInSet = (firstPageMsg === null || firstPageMsg === void 0 ? void 0 : firstPageMsg.id) === ((_parentSet$messages$2 = parentSet.messages[0]) === null || _parentSet$messages$2 === void 0 ? void 0 : _parentSet$messages$2.id),
569
638
  lastPageMsgIsLastInSet = (lastPageMsg === null || lastPageMsg === void 0 ? void 0 : lastPageMsg.id) === ((_parentSet$messages$s2 = parentSet.messages.slice(-1)[0]) === null || _parentSet$messages$s2 === void 0 ? void 0 : _parentSet$messages$s2.id);
570
639
  var updateHasPrev = firstPageMsgIsFirstInSet;
@@ -604,21 +673,21 @@ var messagePaginationIdAround = function messagePaginationIdAround(_ref3) {
604
673
  return newPagination;
605
674
  };
606
675
 
607
- var messagePaginationLinear = function messagePaginationLinear(_ref6) {
676
+ var messagePaginationLinear = function messagePaginationLinear(_ref8) {
608
677
  var _parentSet$messages$3, _parentSet$messages$s3;
609
678
 
610
- var parentSet = _ref6.parentSet,
611
- requestedPageSize = _ref6.requestedPageSize,
612
- returnedPage = _ref6.returnedPage,
613
- messagePaginationOptions = _ref6.messagePaginationOptions;
679
+ var parentSet = _ref8.parentSet,
680
+ requestedPageSize = _ref8.requestedPageSize,
681
+ returnedPage = _ref8.returnedPage,
682
+ messagePaginationOptions = _ref8.messagePaginationOptions;
614
683
 
615
- var newPagination = _objectSpread$9({}, parentSet.pagination);
684
+ var newPagination = _objectSpread$b({}, parentSet.pagination);
616
685
 
617
686
  var hasPrev;
618
687
  var hasNext;
619
- var _ref7 = [returnedPage[0], returnedPage.slice(-1)[0]],
620
- firstPageMsg = _ref7[0],
621
- lastPageMsg = _ref7[1];
688
+ var _ref9 = [returnedPage[0], returnedPage.slice(-1)[0]],
689
+ firstPageMsg = _ref9[0],
690
+ lastPageMsg = _ref9[1];
622
691
  var firstPageMsgIsFirstInSet = (firstPageMsg === null || firstPageMsg === void 0 ? void 0 : firstPageMsg.id) && firstPageMsg.id === ((_parentSet$messages$3 = parentSet.messages[0]) === null || _parentSet$messages$3 === void 0 ? void 0 : _parentSet$messages$3.id),
623
692
  lastPageMsgIsLastInSet = (lastPageMsg === null || lastPageMsg === void 0 ? void 0 : lastPageMsg.id) && lastPageMsg.id === ((_parentSet$messages$s3 = parentSet.messages.slice(-1)[0]) === null || _parentSet$messages$s3 === void 0 ? void 0 : _parentSet$messages$s3.id);
624
693
  var queriedNextMessages = messagePaginationOptions && (messagePaginationOptions.created_at_after_or_equal || messagePaginationOptions.created_at_after || messagePaginationOptions.id_gt || messagePaginationOptions.id_gte);
@@ -666,9 +735,9 @@ var DEFAULT_MESSAGE_SET_PAGINATION = {
666
735
  hasPrev: true
667
736
  };
668
737
 
669
- function ownKeys$8(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
738
+ function ownKeys$a(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
670
739
 
671
- function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
740
+ function _objectSpread$a(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$a(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$a(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
672
741
 
673
742
  /**
674
743
  * ChannelState - A container class for the channel state.
@@ -723,6 +792,10 @@ var ChannelState = /*#__PURE__*/function () {
723
792
 
724
793
  _defineProperty(this, "messageSets", []);
725
794
 
795
+ _defineProperty(this, "formatMessage", function (message) {
796
+ return formatMessage(message);
797
+ });
798
+
726
799
  _defineProperty(this, "setIsUpToDate", function (isUpToDate) {
727
800
  _this.isUpToDate = isUpToDate;
728
801
  });
@@ -745,7 +818,7 @@ var ChannelState = /*#__PURE__*/function () {
745
818
  if (!message) return;
746
819
  if (message.poll_id !== pollVote.poll_id) return;
747
820
 
748
- var updatedPoll = _objectSpread$8({}, poll);
821
+ var updatedPoll = _objectSpread$a({}, poll);
749
822
 
750
823
  var ownVotes = _toConsumableArray(((_message$poll = message.poll) === null || _message$poll === void 0 ? void 0 : _message$poll.own_votes) || []);
751
824
 
@@ -767,7 +840,7 @@ var ChannelState = /*#__PURE__*/function () {
767
840
 
768
841
  updatedPoll.own_votes = ownVotes;
769
842
 
770
- var newMessage = _objectSpread$8(_objectSpread$8({}, message), {}, {
843
+ var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
771
844
  poll: updatedPoll
772
845
  });
773
846
 
@@ -782,7 +855,7 @@ var ChannelState = /*#__PURE__*/function () {
782
855
  if (!message) return;
783
856
  if (message.poll_id !== pollVote.poll_id) return;
784
857
 
785
- var updatedPoll = _objectSpread$8({}, poll);
858
+ var updatedPoll = _objectSpread$a({}, poll);
786
859
 
787
860
  var ownVotes = _toConsumableArray(((_message$poll2 = message.poll) === null || _message$poll2 === void 0 ? void 0 : _message$poll2.own_votes) || []);
788
861
 
@@ -792,7 +865,7 @@ var ChannelState = /*#__PURE__*/function () {
792
865
 
793
866
  updatedPoll.own_votes = ownVotes;
794
867
 
795
- var newMessage = _objectSpread$8(_objectSpread$8({}, message), {}, {
868
+ var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
796
869
  poll: updatedPoll
797
870
  });
798
871
 
@@ -807,7 +880,7 @@ var ChannelState = /*#__PURE__*/function () {
807
880
  if (!message) return;
808
881
  if (message.poll_id !== pollVote.poll_id) return;
809
882
 
810
- var updatedPoll = _objectSpread$8({}, poll);
883
+ var updatedPoll = _objectSpread$a({}, poll);
811
884
 
812
885
  var ownVotes = _toConsumableArray(((_message$poll3 = message.poll) === null || _message$poll3 === void 0 ? void 0 : _message$poll3.own_votes) || []);
813
886
 
@@ -823,7 +896,7 @@ var ChannelState = /*#__PURE__*/function () {
823
896
 
824
897
  updatedPoll.own_votes = ownVotes;
825
898
 
826
- var newMessage = _objectSpread$8(_objectSpread$8({}, message), {}, {
899
+ var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
827
900
  poll: updatedPoll
828
901
  });
829
902
 
@@ -837,11 +910,11 @@ var ChannelState = /*#__PURE__*/function () {
837
910
 
838
911
  if (!message) return;
839
912
 
840
- var updatedPoll = _objectSpread$8(_objectSpread$8({}, poll), {}, {
913
+ var updatedPoll = _objectSpread$a(_objectSpread$a({}, poll), {}, {
841
914
  own_votes: _toConsumableArray(((_message$poll4 = message.poll) === null || _message$poll4 === void 0 ? void 0 : _message$poll4.own_votes) || [])
842
915
  });
843
916
 
844
- var newMessage = _objectSpread$8(_objectSpread$8({}, message), {}, {
917
+ var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
845
918
  poll: updatedPoll
846
919
  });
847
920
 
@@ -856,7 +929,7 @@ var ChannelState = /*#__PURE__*/function () {
856
929
  var m = messages[i];
857
930
 
858
931
  if (((_m$user = m.user) === null || _m$user === void 0 ? void 0 : _m$user.id) === user.id) {
859
- messages[i] = _objectSpread$8(_objectSpread$8({}, m), {}, {
932
+ messages[i] = _objectSpread$a(_objectSpread$a({}, m), {}, {
860
933
  user: user
861
934
  });
862
935
  }
@@ -911,9 +984,9 @@ var ChannelState = /*#__PURE__*/function () {
911
984
  user: m.user
912
985
  };
913
986
  } else {
914
- messages[i] = _objectSpread$8(_objectSpread$8({}, m), {}, {
987
+ messages[i] = _objectSpread$a(_objectSpread$a({}, m), {}, {
915
988
  type: 'deleted',
916
- deleted_at: user.deleted_at
989
+ deleted_at: user.deleted_at ? new Date(user.deleted_at) : null
917
990
  });
918
991
  }
919
992
  }
@@ -1017,28 +1090,15 @@ var ChannelState = /*#__PURE__*/function () {
1017
1090
  return this.addMessagesSorted([newMessage], timestampChanged, false, addIfDoesNotExist, messageSetToAddToIfDoesNotExist);
1018
1091
  }
1019
1092
  /**
1020
- * formatMessage - Takes the message object. Parses the dates, sets __html
1021
- * and sets the status to received if missing. Returns a message object
1022
- *
1023
- * @param {MessageResponse<StreamChatGenerics>} message a message object
1093
+ * Takes the message object, parses the dates, sets `__html`
1094
+ * and sets the status to `received` if missing; returns a new message object.
1024
1095
  *
1096
+ * @param {MessageResponse<StreamChatGenerics>} message `MessageResponse` object
1025
1097
  */
1026
1098
 
1027
1099
  }, {
1028
- key: "formatMessage",
1029
- value: function formatMessage(message) {
1030
- return _objectSpread$8(_objectSpread$8({}, message), {}, {
1031
- /**
1032
- * @deprecated please use `html`
1033
- */
1034
- __html: message.html,
1035
- // parse the date..
1036
- pinned_at: message.pinned_at ? new Date(message.pinned_at) : null,
1037
- created_at: message.created_at ? new Date(message.created_at) : new Date(),
1038
- updated_at: message.updated_at ? new Date(message.updated_at) : new Date(),
1039
- status: message.status || 'received'
1040
- });
1041
- }
1100
+ key: "addMessagesSorted",
1101
+ value:
1042
1102
  /**
1043
1103
  * addMessagesSorted - Add the list of messages to state and resorts the messages
1044
1104
  *
@@ -1049,10 +1109,7 @@ var ChannelState = /*#__PURE__*/function () {
1049
1109
  * @param {MessageSetType} messageSetToAddToIfDoesNotExist Which message set to add to if messages are not in the list (only used if addIfDoesNotExist is true)
1050
1110
  *
1051
1111
  */
1052
-
1053
- }, {
1054
- key: "addMessagesSorted",
1055
- value: function addMessagesSorted(newMessages) {
1112
+ function addMessagesSorted(newMessages) {
1056
1113
  var timestampChanged = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1057
1114
  var initializing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1058
1115
  var addIfDoesNotExist = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
@@ -1245,7 +1302,7 @@ var ChannelState = /*#__PURE__*/function () {
1245
1302
  var parseMessage = function parseMessage(m) {
1246
1303
  var _m$pinned_at, _m$updated_at;
1247
1304
 
1248
- return _objectSpread$8(_objectSpread$8({}, m), {}, {
1305
+ return _objectSpread$a(_objectSpread$a({}, m), {}, {
1249
1306
  created_at: m.created_at.toISOString(),
1250
1307
  pinned_at: (_m$pinned_at = m.pinned_at) === null || _m$pinned_at === void 0 ? void 0 : _m$pinned_at.toISOString(),
1251
1308
  updated_at: (_m$updated_at = m.updated_at) === null || _m$updated_at === void 0 ? void 0 : _m$updated_at.toISOString()
@@ -1255,8 +1312,8 @@ var ChannelState = /*#__PURE__*/function () {
1255
1312
  var update = function update(messages) {
1256
1313
  var updatedMessages = messages.reduce(function (acc, msg) {
1257
1314
  if (msg.quoted_message_id === message.id) {
1258
- acc.push(_objectSpread$8(_objectSpread$8({}, parseMessage(msg)), {}, {
1259
- quoted_message: remove ? _objectSpread$8(_objectSpread$8({}, message), {}, {
1315
+ acc.push(_objectSpread$a(_objectSpread$a({}, parseMessage(msg)), {}, {
1316
+ quoted_message: remove ? _objectSpread$a(_objectSpread$a({}, message), {}, {
1260
1317
  attachments: []
1261
1318
  }) : message
1262
1319
  }));
@@ -1745,9 +1802,9 @@ function _unsupportedIterableToArray$3(o, minLen) { if (!o) return; if (typeof o
1745
1802
 
1746
1803
  function _arrayLikeToArray$3(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1747
1804
 
1748
- function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1805
+ function ownKeys$9(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1749
1806
 
1750
- function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1807
+ function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1751
1808
  /**
1752
1809
  * Channel - The Channel class manages it's own state.
1753
1810
  */
@@ -1820,7 +1877,7 @@ var Channel = /*#__PURE__*/function () {
1820
1877
  while (1) {
1821
1878
  switch (_context.prev = _context.next) {
1822
1879
  case 0:
1823
- defaultOptions = _objectSpread$7(_objectSpread$7({}, options), {}, {
1880
+ defaultOptions = _objectSpread$9(_objectSpread$9({}, options), {}, {
1824
1881
  watch: false,
1825
1882
  state: false,
1826
1883
  presence: false
@@ -1892,7 +1949,7 @@ var Channel = /*#__PURE__*/function () {
1892
1949
 
1893
1950
  this.data = data; // this._data is used for the requests...
1894
1951
 
1895
- this._data = _objectSpread$7({}, data);
1952
+ this._data = _objectSpread$9({}, data);
1896
1953
  this.cid = "".concat(type, ":").concat(id);
1897
1954
  this.listeners = {}; // perhaps the state variable should be private
1898
1955
 
@@ -1954,7 +2011,7 @@ var Channel = /*#__PURE__*/function () {
1954
2011
  switch (_context2.prev = _context2.next) {
1955
2012
  case 0:
1956
2013
  _context2.next = 2;
1957
- return this.getClient().post(this._channelURL() + '/message', _objectSpread$7({
2014
+ return this.getClient().post(this._channelURL() + '/message', _objectSpread$9({
1958
2015
  message: message
1959
2016
  }, options));
1960
2017
 
@@ -2070,7 +2127,7 @@ var Channel = /*#__PURE__*/function () {
2070
2127
 
2071
2128
  case 3:
2072
2129
  // Return a list of channels
2073
- payload = _objectSpread$7(_objectSpread$7({
2130
+ payload = _objectSpread$9(_objectSpread$9({
2074
2131
  filter_conditions: {
2075
2132
  cid: this.cid
2076
2133
  }
@@ -2167,7 +2224,7 @@ var Channel = /*#__PURE__*/function () {
2167
2224
 
2168
2225
  _context5.next = 6;
2169
2226
  return this.getClient().get(this.getClient().baseURL + '/members', {
2170
- payload: _objectSpread$7({
2227
+ payload: _objectSpread$9({
2171
2228
  type: type,
2172
2229
  id: id,
2173
2230
  members: members,
@@ -2228,7 +2285,7 @@ var Channel = /*#__PURE__*/function () {
2228
2285
 
2229
2286
  case 4:
2230
2287
  _context6.next = 6;
2231
- return this.getClient().post(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(messageID), "/reaction"), _objectSpread$7({
2288
+ return this.getClient().post(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(messageID), "/reaction"), _objectSpread$9({
2232
2289
  reaction: reaction
2233
2290
  }, options));
2234
2291
 
@@ -2309,7 +2366,7 @@ var Channel = /*#__PURE__*/function () {
2309
2366
  delete channelData[key];
2310
2367
  });
2311
2368
  _context7.next = 7;
2312
- return this._update(_objectSpread$7({
2369
+ return this._update(_objectSpread$9({
2313
2370
  message: updateMessage,
2314
2371
  data: channelData
2315
2372
  }, options));
@@ -2481,7 +2538,7 @@ var Channel = /*#__PURE__*/function () {
2481
2538
  case 0:
2482
2539
  options = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
2483
2540
  _context11.next = 3;
2484
- return this.getClient().delete(this._channelURL(), _objectSpread$7({}, options));
2541
+ return this.getClient().delete(this._channelURL(), _objectSpread$9({}, options));
2485
2542
 
2486
2543
  case 3:
2487
2544
  return _context11.abrupt("return", _context11.sent);
@@ -2557,7 +2614,7 @@ var Channel = /*#__PURE__*/function () {
2557
2614
  case 0:
2558
2615
  options = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
2559
2616
  _context13.next = 3;
2560
- return this._update(_objectSpread$7({
2617
+ return this._update(_objectSpread$9({
2561
2618
  accept_invite: true
2562
2619
  }, options));
2563
2620
 
@@ -2598,7 +2655,7 @@ var Channel = /*#__PURE__*/function () {
2598
2655
  case 0:
2599
2656
  options = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
2600
2657
  _context14.next = 3;
2601
- return this._update(_objectSpread$7({
2658
+ return this._update(_objectSpread$9({
2602
2659
  reject_invite: true
2603
2660
  }, options));
2604
2661
 
@@ -2640,7 +2697,7 @@ var Channel = /*#__PURE__*/function () {
2640
2697
  case 0:
2641
2698
  options = _args15.length > 2 && _args15[2] !== undefined ? _args15[2] : {};
2642
2699
  _context15.next = 3;
2643
- return this._update(_objectSpread$7({
2700
+ return this._update(_objectSpread$9({
2644
2701
  add_members: members,
2645
2702
  message: message
2646
2703
  }, options));
@@ -2683,7 +2740,7 @@ var Channel = /*#__PURE__*/function () {
2683
2740
  case 0:
2684
2741
  options = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : {};
2685
2742
  _context16.next = 3;
2686
- return this._update(_objectSpread$7({
2743
+ return this._update(_objectSpread$9({
2687
2744
  add_moderators: members,
2688
2745
  message: message
2689
2746
  }, options));
@@ -2726,7 +2783,7 @@ var Channel = /*#__PURE__*/function () {
2726
2783
  case 0:
2727
2784
  options = _args17.length > 2 && _args17[2] !== undefined ? _args17[2] : {};
2728
2785
  _context17.next = 3;
2729
- return this._update(_objectSpread$7({
2786
+ return this._update(_objectSpread$9({
2730
2787
  assign_roles: roles,
2731
2788
  message: message
2732
2789
  }, options));
@@ -2769,7 +2826,7 @@ var Channel = /*#__PURE__*/function () {
2769
2826
  case 0:
2770
2827
  options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
2771
2828
  _context18.next = 3;
2772
- return this._update(_objectSpread$7({
2829
+ return this._update(_objectSpread$9({
2773
2830
  invites: members,
2774
2831
  message: message
2775
2832
  }, options));
@@ -2812,7 +2869,7 @@ var Channel = /*#__PURE__*/function () {
2812
2869
  case 0:
2813
2870
  options = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : {};
2814
2871
  _context19.next = 3;
2815
- return this._update(_objectSpread$7({
2872
+ return this._update(_objectSpread$9({
2816
2873
  remove_members: members,
2817
2874
  message: message
2818
2875
  }, options));
@@ -2855,7 +2912,7 @@ var Channel = /*#__PURE__*/function () {
2855
2912
  case 0:
2856
2913
  options = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2857
2914
  _context20.next = 3;
2858
- return this._update(_objectSpread$7({
2915
+ return this._update(_objectSpread$9({
2859
2916
  demote_moderators: members,
2860
2917
  message: message
2861
2918
  }, options));
@@ -2940,7 +2997,7 @@ var Channel = /*#__PURE__*/function () {
2940
2997
  case 0:
2941
2998
  opts = _args22.length > 0 && _args22[0] !== undefined ? _args22[0] : {};
2942
2999
  _context22.next = 3;
2943
- return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$7({
3000
+ return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$9({
2944
3001
  channel_cid: this.cid
2945
3002
  }, opts));
2946
3003
 
@@ -2982,7 +3039,7 @@ var Channel = /*#__PURE__*/function () {
2982
3039
  case 0:
2983
3040
  opts = _args23.length > 0 && _args23[0] !== undefined ? _args23[0] : {};
2984
3041
  _context23.next = 3;
2985
- return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$7({
3042
+ return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$9({
2986
3043
  channel_cid: this.cid
2987
3044
  }, opts));
2988
3045
 
@@ -3067,7 +3124,7 @@ var Channel = /*#__PURE__*/function () {
3067
3124
 
3068
3125
  this.lastTypingEvent = new Date();
3069
3126
  _context24.next = 10;
3070
- return this.sendEvent(_objectSpread$7({
3127
+ return this.sendEvent(_objectSpread$9({
3071
3128
  type: 'typing.start',
3072
3129
  parent_id: parent_id
3073
3130
  }, options || {}));
@@ -3111,7 +3168,7 @@ var Channel = /*#__PURE__*/function () {
3111
3168
  this.lastTypingEvent = null;
3112
3169
  this.isTyping = false;
3113
3170
  _context25.next = 6;
3114
- return this.sendEvent(_objectSpread$7({
3171
+ return this.sendEvent(_objectSpread$9({
3115
3172
  type: 'typing.stop',
3116
3173
  parent_id: parent_id
3117
3174
  }, options || {}));
@@ -3198,7 +3255,7 @@ var Channel = /*#__PURE__*/function () {
3198
3255
 
3199
3256
  case 4:
3200
3257
  _context26.next = 6;
3201
- return this.getClient().post(this._channelURL() + '/read', _objectSpread$7({}, data));
3258
+ return this.getClient().post(this._channelURL() + '/read', _objectSpread$9({}, data));
3202
3259
 
3203
3260
  case 6:
3204
3261
  return _context26.abrupt("return", _context26.sent);
@@ -3245,7 +3302,7 @@ var Channel = /*#__PURE__*/function () {
3245
3302
 
3246
3303
  case 3:
3247
3304
  _context27.next = 5;
3248
- return this.getClient().post(this._channelURL() + '/unread', _objectSpread$7({}, data));
3305
+ return this.getClient().post(this._channelURL() + '/unread', _objectSpread$9({}, data));
3249
3306
 
3250
3307
  case 5:
3251
3308
  return _context27.abrupt("return", _context27.sent);
@@ -3313,7 +3370,7 @@ var Channel = /*#__PURE__*/function () {
3313
3370
  defaultOptions.watch = false;
3314
3371
  }
3315
3372
 
3316
- combined = _objectSpread$7(_objectSpread$7({}, defaultOptions), options);
3373
+ combined = _objectSpread$9(_objectSpread$9({}, defaultOptions), options);
3317
3374
  _context28.next = 7;
3318
3375
  return this.query(combined, 'latest');
3319
3376
 
@@ -3386,7 +3443,9 @@ var Channel = /*#__PURE__*/function () {
3386
3443
  return stopWatching;
3387
3444
  }()
3388
3445
  /**
3389
- * getReplies - List the message replies for a parent message
3446
+ * getReplies - List the message replies for a parent message.
3447
+ *
3448
+ * The recommended way of working with threads is to use the Thread class.
3390
3449
  *
3391
3450
  * @param {string} parent_id The message parent id, ie the top of the thread
3392
3451
  * @param {MessagePaginationOptions & { user?: UserResponse<StreamChatGenerics>; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
@@ -3405,7 +3464,7 @@ var Channel = /*#__PURE__*/function () {
3405
3464
  case 0:
3406
3465
  normalizedSort = sort ? normalizeQuerySort(sort) : undefined;
3407
3466
  _context30.next = 3;
3408
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(parent_id), "/replies"), _objectSpread$7({
3467
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(parent_id), "/replies"), _objectSpread$9({
3409
3468
  sort: normalizedSort
3410
3469
  }, options));
3411
3470
 
@@ -3455,7 +3514,7 @@ var Channel = /*#__PURE__*/function () {
3455
3514
  sort = _args31.length > 1 && _args31[1] !== undefined ? _args31[1] : [];
3456
3515
  _context31.next = 3;
3457
3516
  return this.getClient().get(this._channelURL() + '/pinned_messages', {
3458
- payload: _objectSpread$7(_objectSpread$7({}, options), {}, {
3517
+ payload: _objectSpread$9(_objectSpread$9({}, options), {}, {
3459
3518
  sort: normalizeQuerySort(sort)
3460
3519
  })
3461
3520
  });
@@ -3489,7 +3548,7 @@ var Channel = /*#__PURE__*/function () {
3489
3548
  }, {
3490
3549
  key: "getReactions",
3491
3550
  value: function getReactions(message_id, options) {
3492
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(message_id), "/reactions"), _objectSpread$7({}, options));
3551
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(message_id), "/reactions"), _objectSpread$9({}, options));
3493
3552
  }
3494
3553
  /**
3495
3554
  * getMessagesById - Retrieves a list of messages by ID
@@ -3637,7 +3696,7 @@ var Channel = /*#__PURE__*/function () {
3637
3696
  }
3638
3697
 
3639
3698
  _context32.next = 7;
3640
- return this.getClient().post(queryURL + '/query', _objectSpread$7({
3699
+ return this.getClient().post(queryURL + '/query', _objectSpread$9({
3641
3700
  data: this._data,
3642
3701
  state: true
3643
3702
  }, options));
@@ -3672,7 +3731,7 @@ var Channel = /*#__PURE__*/function () {
3672
3731
 
3673
3732
 
3674
3733
  _this$_initializeStat = this._initializeState(state, messageSetToAddToIfDoesNotExist), messageSet = _this$_initializeStat.messageSet;
3675
- messageSet.pagination = _objectSpread$7(_objectSpread$7({}, messageSet.pagination), messageSetPagination({
3734
+ messageSet.pagination = _objectSpread$9(_objectSpread$9({}, messageSet.pagination), messageSetPagination({
3676
3735
  parentSet: messageSet,
3677
3736
  messagePaginationOptions: options === null || options === void 0 ? void 0 : options.messages,
3678
3737
  requestedPageSize: (_options$messages$lim = options === null || options === void 0 ? void 0 : (_options$messages = options.messages) === null || _options$messages === void 0 ? void 0 : _options$messages.limit) !== null && _options$messages$lim !== void 0 ? _options$messages$lim : DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE,
@@ -3733,7 +3792,7 @@ var Channel = /*#__PURE__*/function () {
3733
3792
  this._checkInitialized();
3734
3793
 
3735
3794
  _context33.next = 3;
3736
- return this.getClient().banUser(targetUserID, _objectSpread$7(_objectSpread$7({}, options), {}, {
3795
+ return this.getClient().banUser(targetUserID, _objectSpread$9(_objectSpread$9({}, options), {}, {
3737
3796
  type: this.type,
3738
3797
  id: this.id
3739
3798
  }));
@@ -3905,7 +3964,7 @@ var Channel = /*#__PURE__*/function () {
3905
3964
  this._checkInitialized();
3906
3965
 
3907
3966
  _context37.next = 3;
3908
- return this.getClient().shadowBan(targetUserID, _objectSpread$7(_objectSpread$7({}, options), {}, {
3967
+ return this.getClient().shadowBan(targetUserID, _objectSpread$9(_objectSpread$9({}, options), {}, {
3909
3968
  type: this.type,
3910
3969
  id: this.id
3911
3970
  }));
@@ -4359,7 +4418,7 @@ var Channel = /*#__PURE__*/function () {
4359
4418
  });
4360
4419
  }
4361
4420
 
4362
- channel.data = _objectSpread$7(_objectSpread$7({}, event.channel), {}, {
4421
+ channel.data = _objectSpread$9(_objectSpread$9({}, event.channel), {}, {
4363
4422
  hidden: (_event$channel$hidden = (_event$channel3 = event.channel) === null || _event$channel3 === void 0 ? void 0 : _event$channel3.hidden) !== null && _event$channel$hidden !== void 0 ? _event$channel$hidden : (_channel$data2 = channel.data) === null || _channel$data2 === void 0 ? void 0 : _channel$data2.hidden,
4364
4423
  own_capabilities: (_event$channel$own_ca = (_event$channel4 = event.channel) === null || _event$channel4 === void 0 ? void 0 : _event$channel4.own_capabilities) !== null && _event$channel$own_ca !== void 0 ? _event$channel$own_ca : (_channel$data3 = channel.data) === null || _channel$data3 === void 0 ? void 0 : _channel$data3.own_capabilities
4365
4424
  });
@@ -4433,7 +4492,7 @@ var Channel = /*#__PURE__*/function () {
4433
4492
  break;
4434
4493
 
4435
4494
  case 'channel.hidden':
4436
- channel.data = _objectSpread$7(_objectSpread$7({}, channel.data), {}, {
4495
+ channel.data = _objectSpread$9(_objectSpread$9({}, channel.data), {}, {
4437
4496
  hidden: true
4438
4497
  });
4439
4498
 
@@ -4444,26 +4503,26 @@ var Channel = /*#__PURE__*/function () {
4444
4503
  break;
4445
4504
 
4446
4505
  case 'channel.visible':
4447
- channel.data = _objectSpread$7(_objectSpread$7({}, channel.data), {}, {
4506
+ channel.data = _objectSpread$9(_objectSpread$9({}, channel.data), {}, {
4448
4507
  hidden: false
4449
4508
  });
4450
4509
  break;
4451
4510
 
4452
4511
  case 'user.banned':
4453
4512
  if (!((_event$user11 = event.user) !== null && _event$user11 !== void 0 && _event$user11.id)) break;
4454
- channelState.members[event.user.id] = _objectSpread$7(_objectSpread$7({}, channelState.members[event.user.id] || {}), {}, {
4513
+ channelState.members[event.user.id] = _objectSpread$9(_objectSpread$9({}, channelState.members[event.user.id] || {}), {}, {
4455
4514
  shadow_banned: !!event.shadow,
4456
4515
  banned: !event.shadow,
4457
- user: _objectSpread$7(_objectSpread$7({}, ((_channelState$members = channelState.members[event.user.id]) === null || _channelState$members === void 0 ? void 0 : _channelState$members.user) || {}), event.user)
4516
+ user: _objectSpread$9(_objectSpread$9({}, ((_channelState$members = channelState.members[event.user.id]) === null || _channelState$members === void 0 ? void 0 : _channelState$members.user) || {}), event.user)
4458
4517
  });
4459
4518
  break;
4460
4519
 
4461
4520
  case 'user.unbanned':
4462
4521
  if (!((_event$user12 = event.user) !== null && _event$user12 !== void 0 && _event$user12.id)) break;
4463
- channelState.members[event.user.id] = _objectSpread$7(_objectSpread$7({}, channelState.members[event.user.id] || {}), {}, {
4522
+ channelState.members[event.user.id] = _objectSpread$9(_objectSpread$9({}, channelState.members[event.user.id] || {}), {}, {
4464
4523
  shadow_banned: false,
4465
4524
  banned: false,
4466
- user: _objectSpread$7(_objectSpread$7({}, ((_channelState$members2 = channelState.members[event.user.id]) === null || _channelState$members2 === void 0 ? void 0 : _channelState$members2.user) || {}), event.user)
4525
+ user: _objectSpread$9(_objectSpread$9({}, ((_channelState$members2 = channelState.members[event.user.id]) === null || _channelState$members2 === void 0 ? void 0 : _channelState$members2.user) || {}), event.user)
4467
4526
  });
4468
4527
  break;
4469
4528
  } // any event can send over the online count
@@ -4717,9 +4776,9 @@ var ClientState = /*#__PURE__*/function () {
4717
4776
  return ClientState;
4718
4777
  }();
4719
4778
 
4720
- function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4779
+ function ownKeys$8(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4721
4780
 
4722
- function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4781
+ function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4723
4782
  var InsightMetrics = function InsightMetrics() {
4724
4783
  _classCallCheck(this, InsightMetrics);
4725
4784
 
@@ -4798,7 +4857,7 @@ var postInsights = /*#__PURE__*/function () {
4798
4857
  };
4799
4858
  }();
4800
4859
  function buildWsFatalInsight(connection, event) {
4801
- return _objectSpread$6(_objectSpread$6({}, event), buildWsBaseInsight(connection));
4860
+ return _objectSpread$8(_objectSpread$8({}, event), buildWsBaseInsight(connection));
4802
4861
  }
4803
4862
 
4804
4863
  function buildWsBaseInsight(connection) {
@@ -4831,9 +4890,9 @@ function buildWsSuccessAfterFailureInsight(connection) {
4831
4890
  return buildWsBaseInsight(connection);
4832
4891
  }
4833
4892
 
4834
- function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4893
+ function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4835
4894
 
4836
- function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4895
+ function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4837
4896
 
4838
4897
  // Type guards to check WebSocket error type
4839
4898
  var isCloseEvent = function isCloseEvent(res) {
@@ -5197,7 +5256,7 @@ var StableWSConnection = /*#__PURE__*/function () {
5197
5256
  value: function _log(msg) {
5198
5257
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5199
5258
  var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
5200
- this.client.logger(level, 'connection:' + msg, _objectSpread$5({
5259
+ this.client.logger(level, 'connection:' + msg, _objectSpread$7({
5201
5260
  tags: ['connection']
5202
5261
  }, extra));
5203
5262
  }
@@ -5792,9 +5851,9 @@ var jwt = null;
5792
5851
 
5793
5852
  var crypto$1 = null;
5794
5853
 
5795
- function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
5854
+ function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
5796
5855
 
5797
- function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5856
+ function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
5798
5857
 
5799
5858
  /**
5800
5859
  * Creates the JWT token that can be used for a UserSession
@@ -5815,7 +5874,7 @@ function JWTUserToken(apiSecret, userId) {
5815
5874
  throw new TypeError('userId should be a string');
5816
5875
  }
5817
5876
 
5818
- var payload = _objectSpread$4({
5877
+ var payload = _objectSpread$6({
5819
5878
  user_id: userId
5820
5879
  }, extraData); // make sure we return a clear error when jwt is shimmed (ie. browser build)
5821
5880
 
@@ -6219,9 +6278,9 @@ function isErrorResponse(res) {
6219
6278
  return !res.status || res.status < 200 || 300 <= res.status;
6220
6279
  }
6221
6280
 
6222
- function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6281
+ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6223
6282
 
6224
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6283
+ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6225
6284
  var ConnectionState;
6226
6285
 
6227
6286
  (function (ConnectionState) {
@@ -6284,7 +6343,7 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6284
6343
  _context.next = 4;
6285
6344
  return _this.client.doAxiosRequest('get', _this.client.baseURL.replace(':3030', ':8900') + '/longpoll', // replace port if present for testing with local API
6286
6345
  undefined, {
6287
- config: _objectSpread$3(_objectSpread$3({}, config), {}, {
6346
+ config: _objectSpread$5(_objectSpread$5({}, config), {}, {
6288
6347
  cancelToken: (_this$cancelToken2 = _this.cancelToken) === null || _this$cancelToken2 === void 0 ? void 0 : _this$cancelToken2.token
6289
6348
  }),
6290
6349
  params: params
@@ -6562,7 +6621,7 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6562
6621
  value: function _log(msg) {
6563
6622
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6564
6623
  var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
6565
- this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$3({
6624
+ this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$5({
6566
6625
  tags: ['connection_fallback', 'connection']
6567
6626
  }, extra));
6568
6627
  }
@@ -7142,196 +7201,738 @@ var VotingVisibility;
7142
7201
  VotingVisibility["public"] = "public";
7143
7202
  })(VotingVisibility || (VotingVisibility = {}));
7144
7203
 
7145
- var _excluded$1 = ["parent_message_id", "parent_message", "latest_replies", "thread_participants", "reply_count", "channel", "read"];
7204
+ function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7146
7205
 
7147
- function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7206
+ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7148
7207
 
7149
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7208
+ function isPatch(value) {
7209
+ return typeof value === 'function';
7210
+ }
7150
7211
 
7151
- function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
7212
+ var StateStore = function StateStore(value) {
7213
+ var _this = this;
7152
7214
 
7153
- function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
7215
+ _classCallCheck(this, StateStore);
7154
7216
 
7155
- function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
7217
+ this.value = value;
7218
+
7219
+ _defineProperty(this, "handlerSet", new Set());
7220
+
7221
+ _defineProperty(this, "next", function (newValueOrPatch) {
7222
+ // newValue (or patch output) should never be mutated previous value
7223
+ var newValue = isPatch(newValueOrPatch) ? newValueOrPatch(_this.value) : newValueOrPatch; // do not notify subscribers if the value hasn't changed
7224
+
7225
+ if (newValue === _this.value) return;
7226
+ var oldValue = _this.value;
7227
+ _this.value = newValue;
7228
+
7229
+ _this.handlerSet.forEach(function (handler) {
7230
+ return handler(_this.value, oldValue);
7231
+ });
7232
+ });
7233
+
7234
+ _defineProperty(this, "partialNext", function (partial) {
7235
+ return _this.next(function (current) {
7236
+ return _objectSpread$4(_objectSpread$4({}, current), partial);
7237
+ });
7238
+ });
7239
+
7240
+ _defineProperty(this, "getLatestValue", function () {
7241
+ return _this.value;
7242
+ });
7243
+
7244
+ _defineProperty(this, "subscribe", function (handler) {
7245
+ handler(_this.value, undefined);
7246
+
7247
+ _this.handlerSet.add(handler);
7248
+
7249
+ return function () {
7250
+ _this.handlerSet.delete(handler);
7251
+ };
7252
+ });
7253
+
7254
+ _defineProperty(this, "subscribeWithSelector", function (selector, handler) {
7255
+ // begin with undefined to reduce amount of selector calls
7256
+ var selectedValues;
7257
+
7258
+ var wrappedHandler = function wrappedHandler(nextValue) {
7259
+ var _selectedValues$some, _selectedValues;
7260
+
7261
+ var newlySelectedValues = selector(nextValue);
7262
+ var hasUpdatedValues = (_selectedValues$some = (_selectedValues = selectedValues) === null || _selectedValues === void 0 ? void 0 : _selectedValues.some(function (value, index) {
7263
+ return value !== newlySelectedValues[index];
7264
+ })) !== null && _selectedValues$some !== void 0 ? _selectedValues$some : true;
7265
+ if (!hasUpdatedValues) return;
7266
+ var oldSelectedValues = selectedValues;
7267
+ selectedValues = newlySelectedValues;
7268
+ handler(newlySelectedValues, oldSelectedValues);
7269
+ };
7270
+
7271
+ return _this.subscribe(wrappedHandler);
7272
+ });
7273
+ };
7274
+
7275
+ var _excluded$1 = ["limit", "sort"];
7276
+
7277
+ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7278
+
7279
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7280
+ var DEFAULT_PAGE_LIMIT = 50;
7281
+ var DEFAULT_SORT = [{
7282
+ created_at: -1
7283
+ }];
7284
+ var MARK_AS_READ_THROTTLE_TIMEOUT = 1000;
7156
7285
  var Thread = /*#__PURE__*/function () {
7157
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7158
- function Thread(client, t) {
7286
+ function Thread(_ref) {
7287
+ var _this = this,
7288
+ _threadData$read,
7289
+ _threadData$reply_cou;
7290
+
7291
+ var client = _ref.client,
7292
+ threadData = _ref.threadData;
7293
+
7159
7294
  _classCallCheck(this, Thread);
7160
7295
 
7296
+ _defineProperty(this, "state", void 0);
7297
+
7161
7298
  _defineProperty(this, "id", void 0);
7162
7299
 
7163
- _defineProperty(this, "latestReplies", []);
7300
+ _defineProperty(this, "client", void 0);
7164
7301
 
7165
- _defineProperty(this, "participants", []);
7302
+ _defineProperty(this, "unsubscribeFunctions", new Set());
7166
7303
 
7167
- _defineProperty(this, "message", void 0);
7304
+ _defineProperty(this, "failedRepliesMap", new Map());
7168
7305
 
7169
- _defineProperty(this, "channel", void 0);
7306
+ _defineProperty(this, "activate", function () {
7307
+ _this.state.partialNext({
7308
+ active: true
7309
+ });
7310
+ });
7170
7311
 
7171
- _defineProperty(this, "_channel", void 0);
7312
+ _defineProperty(this, "deactivate", function () {
7313
+ _this.state.partialNext({
7314
+ active: false
7315
+ });
7316
+ });
7172
7317
 
7173
- _defineProperty(this, "replyCount", 0);
7318
+ _defineProperty(this, "reload", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
7319
+ var thread;
7320
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
7321
+ while (1) {
7322
+ switch (_context.prev = _context.next) {
7323
+ case 0:
7324
+ if (!_this.state.getLatestValue().isLoading) {
7325
+ _context.next = 2;
7326
+ break;
7327
+ }
7174
7328
 
7175
- _defineProperty(this, "_client", void 0);
7329
+ return _context.abrupt("return");
7176
7330
 
7177
- _defineProperty(this, "read", {});
7178
-
7179
- _defineProperty(this, "data", {});
7180
-
7181
- var parent_message_id = t.parent_message_id,
7182
- parent_message = t.parent_message,
7183
- latest_replies = t.latest_replies,
7184
- thread_participants = t.thread_participants,
7185
- reply_count = t.reply_count,
7186
- channel = t.channel,
7187
- read = t.read,
7188
- data = _objectWithoutProperties(t, _excluded$1);
7189
-
7190
- this.id = parent_message_id;
7191
- this.message = formatMessage(parent_message);
7192
- this.latestReplies = latest_replies.map(formatMessage);
7193
- this.participants = thread_participants;
7194
- this.replyCount = reply_count;
7195
- this.channel = channel;
7196
- this._channel = client.channel(t.channel.type, t.channel.id);
7197
- this._client = client;
7331
+ case 2:
7332
+ _this.state.partialNext({
7333
+ isLoading: true
7334
+ });
7198
7335
 
7199
- if (read) {
7200
- var _iterator = _createForOfIteratorHelper$1(read),
7201
- _step;
7336
+ _context.prev = 3;
7337
+ _context.next = 6;
7338
+ return _this.client.getThread(_this.id, {
7339
+ watch: true
7340
+ });
7202
7341
 
7203
- try {
7204
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
7205
- var r = _step.value;
7206
- this.read[r.user.id] = _objectSpread$2(_objectSpread$2({}, r), {}, {
7207
- last_read: new Date(r.last_read)
7208
- });
7209
- }
7210
- } catch (err) {
7211
- _iterator.e(err);
7212
- } finally {
7213
- _iterator.f();
7214
- }
7215
- }
7342
+ case 6:
7343
+ thread = _context.sent;
7216
7344
 
7217
- this.data = data;
7218
- }
7345
+ _this.hydrateState(thread);
7219
7346
 
7220
- _createClass(Thread, [{
7221
- key: "getClient",
7222
- value: function getClient() {
7223
- return this._client;
7224
- }
7225
- /**
7226
- * addReply - Adds or updates a latestReplies to the thread
7227
- *
7228
- * @param {MessageResponse<StreamChatGenerics>} message reply message to be added.
7229
- */
7347
+ case 8:
7348
+ _context.prev = 8;
7230
7349
 
7231
- }, {
7232
- key: "addReply",
7233
- value: function addReply(message) {
7234
- if (message.parent_id !== this.message.id) {
7235
- throw new Error('Message does not belong to this thread');
7236
- }
7350
+ _this.state.partialNext({
7351
+ isLoading: false
7352
+ });
7237
7353
 
7238
- this.latestReplies = addToMessageList(this.latestReplies, formatMessage(message), true);
7239
- }
7240
- }, {
7241
- key: "updateReply",
7242
- value: function updateReply(message) {
7243
- this.latestReplies = this.latestReplies.map(function (m) {
7244
- if (m.id === message.id) {
7245
- return formatMessage(message);
7354
+ return _context.finish(8);
7355
+
7356
+ case 11:
7357
+ case "end":
7358
+ return _context.stop();
7359
+ }
7246
7360
  }
7361
+ }, _callee, null, [[3,, 8, 11]]);
7362
+ })));
7247
7363
 
7248
- return m;
7249
- });
7250
- }
7251
- }, {
7252
- key: "updateMessageOrReplyIfExists",
7253
- value: function updateMessageOrReplyIfExists(message) {
7254
- if (!message.parent_id && message.id !== this.message.id) {
7364
+ _defineProperty(this, "hydrateState", function (thread) {
7365
+ if (thread === _this) {
7366
+ // skip if the instances are the same
7255
7367
  return;
7256
7368
  }
7257
7369
 
7258
- if (message.parent_id && message.parent_id !== this.message.id) {
7259
- return;
7370
+ if (thread.id !== _this.id) {
7371
+ throw new Error("Cannot hydrate thread state with using thread's state");
7260
7372
  }
7261
7373
 
7262
- if (message.parent_id && message.parent_id === this.message.id) {
7263
- this.updateReply(message);
7374
+ var _thread$state$getLate = thread.state.getLatestValue(),
7375
+ read = _thread$state$getLate.read,
7376
+ replyCount = _thread$state$getLate.replyCount,
7377
+ replies = _thread$state$getLate.replies,
7378
+ parentMessage = _thread$state$getLate.parentMessage,
7379
+ participants = _thread$state$getLate.participants,
7380
+ createdAt = _thread$state$getLate.createdAt,
7381
+ deletedAt = _thread$state$getLate.deletedAt,
7382
+ updatedAt = _thread$state$getLate.updatedAt; // Preserve pending replies and append them to the updated list of replies
7383
+
7384
+
7385
+ var pendingReplies = Array.from(_this.failedRepliesMap.values());
7386
+
7387
+ _this.state.partialNext({
7388
+ read: read,
7389
+ replyCount: replyCount,
7390
+ replies: pendingReplies.length ? replies.concat(pendingReplies) : replies,
7391
+ parentMessage: parentMessage,
7392
+ participants: participants,
7393
+ createdAt: createdAt,
7394
+ deletedAt: deletedAt,
7395
+ updatedAt: updatedAt,
7396
+ isStateStale: false
7397
+ });
7398
+ });
7399
+
7400
+ _defineProperty(this, "registerSubscriptions", function () {
7401
+ if (_this.unsubscribeFunctions.size) {
7402
+ // Thread is already listening for events and changes
7264
7403
  return;
7265
7404
  }
7266
7405
 
7267
- if (!message.parent_id && message.id === this.message.id) {
7268
- this.message = formatMessage(message);
7269
- }
7270
- }
7271
- }, {
7272
- key: "addReaction",
7273
- value: function addReaction(reaction, message, enforce_unique) {
7274
- var _this = this;
7406
+ _this.unsubscribeFunctions.add(_this.subscribeMarkActiveThreadRead());
7275
7407
 
7276
- if (!message) return;
7277
- this.latestReplies = this.latestReplies.map(function (m) {
7278
- if (m.id === message.id) {
7279
- return formatMessage(_this._channel.state.addReaction(reaction, message, enforce_unique));
7280
- }
7408
+ _this.unsubscribeFunctions.add(_this.subscribeReloadActiveStaleThread());
7409
+
7410
+ _this.unsubscribeFunctions.add(_this.subscribeMarkThreadStale());
7411
+
7412
+ _this.unsubscribeFunctions.add(_this.subscribeNewReplies());
7413
+
7414
+ _this.unsubscribeFunctions.add(_this.subscribeRepliesRead());
7415
+
7416
+ _this.unsubscribeFunctions.add(_this.subscribeReplyDeleted());
7417
+
7418
+ _this.unsubscribeFunctions.add(_this.subscribeMessageUpdated());
7419
+ });
7420
+
7421
+ _defineProperty(this, "subscribeMarkActiveThreadRead", function () {
7422
+ return _this.state.subscribeWithSelector(function (nextValue) {
7423
+ return [nextValue.active, ownUnreadCountSelector(_this.client.userID)(nextValue)];
7424
+ }, function (_ref3) {
7425
+ var _ref4 = _slicedToArray(_ref3, 2),
7426
+ active = _ref4[0],
7427
+ unreadMessageCount = _ref4[1];
7281
7428
 
7282
- return m;
7429
+ if (!active || !unreadMessageCount) return;
7430
+
7431
+ _this.throttledMarkAsRead();
7283
7432
  });
7284
- }
7285
- }, {
7286
- key: "removeReaction",
7287
- value: function removeReaction(reaction, message) {
7288
- var _this2 = this;
7433
+ });
7289
7434
 
7290
- if (!message) return;
7291
- this.latestReplies = this.latestReplies.map(function (m) {
7292
- if (m.id === message.id) {
7293
- return formatMessage(_this2._channel.state.removeReaction(reaction, message));
7294
- }
7435
+ _defineProperty(this, "subscribeReloadActiveStaleThread", function () {
7436
+ return _this.state.subscribeWithSelector(function (nextValue) {
7437
+ return [nextValue.active, nextValue.isStateStale];
7438
+ }, function (_ref5) {
7439
+ var _ref6 = _slicedToArray(_ref5, 2),
7440
+ active = _ref6[0],
7441
+ isStateStale = _ref6[1];
7295
7442
 
7296
- return m;
7443
+ if (active && isStateStale) {
7444
+ _this.reload();
7445
+ }
7297
7446
  });
7298
- }
7299
- }]);
7447
+ });
7300
7448
 
7301
- return Thread;
7302
- }();
7449
+ _defineProperty(this, "subscribeMarkThreadStale", function () {
7450
+ return _this.client.on('user.watching.stop', function (event) {
7451
+ var _event$user, _event$channel;
7303
7452
 
7304
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7453
+ var _this$state$getLatest = _this.state.getLatestValue(),
7454
+ channel = _this$state$getLatest.channel;
7305
7455
 
7306
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7307
- var MODERATION_ENTITY_TYPES = {
7308
- user: 'stream:user',
7309
- message: 'stream:chat:v1:message'
7310
- }; // Moderation class provides all the endpoints related to moderation v2.
7456
+ if (!_this.client.userID || _this.client.userID !== ((_event$user = event.user) === null || _event$user === void 0 ? void 0 : _event$user.id) || ((_event$channel = event.channel) === null || _event$channel === void 0 ? void 0 : _event$channel.cid) !== channel.cid) {
7457
+ return;
7458
+ }
7311
7459
 
7312
- var Moderation = /*#__PURE__*/function () {
7313
- function Moderation(client) {
7314
- _classCallCheck(this, Moderation);
7460
+ _this.state.partialNext({
7461
+ isStateStale: true
7462
+ });
7463
+ }).unsubscribe;
7464
+ });
7315
7465
 
7316
- _defineProperty(this, "client", void 0);
7466
+ _defineProperty(this, "subscribeNewReplies", function () {
7467
+ return _this.client.on('message.new', function (event) {
7468
+ var _event$message, _event$message$user;
7317
7469
 
7318
- this.client = client;
7319
- }
7320
- /**
7321
- * Flag a user
7322
- *
7323
- * @param {string} flaggedUserID User ID to be flagged
7324
- * @param {string} reason Reason for flagging the user
7325
- * @param {Object} options Additional options for flagging the user
7326
- * @param {string} options.user_id (For server side usage) User ID of the user who is flagging the target user
7327
- * @param {Object} options.custom Additional data to be stored with the flag
7328
- * @returns
7329
- */
7470
+ if (!_this.client.userID || ((_event$message = event.message) === null || _event$message === void 0 ? void 0 : _event$message.parent_id) !== _this.id) {
7471
+ return;
7472
+ }
7330
7473
 
7474
+ var isOwnMessage = ((_event$message$user = event.message.user) === null || _event$message$user === void 0 ? void 0 : _event$message$user.id) === _this.client.userID;
7331
7475
 
7332
- _createClass(Moderation, [{
7333
- key: "flagUser",
7334
- value: function () {
7476
+ var _this$state$getLatest2 = _this.state.getLatestValue(),
7477
+ active = _this$state$getLatest2.active,
7478
+ read = _this$state$getLatest2.read;
7479
+
7480
+ _this.upsertReplyLocally({
7481
+ message: event.message,
7482
+ // Message from current user could have been added optimistically,
7483
+ // so the actual timestamp might differ in the event
7484
+ timestampChanged: isOwnMessage
7485
+ });
7486
+
7487
+ if (active) {
7488
+ _this.throttledMarkAsRead();
7489
+ }
7490
+
7491
+ var nextRead = {};
7492
+
7493
+ for (var _i = 0, _Object$keys = Object.keys(read); _i < _Object$keys.length; _i++) {
7494
+ var userId = _Object$keys[_i];
7495
+ var userRead = read[userId];
7496
+
7497
+ if (userRead) {
7498
+ var _event$user2;
7499
+
7500
+ var nextUserRead = userRead;
7501
+
7502
+ if (userId === ((_event$user2 = event.user) === null || _event$user2 === void 0 ? void 0 : _event$user2.id)) {
7503
+ // The user who just sent a message to the thread has no unread messages
7504
+ // in that thread
7505
+ nextUserRead = _objectSpread$3(_objectSpread$3({}, nextUserRead), {}, {
7506
+ lastReadAt: event.created_at ? new Date(event.created_at) : new Date(),
7507
+ user: event.user,
7508
+ unreadMessageCount: 0
7509
+ });
7510
+ } else if (active && userId === _this.client.userID) ; else {
7511
+ // Increment unread count for all users except the author of the new message
7512
+ nextUserRead = _objectSpread$3(_objectSpread$3({}, nextUserRead), {}, {
7513
+ unreadMessageCount: userRead.unreadMessageCount + 1
7514
+ });
7515
+ }
7516
+
7517
+ nextRead[userId] = nextUserRead;
7518
+ }
7519
+ }
7520
+
7521
+ _this.state.partialNext({
7522
+ read: nextRead
7523
+ });
7524
+ }).unsubscribe;
7525
+ });
7526
+
7527
+ _defineProperty(this, "subscribeRepliesRead", function () {
7528
+ return _this.client.on('message.read', function (event) {
7529
+ if (!event.user || !event.created_at || !event.thread) return;
7530
+ if (event.thread.parent_message_id !== _this.id) return;
7531
+ var userId = event.user.id;
7532
+ var createdAt = event.created_at;
7533
+ var user = event.user;
7534
+
7535
+ _this.state.next(function (current) {
7536
+ return _objectSpread$3(_objectSpread$3({}, current), {}, {
7537
+ read: _objectSpread$3(_objectSpread$3({}, current.read), {}, _defineProperty({}, userId, {
7538
+ lastReadAt: new Date(createdAt),
7539
+ user: user,
7540
+ lastReadMessageId: event.last_read_message_id,
7541
+ unreadMessageCount: 0
7542
+ }))
7543
+ });
7544
+ });
7545
+ }).unsubscribe;
7546
+ });
7547
+
7548
+ _defineProperty(this, "subscribeReplyDeleted", function () {
7549
+ return _this.client.on('message.deleted', function (event) {
7550
+ var _event$message2;
7551
+
7552
+ if (((_event$message2 = event.message) === null || _event$message2 === void 0 ? void 0 : _event$message2.parent_id) === _this.id && event.hard_delete) {
7553
+ return _this.deleteReplyLocally({
7554
+ message: event.message
7555
+ });
7556
+ }
7557
+ }).unsubscribe;
7558
+ });
7559
+
7560
+ _defineProperty(this, "subscribeMessageUpdated", function () {
7561
+ var unsubscribeFunctions = ['message.updated', 'reaction.new', 'reaction.deleted'].map(function (eventType) {
7562
+ return _this.client.on(eventType, function (event) {
7563
+ if (event.message) {
7564
+ _this.updateParentMessageOrReplyLocally(event.message);
7565
+ }
7566
+ }).unsubscribe;
7567
+ });
7568
+ return function () {
7569
+ return unsubscribeFunctions.forEach(function (unsubscribe) {
7570
+ return unsubscribe();
7571
+ });
7572
+ };
7573
+ });
7574
+
7575
+ _defineProperty(this, "unregisterSubscriptions", function () {
7576
+ _this.unsubscribeFunctions.forEach(function (cleanupFunction) {
7577
+ return cleanupFunction();
7578
+ });
7579
+
7580
+ _this.unsubscribeFunctions.clear();
7581
+ });
7582
+
7583
+ _defineProperty(this, "deleteReplyLocally", function (_ref7) {
7584
+ var _replies$index, _replies;
7585
+
7586
+ var message = _ref7.message;
7587
+
7588
+ var _this$state$getLatest3 = _this.state.getLatestValue(),
7589
+ replies = _this$state$getLatest3.replies;
7590
+
7591
+ var index = findIndexInSortedArray({
7592
+ needle: formatMessage(message),
7593
+ sortedArray: replies,
7594
+ sortDirection: 'ascending',
7595
+ selectValueToCompare: function selectValueToCompare(reply) {
7596
+ return reply.created_at.getTime();
7597
+ }
7598
+ });
7599
+ 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;
7600
+
7601
+ if (actualIndex === null) {
7602
+ return;
7603
+ }
7604
+
7605
+ var updatedReplies = _toConsumableArray(replies);
7606
+
7607
+ updatedReplies.splice(actualIndex, 1);
7608
+
7609
+ _this.state.partialNext({
7610
+ replies: updatedReplies
7611
+ });
7612
+ });
7613
+
7614
+ _defineProperty(this, "upsertReplyLocally", function (_ref8) {
7615
+ var message = _ref8.message,
7616
+ _ref8$timestampChange = _ref8.timestampChanged,
7617
+ timestampChanged = _ref8$timestampChange === void 0 ? false : _ref8$timestampChange;
7618
+
7619
+ if (message.parent_id !== _this.id) {
7620
+ throw new Error('Reply does not belong to this thread');
7621
+ }
7622
+
7623
+ var formattedMessage = formatMessage(message);
7624
+
7625
+ if (message.status === 'failed') {
7626
+ // store failed reply so that it's not lost when reloading or hydrating
7627
+ _this.failedRepliesMap.set(formattedMessage.id, formattedMessage);
7628
+ } else if (_this.failedRepliesMap.has(message.id)) {
7629
+ _this.failedRepliesMap.delete(message.id);
7630
+ }
7631
+
7632
+ _this.state.next(function (current) {
7633
+ return _objectSpread$3(_objectSpread$3({}, current), {}, {
7634
+ replies: addToMessageList(current.replies, formattedMessage, timestampChanged)
7635
+ });
7636
+ });
7637
+ });
7638
+
7639
+ _defineProperty(this, "updateParentMessageLocally", function (message) {
7640
+ if (message.id !== _this.id) {
7641
+ throw new Error('Message does not belong to this thread');
7642
+ }
7643
+
7644
+ _this.state.next(function (current) {
7645
+ var _message$reply_count;
7646
+
7647
+ var formattedMessage = formatMessage(message);
7648
+
7649
+ var newData = _objectSpread$3(_objectSpread$3({}, current), {}, {
7650
+ deletedAt: formattedMessage.deleted_at,
7651
+ parentMessage: formattedMessage,
7652
+ replyCount: (_message$reply_count = message.reply_count) !== null && _message$reply_count !== void 0 ? _message$reply_count : current.replyCount
7653
+ }); // update channel on channelData change (unlikely but handled anyway)
7654
+
7655
+
7656
+ if (message.channel) {
7657
+ newData['channel'] = _this.client.channel(message.channel.type, message.channel.id, message.channel);
7658
+ }
7659
+
7660
+ return newData;
7661
+ });
7662
+ });
7663
+
7664
+ _defineProperty(this, "updateParentMessageOrReplyLocally", function (message) {
7665
+ if (message.parent_id === _this.id) {
7666
+ _this.upsertReplyLocally({
7667
+ message: message
7668
+ });
7669
+ }
7670
+
7671
+ if (!message.parent_id && message.id === _this.id) {
7672
+ _this.updateParentMessageLocally(message);
7673
+ }
7674
+ });
7675
+
7676
+ _defineProperty(this, "markAsRead", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
7677
+ var _ref10,
7678
+ _ref10$force,
7679
+ force,
7680
+ _args2 = arguments;
7681
+
7682
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
7683
+ while (1) {
7684
+ switch (_context2.prev = _context2.next) {
7685
+ case 0:
7686
+ _ref10 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref10$force = _ref10.force, force = _ref10$force === void 0 ? false : _ref10$force;
7687
+
7688
+ if (!(_this.ownUnreadCount === 0 && !force)) {
7689
+ _context2.next = 3;
7690
+ break;
7691
+ }
7692
+
7693
+ return _context2.abrupt("return", null);
7694
+
7695
+ case 3:
7696
+ _context2.next = 5;
7697
+ return _this.channel.markRead({
7698
+ thread_id: _this.id
7699
+ });
7700
+
7701
+ case 5:
7702
+ return _context2.abrupt("return", _context2.sent);
7703
+
7704
+ case 6:
7705
+ case "end":
7706
+ return _context2.stop();
7707
+ }
7708
+ }
7709
+ }, _callee2);
7710
+ })));
7711
+
7712
+ _defineProperty(this, "throttledMarkAsRead", throttle(function () {
7713
+ return _this.markAsRead();
7714
+ }, MARK_AS_READ_THROTTLE_TIMEOUT, {
7715
+ trailing: true
7716
+ }));
7717
+
7718
+ _defineProperty(this, "queryReplies", function () {
7719
+ var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7720
+
7721
+ var _ref11$limit = _ref11.limit,
7722
+ limit = _ref11$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref11$limit,
7723
+ _ref11$sort = _ref11.sort,
7724
+ sort = _ref11$sort === void 0 ? DEFAULT_SORT : _ref11$sort,
7725
+ otherOptions = _objectWithoutProperties(_ref11, _excluded$1);
7726
+
7727
+ return _this.channel.getReplies(_this.id, _objectSpread$3({
7728
+ limit: limit
7729
+ }, otherOptions), sort);
7730
+ });
7731
+
7732
+ _defineProperty(this, "loadNextPage", function () {
7733
+ var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7734
+ _ref12$limit = _ref12.limit,
7735
+ limit = _ref12$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref12$limit;
7736
+
7737
+ return _this.loadPage(limit);
7738
+ });
7739
+
7740
+ _defineProperty(this, "loadPrevPage", function () {
7741
+ var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7742
+ _ref13$limit = _ref13.limit,
7743
+ limit = _ref13$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref13$limit;
7744
+
7745
+ return _this.loadPage(-limit);
7746
+ });
7747
+
7748
+ _defineProperty(this, "loadPage", /*#__PURE__*/function () {
7749
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(count) {
7750
+ var _this$state$getLatest4, pagination, _ref15, _ref16, loadingKey, cursorKey, insertionMethodKey, queryOptions, limit, _replies$at$id, _replies$at, data, replies, maybeNextCursor;
7751
+
7752
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
7753
+ while (1) {
7754
+ switch (_context3.prev = _context3.next) {
7755
+ case 0:
7756
+ _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
7757
+ _ref15 = count > 0 ? ['isLoadingNext', 'nextCursor', 'push'] : ['isLoadingPrev', 'prevCursor', 'unshift'], _ref16 = _slicedToArray(_ref15, 3), loadingKey = _ref16[0], cursorKey = _ref16[1], insertionMethodKey = _ref16[2];
7758
+
7759
+ if (!(pagination[loadingKey] || pagination[cursorKey] === null)) {
7760
+ _context3.next = 4;
7761
+ break;
7762
+ }
7763
+
7764
+ return _context3.abrupt("return");
7765
+
7766
+ case 4:
7767
+ queryOptions = _defineProperty({}, count > 0 ? 'id_gt' : 'id_lt', pagination[cursorKey]);
7768
+ limit = Math.abs(count);
7769
+
7770
+ _this.state.partialNext({
7771
+ pagination: _objectSpread$3(_objectSpread$3({}, pagination), {}, _defineProperty({}, loadingKey, true))
7772
+ });
7773
+
7774
+ _context3.prev = 7;
7775
+ _context3.next = 10;
7776
+ return _this.queryReplies(_objectSpread$3(_objectSpread$3({}, queryOptions), {}, {
7777
+ limit: limit
7778
+ }));
7779
+
7780
+ case 10:
7781
+ data = _context3.sent;
7782
+ replies = data.messages.map(formatMessage);
7783
+ maybeNextCursor = (_replies$at$id = (_replies$at = replies.at(count > 0 ? -1 : 0)) === null || _replies$at === void 0 ? void 0 : _replies$at.id) !== null && _replies$at$id !== void 0 ? _replies$at$id : null;
7784
+
7785
+ _this.state.next(function (current) {
7786
+ var _objectSpread4;
7787
+
7788
+ var nextReplies = current.replies; // prevent re-creating array if there's nothing to add to the current one
7789
+
7790
+ if (replies.length > 0) {
7791
+ var _nextReplies;
7792
+
7793
+ nextReplies = _toConsumableArray(current.replies);
7794
+
7795
+ (_nextReplies = nextReplies)[insertionMethodKey].apply(_nextReplies, _toConsumableArray(replies));
7796
+ }
7797
+
7798
+ return _objectSpread$3(_objectSpread$3({}, current), {}, {
7799
+ replies: nextReplies,
7800
+ pagination: _objectSpread$3(_objectSpread$3({}, current.pagination), {}, (_objectSpread4 = {}, _defineProperty(_objectSpread4, cursorKey, data.messages.length < limit ? null : maybeNextCursor), _defineProperty(_objectSpread4, loadingKey, false), _objectSpread4))
7801
+ });
7802
+ });
7803
+
7804
+ _context3.next = 20;
7805
+ break;
7806
+
7807
+ case 16:
7808
+ _context3.prev = 16;
7809
+ _context3.t0 = _context3["catch"](7);
7810
+
7811
+ _this.client.logger('error', _context3.t0.message);
7812
+
7813
+ _this.state.next(function (current) {
7814
+ return _objectSpread$3(_objectSpread$3({}, current), {}, {
7815
+ pagination: _objectSpread$3(_objectSpread$3({}, current.pagination), {}, _defineProperty({}, loadingKey, false))
7816
+ });
7817
+ });
7818
+
7819
+ case 20:
7820
+ case "end":
7821
+ return _context3.stop();
7822
+ }
7823
+ }
7824
+ }, _callee3, null, [[7, 16]]);
7825
+ }));
7826
+
7827
+ return function (_x) {
7828
+ return _ref14.apply(this, arguments);
7829
+ };
7830
+ }());
7831
+
7832
+ this.state = new StateStore({
7833
+ active: false,
7834
+ channel: client.channel(threadData.channel.type, threadData.channel.id),
7835
+ createdAt: new Date(threadData.created_at),
7836
+ deletedAt: threadData.deleted_at ? new Date(threadData.deleted_at) : null,
7837
+ isLoading: false,
7838
+ isStateStale: false,
7839
+ pagination: repliesPaginationFromInitialThread(threadData),
7840
+ parentMessage: formatMessage(threadData.parent_message),
7841
+ participants: threadData.thread_participants,
7842
+ read: formatReadState((_threadData$read = threadData.read) !== null && _threadData$read !== void 0 ? _threadData$read : []),
7843
+ replies: threadData.latest_replies.map(formatMessage),
7844
+ replyCount: (_threadData$reply_cou = threadData.reply_count) !== null && _threadData$reply_cou !== void 0 ? _threadData$reply_cou : 0,
7845
+ updatedAt: threadData.updated_at ? new Date(threadData.updated_at) : null
7846
+ });
7847
+ this.id = threadData.parent_message_id;
7848
+ this.client = client;
7849
+ }
7850
+
7851
+ _createClass(Thread, [{
7852
+ key: "channel",
7853
+ get: function get() {
7854
+ return this.state.getLatestValue().channel;
7855
+ }
7856
+ }, {
7857
+ key: "hasStaleState",
7858
+ get: function get() {
7859
+ return this.state.getLatestValue().isStateStale;
7860
+ }
7861
+ }, {
7862
+ key: "ownUnreadCount",
7863
+ get: function get() {
7864
+ return ownUnreadCountSelector(this.client.userID)(this.state.getLatestValue());
7865
+ }
7866
+ }]);
7867
+
7868
+ return Thread;
7869
+ }();
7870
+
7871
+ var formatReadState = function formatReadState(read) {
7872
+ return read.reduce(function (state, userRead) {
7873
+ var _userRead$unread_mess;
7874
+
7875
+ state[userRead.user.id] = {
7876
+ user: userRead.user,
7877
+ lastReadMessageId: userRead.last_read_message_id,
7878
+ unreadMessageCount: (_userRead$unread_mess = userRead.unread_messages) !== null && _userRead$unread_mess !== void 0 ? _userRead$unread_mess : 0,
7879
+ lastReadAt: new Date(userRead.last_read)
7880
+ };
7881
+ return state;
7882
+ }, {});
7883
+ };
7884
+
7885
+ var repliesPaginationFromInitialThread = function repliesPaginationFromInitialThread(thread) {
7886
+ var _thread$latest_replie, _thread$latest_replie2;
7887
+
7888
+ var latestRepliesContainsAllReplies = thread.latest_replies.length === thread.reply_count;
7889
+ return {
7890
+ nextCursor: null,
7891
+ prevCursor: latestRepliesContainsAllReplies ? null : (_thread$latest_replie = (_thread$latest_replie2 = thread.latest_replies.at(0)) === null || _thread$latest_replie2 === void 0 ? void 0 : _thread$latest_replie2.id) !== null && _thread$latest_replie !== void 0 ? _thread$latest_replie : null,
7892
+ isLoadingNext: false,
7893
+ isLoadingPrev: false
7894
+ };
7895
+ };
7896
+
7897
+ var ownUnreadCountSelector = function ownUnreadCountSelector(currentUserId) {
7898
+ return function (state) {
7899
+ var _state$read$currentUs;
7900
+
7901
+ return currentUserId && ((_state$read$currentUs = state.read[currentUserId]) === null || _state$read$currentUs === void 0 ? void 0 : _state$read$currentUs.unreadMessageCount) || 0;
7902
+ };
7903
+ };
7904
+
7905
+ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
7906
+
7907
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7908
+ var MODERATION_ENTITY_TYPES = {
7909
+ user: 'stream:user',
7910
+ message: 'stream:chat:v1:message'
7911
+ }; // Moderation class provides all the endpoints related to moderation v2.
7912
+
7913
+ var Moderation = /*#__PURE__*/function () {
7914
+ function Moderation(client) {
7915
+ _classCallCheck(this, Moderation);
7916
+
7917
+ _defineProperty(this, "client", void 0);
7918
+
7919
+ this.client = client;
7920
+ }
7921
+ /**
7922
+ * Flag a user
7923
+ *
7924
+ * @param {string} flaggedUserID User ID to be flagged
7925
+ * @param {string} reason Reason for flagging the user
7926
+ * @param {Object} options Additional options for flagging the user
7927
+ * @param {string} options.user_id (For server side usage) User ID of the user who is flagging the target user
7928
+ * @param {Object} options.custom Additional data to be stored with the flag
7929
+ * @returns
7930
+ */
7931
+
7932
+
7933
+ _createClass(Moderation, [{
7934
+ key: "flagUser",
7935
+ value: function () {
7335
7936
  var _flagUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(flaggedUserID, reason) {
7336
7937
  var options,
7337
7938
  _args = arguments;
@@ -7420,7 +8021,7 @@ var Moderation = /*#__PURE__*/function () {
7420
8021
  case 0:
7421
8022
  options = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : {};
7422
8023
  _context3.next = 3;
7423
- return this.client.post(this.client.baseURL + '/api/v2/moderation/flag', _objectSpread$1({
8024
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/flag', _objectSpread$2({
7424
8025
  entity_type: entityType,
7425
8026
  entity_id: entityId,
7426
8027
  entity_creator_id: entityCreatorID,
@@ -7465,7 +8066,7 @@ var Moderation = /*#__PURE__*/function () {
7465
8066
  case 0:
7466
8067
  options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
7467
8068
  _context4.next = 3;
7468
- return this.client.post(this.client.baseURL + '/api/v2/moderation/mute', _objectSpread$1({
8069
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/mute', _objectSpread$2({
7469
8070
  target_ids: [targetID]
7470
8071
  }, options));
7471
8072
 
@@ -7503,7 +8104,7 @@ var Moderation = /*#__PURE__*/function () {
7503
8104
  switch (_context5.prev = _context5.next) {
7504
8105
  case 0:
7505
8106
  _context5.next = 2;
7506
- return this.client.post(this.client.baseURL + '/api/v2/moderation/unmute', _objectSpread$1({
8107
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/unmute', _objectSpread$2({
7507
8108
  target_ids: [targetID]
7508
8109
  }, options));
7509
8110
 
@@ -7545,7 +8146,7 @@ var Moderation = /*#__PURE__*/function () {
7545
8146
  case 0:
7546
8147
  options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
7547
8148
  _context6.next = 3;
7548
- return this.client.get(this.client.baseURL + "/api/v2/moderation/user_report", _objectSpread$1({
8149
+ return this.client.get(this.client.baseURL + "/api/v2/moderation/user_report", _objectSpread$2({
7549
8150
  user_id: userID
7550
8151
  }, options));
7551
8152
 
@@ -7589,7 +8190,7 @@ var Moderation = /*#__PURE__*/function () {
7589
8190
  sort = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : [];
7590
8191
  options = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : {};
7591
8192
  _context7.next = 5;
7592
- return this.client.post(this.client.baseURL + '/api/v2/moderation/review_queue', _objectSpread$1({
8193
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/review_queue', _objectSpread$2({
7593
8194
  filter: filterConditions,
7594
8195
  sort: normalizeQuerySort(sort)
7595
8196
  }, options));
@@ -7692,7 +8293,7 @@ var Moderation = /*#__PURE__*/function () {
7692
8293
  case 0:
7693
8294
  options = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : {};
7694
8295
  _context10.next = 3;
7695
- return this.client.post(this.client.baseURL + '/api/v2/moderation/submit_action', _objectSpread$1({
8296
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/submit_action', _objectSpread$2({
7696
8297
  action_type: actionType,
7697
8298
  item_id: itemID
7698
8299
  }, options));
@@ -7719,6 +8320,454 @@ var Moderation = /*#__PURE__*/function () {
7719
8320
  return Moderation;
7720
8321
  }();
7721
8322
 
8323
+ function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8324
+
8325
+ function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
8326
+
8327
+ function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8328
+
8329
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
8330
+
8331
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8332
+ var DEFAULT_CONNECTION_RECOVERY_THROTTLE_DURATION = 1000;
8333
+ var MAX_QUERY_THREADS_LIMIT = 25;
8334
+ var ThreadManager = /*#__PURE__*/function () {
8335
+ function ThreadManager(_ref) {
8336
+ var _this = this;
8337
+
8338
+ var client = _ref.client;
8339
+
8340
+ _classCallCheck(this, ThreadManager);
8341
+
8342
+ _defineProperty(this, "state", void 0);
8343
+
8344
+ _defineProperty(this, "client", void 0);
8345
+
8346
+ _defineProperty(this, "unsubscribeFunctions", new Set());
8347
+
8348
+ _defineProperty(this, "threadsByIdGetterCache", void 0);
8349
+
8350
+ _defineProperty(this, "activate", function () {
8351
+ _this.state.partialNext({
8352
+ active: true
8353
+ });
8354
+ });
8355
+
8356
+ _defineProperty(this, "deactivate", function () {
8357
+ _this.state.partialNext({
8358
+ active: false
8359
+ });
8360
+ });
8361
+
8362
+ _defineProperty(this, "registerSubscriptions", function () {
8363
+ if (_this.unsubscribeFunctions.size) return;
8364
+
8365
+ _this.unsubscribeFunctions.add(_this.subscribeUnreadThreadsCountChange());
8366
+
8367
+ _this.unsubscribeFunctions.add(_this.subscribeManageThreadSubscriptions());
8368
+
8369
+ _this.unsubscribeFunctions.add(_this.subscribeReloadOnActivation());
8370
+
8371
+ _this.unsubscribeFunctions.add(_this.subscribeNewReplies());
8372
+
8373
+ _this.unsubscribeFunctions.add(_this.subscribeRecoverAfterConnectionDrop());
8374
+ });
8375
+
8376
+ _defineProperty(this, "subscribeUnreadThreadsCountChange", function () {
8377
+ var _ref3;
8378
+
8379
+ // initiate
8380
+ var _ref2 = (_ref3 = _this.client.user) !== null && _ref3 !== void 0 ? _ref3 : {},
8381
+ _ref2$unread_threads = _ref2.unread_threads,
8382
+ unreadThreadCount = _ref2$unread_threads === void 0 ? 0 : _ref2$unread_threads;
8383
+
8384
+ _this.state.partialNext({
8385
+ unreadThreadCount: unreadThreadCount
8386
+ });
8387
+
8388
+ var unsubscribeFunctions = ['health.check', 'notification.mark_read', 'notification.thread_message_new', 'notification.channel_deleted'].map(function (eventType) {
8389
+ return _this.client.on(eventType, function (event) {
8390
+ var _event$me;
8391
+
8392
+ var _ref4 = (_event$me = event.me) !== null && _event$me !== void 0 ? _event$me : event,
8393
+ unreadThreadCount = _ref4.unread_threads;
8394
+
8395
+ if (typeof unreadThreadCount === 'number') {
8396
+ _this.state.partialNext({
8397
+ unreadThreadCount: unreadThreadCount
8398
+ });
8399
+ }
8400
+ }).unsubscribe;
8401
+ });
8402
+ return function () {
8403
+ return unsubscribeFunctions.forEach(function (unsubscribe) {
8404
+ return unsubscribe();
8405
+ });
8406
+ };
8407
+ });
8408
+
8409
+ _defineProperty(this, "subscribeManageThreadSubscriptions", function () {
8410
+ return _this.state.subscribeWithSelector(function (nextValue) {
8411
+ return [nextValue.threads];
8412
+ }, function (_ref5, prev) {
8413
+ var _ref6 = _slicedToArray(_ref5, 1),
8414
+ nextThreads = _ref6[0];
8415
+
8416
+ var _ref7 = prev !== null && prev !== void 0 ? prev : [],
8417
+ _ref8 = _slicedToArray(_ref7, 1),
8418
+ _ref8$ = _ref8[0],
8419
+ prevThreads = _ref8$ === void 0 ? [] : _ref8$; // Thread instance was removed if there's no thread with the given id at all,
8420
+ // or it was replaced with a new instance
8421
+
8422
+
8423
+ var removedThreads = prevThreads.filter(function (thread) {
8424
+ return thread !== _this.threadsById[thread.id];
8425
+ });
8426
+ nextThreads.forEach(function (thread) {
8427
+ return thread.registerSubscriptions();
8428
+ });
8429
+ removedThreads.forEach(function (thread) {
8430
+ return thread.unregisterSubscriptions();
8431
+ });
8432
+ });
8433
+ });
8434
+
8435
+ _defineProperty(this, "subscribeReloadOnActivation", function () {
8436
+ return _this.state.subscribeWithSelector(function (nextValue) {
8437
+ return [nextValue.active];
8438
+ }, function (_ref9) {
8439
+ var _ref10 = _slicedToArray(_ref9, 1),
8440
+ active = _ref10[0];
8441
+
8442
+ if (active) _this.reload();
8443
+ });
8444
+ });
8445
+
8446
+ _defineProperty(this, "subscribeNewReplies", function () {
8447
+ return _this.client.on('notification.thread_message_new', function (event) {
8448
+ var _event$message;
8449
+
8450
+ var parentId = (_event$message = event.message) === null || _event$message === void 0 ? void 0 : _event$message.parent_id;
8451
+ if (!parentId) return;
8452
+
8453
+ var _this$state$getLatest = _this.state.getLatestValue(),
8454
+ unseenThreadIds = _this$state$getLatest.unseenThreadIds,
8455
+ ready = _this$state$getLatest.ready;
8456
+
8457
+ if (!ready) return;
8458
+
8459
+ if (_this.threadsById[parentId]) {
8460
+ _this.state.partialNext({
8461
+ isThreadOrderStale: true
8462
+ });
8463
+ } else if (!unseenThreadIds.includes(parentId)) {
8464
+ _this.state.partialNext({
8465
+ unseenThreadIds: unseenThreadIds.concat(parentId)
8466
+ });
8467
+ }
8468
+ }).unsubscribe;
8469
+ });
8470
+
8471
+ _defineProperty(this, "subscribeRecoverAfterConnectionDrop", function () {
8472
+ var unsubscribeConnectionDropped = _this.client.on('connection.changed', function (event) {
8473
+ if (event.online === false) {
8474
+ _this.state.next(function (current) {
8475
+ return current.lastConnectionDropAt ? current : _objectSpread$1(_objectSpread$1({}, current), {}, {
8476
+ lastConnectionDropAt: new Date()
8477
+ });
8478
+ });
8479
+ }
8480
+ }).unsubscribe;
8481
+
8482
+ var throttledHandleConnectionRecovered = throttle(function () {
8483
+ var _this$state$getLatest2 = _this.state.getLatestValue(),
8484
+ lastConnectionDropAt = _this$state$getLatest2.lastConnectionDropAt;
8485
+
8486
+ if (!lastConnectionDropAt) return;
8487
+
8488
+ _this.reload({
8489
+ force: true
8490
+ });
8491
+ }, DEFAULT_CONNECTION_RECOVERY_THROTTLE_DURATION, {
8492
+ trailing: true
8493
+ });
8494
+
8495
+ var unsubscribeConnectionRecovered = _this.client.on('connection.recovered', throttledHandleConnectionRecovered).unsubscribe;
8496
+
8497
+ return function () {
8498
+ unsubscribeConnectionDropped();
8499
+ unsubscribeConnectionRecovered();
8500
+ };
8501
+ });
8502
+
8503
+ _defineProperty(this, "unregisterSubscriptions", function () {
8504
+ _this.state.getLatestValue().threads.forEach(function (thread) {
8505
+ return thread.unregisterSubscriptions();
8506
+ });
8507
+
8508
+ _this.unsubscribeFunctions.forEach(function (cleanupFunction) {
8509
+ return cleanupFunction();
8510
+ });
8511
+
8512
+ _this.unsubscribeFunctions.clear();
8513
+ });
8514
+
8515
+ _defineProperty(this, "reload", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
8516
+ var _ref12,
8517
+ _ref12$force,
8518
+ force,
8519
+ _this$state$getLatest3,
8520
+ threads,
8521
+ unseenThreadIds,
8522
+ isThreadOrderStale,
8523
+ pagination,
8524
+ ready,
8525
+ limit,
8526
+ response,
8527
+ currentThreads,
8528
+ nextThreads,
8529
+ _iterator,
8530
+ _step,
8531
+ incomingThread,
8532
+ existingThread,
8533
+ _args = arguments;
8534
+
8535
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
8536
+ while (1) {
8537
+ switch (_context.prev = _context.next) {
8538
+ case 0:
8539
+ _ref12 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref12$force = _ref12.force, force = _ref12$force === void 0 ? false : _ref12$force;
8540
+ _this$state$getLatest3 = _this.state.getLatestValue(), threads = _this$state$getLatest3.threads, unseenThreadIds = _this$state$getLatest3.unseenThreadIds, isThreadOrderStale = _this$state$getLatest3.isThreadOrderStale, pagination = _this$state$getLatest3.pagination, ready = _this$state$getLatest3.ready;
8541
+
8542
+ if (!pagination.isLoading) {
8543
+ _context.next = 4;
8544
+ break;
8545
+ }
8546
+
8547
+ return _context.abrupt("return");
8548
+
8549
+ case 4:
8550
+ if (!(!force && ready && !unseenThreadIds.length && !isThreadOrderStale)) {
8551
+ _context.next = 6;
8552
+ break;
8553
+ }
8554
+
8555
+ return _context.abrupt("return");
8556
+
8557
+ case 6:
8558
+ limit = threads.length + unseenThreadIds.length;
8559
+ _context.prev = 7;
8560
+
8561
+ _this.state.next(function (current) {
8562
+ return _objectSpread$1(_objectSpread$1({}, current), {}, {
8563
+ pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8564
+ isLoading: true
8565
+ })
8566
+ });
8567
+ });
8568
+
8569
+ _context.next = 11;
8570
+ return _this.queryThreads({
8571
+ limit: Math.min(limit, MAX_QUERY_THREADS_LIMIT)
8572
+ });
8573
+
8574
+ case 11:
8575
+ response = _context.sent;
8576
+ currentThreads = _this.threadsById;
8577
+ nextThreads = [];
8578
+ _iterator = _createForOfIteratorHelper$1(response.threads);
8579
+
8580
+ try {
8581
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
8582
+ incomingThread = _step.value;
8583
+ existingThread = currentThreads[incomingThread.id];
8584
+
8585
+ if (existingThread) {
8586
+ // Reuse thread instances if possible
8587
+ nextThreads.push(existingThread);
8588
+
8589
+ if (existingThread.hasStaleState) {
8590
+ existingThread.hydrateState(incomingThread);
8591
+ }
8592
+ } else {
8593
+ nextThreads.push(incomingThread);
8594
+ }
8595
+ }
8596
+ } catch (err) {
8597
+ _iterator.e(err);
8598
+ } finally {
8599
+ _iterator.f();
8600
+ }
8601
+
8602
+ _this.state.next(function (current) {
8603
+ var _response$next;
8604
+
8605
+ return _objectSpread$1(_objectSpread$1({}, current), {}, {
8606
+ threads: nextThreads,
8607
+ unseenThreadIds: [],
8608
+ isThreadOrderStale: false,
8609
+ pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8610
+ isLoading: false,
8611
+ nextCursor: (_response$next = response.next) !== null && _response$next !== void 0 ? _response$next : null
8612
+ }),
8613
+ ready: true
8614
+ });
8615
+ });
8616
+
8617
+ _context.next = 23;
8618
+ break;
8619
+
8620
+ case 19:
8621
+ _context.prev = 19;
8622
+ _context.t0 = _context["catch"](7);
8623
+
8624
+ _this.client.logger('error', _context.t0.message);
8625
+
8626
+ _this.state.next(function (current) {
8627
+ return _objectSpread$1(_objectSpread$1({}, current), {}, {
8628
+ pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8629
+ isLoading: false
8630
+ })
8631
+ });
8632
+ });
8633
+
8634
+ case 23:
8635
+ case "end":
8636
+ return _context.stop();
8637
+ }
8638
+ }
8639
+ }, _callee, null, [[7, 19]]);
8640
+ })));
8641
+
8642
+ _defineProperty(this, "queryThreads", function () {
8643
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8644
+ return _this.client.queryThreads(_objectSpread$1({
8645
+ limit: 25,
8646
+ participant_limit: 10,
8647
+ reply_limit: 10,
8648
+ watch: true
8649
+ }, options));
8650
+ });
8651
+
8652
+ _defineProperty(this, "loadNextPage", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
8653
+ var options,
8654
+ _this$state$getLatest4,
8655
+ pagination,
8656
+ response,
8657
+ _args2 = arguments;
8658
+
8659
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
8660
+ while (1) {
8661
+ switch (_context2.prev = _context2.next) {
8662
+ case 0:
8663
+ options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
8664
+ _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
8665
+
8666
+ if (!(pagination.isLoadingNext || !pagination.nextCursor)) {
8667
+ _context2.next = 4;
8668
+ break;
8669
+ }
8670
+
8671
+ return _context2.abrupt("return");
8672
+
8673
+ case 4:
8674
+ _context2.prev = 4;
8675
+
8676
+ _this.state.partialNext({
8677
+ pagination: _objectSpread$1(_objectSpread$1({}, pagination), {}, {
8678
+ isLoadingNext: true
8679
+ })
8680
+ });
8681
+
8682
+ _context2.next = 8;
8683
+ return _this.queryThreads(_objectSpread$1(_objectSpread$1({}, options), {}, {
8684
+ next: pagination.nextCursor
8685
+ }));
8686
+
8687
+ case 8:
8688
+ response = _context2.sent;
8689
+
8690
+ _this.state.next(function (current) {
8691
+ var _response$next2;
8692
+
8693
+ return _objectSpread$1(_objectSpread$1({}, current), {}, {
8694
+ threads: response.threads.length ? current.threads.concat(response.threads) : current.threads,
8695
+ pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8696
+ nextCursor: (_response$next2 = response.next) !== null && _response$next2 !== void 0 ? _response$next2 : null,
8697
+ isLoadingNext: false
8698
+ })
8699
+ });
8700
+ });
8701
+
8702
+ _context2.next = 16;
8703
+ break;
8704
+
8705
+ case 12:
8706
+ _context2.prev = 12;
8707
+ _context2.t0 = _context2["catch"](4);
8708
+
8709
+ _this.client.logger('error', _context2.t0.message);
8710
+
8711
+ _this.state.next(function (current) {
8712
+ return _objectSpread$1(_objectSpread$1({}, current), {}, {
8713
+ pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8714
+ isLoadingNext: false
8715
+ })
8716
+ });
8717
+ });
8718
+
8719
+ case 16:
8720
+ case "end":
8721
+ return _context2.stop();
8722
+ }
8723
+ }
8724
+ }, _callee2, null, [[4, 12]]);
8725
+ })));
8726
+
8727
+ this.client = client;
8728
+ this.state = new StateStore({
8729
+ active: false,
8730
+ isThreadOrderStale: false,
8731
+ threads: [],
8732
+ unreadThreadCount: 0,
8733
+ unseenThreadIds: [],
8734
+ lastConnectionDropAt: null,
8735
+ pagination: {
8736
+ isLoading: false,
8737
+ isLoadingNext: false,
8738
+ nextCursor: null
8739
+ },
8740
+ ready: false
8741
+ });
8742
+ this.threadsByIdGetterCache = {
8743
+ threads: [],
8744
+ threadsById: {}
8745
+ };
8746
+ }
8747
+
8748
+ _createClass(ThreadManager, [{
8749
+ key: "threadsById",
8750
+ get: function get() {
8751
+ var _this$state$getLatest5 = this.state.getLatestValue(),
8752
+ threads = _this$state$getLatest5.threads;
8753
+
8754
+ if (threads === this.threadsByIdGetterCache.threads) {
8755
+ return this.threadsByIdGetterCache.threadsById;
8756
+ }
8757
+
8758
+ var threadsById = threads.reduce(function (newThreadsById, thread) {
8759
+ newThreadsById[thread.id] = thread;
8760
+ return newThreadsById;
8761
+ }, {});
8762
+ this.threadsByIdGetterCache.threads = threads;
8763
+ this.threadsByIdGetterCache.threadsById = threadsById;
8764
+ return threadsById;
8765
+ }
8766
+ }]);
8767
+
8768
+ return ThreadManager;
8769
+ }();
8770
+
7722
8771
  var _excluded = ["created_at", "updated_at", "last_active", "online"],
7723
8772
  _excluded2 = ["params", "headers"];
7724
8773
 
@@ -7747,6 +8796,8 @@ var StreamChat = /*#__PURE__*/function () {
7747
8796
 
7748
8797
  _defineProperty(this, "activeChannels", void 0);
7749
8798
 
8799
+ _defineProperty(this, "threads", void 0);
8800
+
7750
8801
  _defineProperty(this, "anonymous", void 0);
7751
8802
 
7752
8803
  _defineProperty(this, "persistUserOnConnectionFailure", void 0);
@@ -7978,7 +9029,7 @@ var StreamChat = /*#__PURE__*/function () {
7978
9029
  tags: ['connection', 'client']
7979
9030
  });
7980
9031
 
7981
- return _context3.abrupt("return", Promise.resolve());
9032
+ return _context3.abrupt("return");
7982
9033
 
7983
9034
  case 8:
7984
9035
  _this.clientID = "".concat(_this.userID, "--").concat(randomId());
@@ -8586,8 +9637,8 @@ var StreamChat = /*#__PURE__*/function () {
8586
9637
  this.tokenManager = new TokenManager(this.secret);
8587
9638
  this.consecutiveFailures = 0;
8588
9639
  this.insightMetrics = new InsightMetrics();
8589
- this.defaultWSTimeoutWithFallback = 6000;
8590
- this.defaultWSTimeout = 15000;
9640
+ this.defaultWSTimeoutWithFallback = 6 * 1000;
9641
+ this.defaultWSTimeout = 15 * 1000;
8591
9642
  this.axiosInstance.defaults.paramsSerializer = axiosParamsSerializer;
8592
9643
  /**
8593
9644
  * logger function should accept 3 parameters:
@@ -8642,6 +9693,9 @@ var StreamChat = /*#__PURE__*/function () {
8642
9693
  return null;
8643
9694
  };
8644
9695
  this.recoverStateOnReconnect = this.options.recoverStateOnReconnect;
9696
+ this.threads = new ThreadManager({
9697
+ client: this
9698
+ });
8645
9699
  }
8646
9700
  /**
8647
9701
  * Get a client instance
@@ -12049,7 +13103,10 @@ var StreamChat = /*#__PURE__*/function () {
12049
13103
  res = _context64.sent;
12050
13104
  return _context64.abrupt("return", {
12051
13105
  threads: res.threads.map(function (thread) {
12052
- return new Thread(_this5, thread);
13106
+ return new Thread({
13107
+ client: _this5,
13108
+ threadData: thread
13109
+ });
12053
13110
  }),
12054
13111
  next: res.next
12055
13112
  });
@@ -12112,7 +13169,10 @@ var StreamChat = /*#__PURE__*/function () {
12112
13169
 
12113
13170
  case 6:
12114
13171
  res = _context65.sent;
12115
- return _context65.abrupt("return", new Thread(this, res.thread));
13172
+ return _context65.abrupt("return", new Thread({
13173
+ client: this,
13174
+ threadData: res.thread
13175
+ }));
12116
13176
 
12117
13177
  case 8:
12118
13178
  case "end":
@@ -12203,7 +13263,7 @@ var StreamChat = /*#__PURE__*/function () {
12203
13263
  }, {
12204
13264
  key: "getUserAgent",
12205
13265
  value: function getUserAgent() {
12206
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.39.0");
13266
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.40.0");
12207
13267
  }
12208
13268
  }, {
12209
13269
  key: "setUserAgent",
@@ -14470,5 +15530,5 @@ var BuiltinPermissions = {
14470
15530
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
14471
15531
  };
14472
15532
 
14473
- export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Campaign, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, ErrorFromResponse, InsightMetrics, JWTServerToken, JWTUserToken, MODERATION_ENTITY_TYPES, MaxPriority, MinPriority, Moderation, Permission, Segment, StableWSConnection, StreamChat, Thread, TokenManager, UserFromToken, VotingVisibility, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, formatMessage, isOwnUser, logChatPromiseExecution, postInsights };
15533
+ export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Campaign, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, ErrorFromResponse, InsightMetrics, JWTServerToken, JWTUserToken, MODERATION_ENTITY_TYPES, MaxPriority, MinPriority, Moderation, Permission, Segment, StableWSConnection, StateStore, StreamChat, Thread, ThreadManager, TokenManager, UserFromToken, VotingVisibility, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, formatMessage, isOwnUser, logChatPromiseExecution, postInsights };
14474
15534
  //# sourceMappingURL=browser.es.js.map