polfan-server-js-client 0.1.996 → 0.1.998

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -668,6 +668,7 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
668
668
  TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "limit", 50);
669
669
  TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "currentState", WindowState.LIVE);
670
670
  TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "fetchingState", undefined);
671
+ TopicHistoryWindow_defineProperty(TopicHistoryWindow_assertThisInitialized(_this), "oldestId", null);
671
672
  return _this;
672
673
  }
673
674
  TopicHistoryWindow_createClass(TraversableRemoteCollection, [{
@@ -684,6 +685,16 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
684
685
  * Maximum numer of items stored in window.
685
686
  * Null for unlimited.
686
687
  */
688
+ }, {
689
+ key: "hasLatest",
690
+ get: function get() {
691
+ return [WindowState.LATEST, WindowState.LIVE].includes(this.state);
692
+ }
693
+ }, {
694
+ key: "hasOldest",
695
+ get: function get() {
696
+ return this.state === WindowState.OLDEST || this.oldestId !== null && this.has(this.oldestId);
697
+ }
687
698
  }, {
688
699
  key: "resetToLatest",
689
700
  value: function () {
@@ -693,33 +704,32 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
693
704
  while (1) {
694
705
  switch (_context.prev = _context.next) {
695
706
  case 0:
696
- this.throwIfFetchingInProgress();
697
- if (!(this.currentState === WindowState.LATEST)) {
698
- _context.next = 3;
707
+ if (!(this.fetchingState || this.currentState === WindowState.LATEST)) {
708
+ _context.next = 2;
699
709
  break;
700
710
  }
701
711
  return _context.abrupt("return");
702
- case 3:
712
+ case 2:
703
713
  this.fetchingState = WindowState.LATEST;
704
- _context.prev = 4;
705
- _context.next = 7;
714
+ _context.prev = 3;
715
+ _context.next = 6;
706
716
  return this.fetchLatestItems();
707
- case 7:
717
+ case 6:
708
718
  result = _context.sent;
709
- case 8:
710
- _context.prev = 8;
719
+ case 7:
720
+ _context.prev = 7;
711
721
  this.fetchingState = undefined;
712
- return _context.finish(8);
713
- case 11:
722
+ return _context.finish(7);
723
+ case 10:
714
724
  this.deleteAll();
715
725
  this.addItems(result, 'tail');
716
726
  this.currentState = WindowState.LATEST;
717
- case 14:
727
+ case 13:
718
728
  case "end":
719
729
  return _context.stop();
720
730
  }
721
731
  }
722
- }, _callee, this, [[4,, 8, 11]]);
732
+ }, _callee, this, [[3,, 7, 10]]);
723
733
  }));
724
734
  function resetToLatest() {
725
735
  return _resetToLatest.apply(this, arguments);
@@ -730,51 +740,59 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
730
740
  key: "fetchPrevious",
731
741
  value: function () {
732
742
  var _fetchPrevious = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
733
- var result;
743
+ var result, firstItem;
734
744
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
735
745
  while (1) {
736
746
  switch (_context2.prev = _context2.next) {
737
747
  case 0:
738
- if (!(this.state === WindowState.OLDEST)) {
748
+ if (!(this.fetchingState || this.hasOldest)) {
739
749
  _context2.next = 2;
740
750
  break;
741
751
  }
742
752
  return _context2.abrupt("return");
743
753
  case 2:
744
- this.throwIfFetchingInProgress();
745
754
  this.fetchingState = WindowState.PAST;
746
- _context2.prev = 4;
747
- _context2.next = 7;
755
+ _context2.prev = 3;
756
+ _context2.next = 6;
748
757
  return this.fetchItemsBefore();
749
- case 7:
758
+ case 6:
750
759
  result = _context2.sent;
751
- case 8:
752
- _context2.prev = 8;
760
+ case 7:
761
+ _context2.prev = 7;
753
762
  this.fetchingState = undefined;
754
- return _context2.finish(8);
755
- case 11:
763
+ return _context2.finish(7);
764
+ case 10:
756
765
  if (result) {
757
- _context2.next = 13;
766
+ _context2.next = 12;
758
767
  break;
759
768
  }
760
769
  return _context2.abrupt("return", this.resetToLatest());
761
- case 13:
770
+ case 12:
762
771
  if (result.length) {
763
- _context2.next = 16;
772
+ _context2.next = 20;
764
773
  break;
765
774
  }
766
- this.currentState = WindowState.OLDEST;
775
+ firstItem = this.getAt(0);
776
+ console.log(firstItem);
777
+ this.oldestId = firstItem ? this.getId(firstItem) : null;
778
+ _context2.next = 18;
779
+ return this.refreshFetchedState();
780
+ case 18:
781
+ // LATEST state has priority over OLDEST
782
+ if (this.currentState === WindowState.PAST) {
783
+ this.currentState = WindowState.OLDEST;
784
+ }
767
785
  return _context2.abrupt("return");
768
- case 16:
786
+ case 20:
769
787
  this.addItems(result, 'head');
770
- _context2.next = 19;
788
+ _context2.next = 23;
771
789
  return this.refreshFetchedState();
772
- case 19:
790
+ case 23:
773
791
  case "end":
774
792
  return _context2.stop();
775
793
  }
776
794
  }
777
- }, _callee2, this, [[4,, 8, 11]]);
795
+ }, _callee2, this, [[3,, 7, 10]]);
778
796
  }));
779
797
  function fetchPrevious() {
780
798
  return _fetchPrevious.apply(this, arguments);
@@ -790,40 +808,47 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
790
808
  while (1) {
791
809
  switch (_context3.prev = _context3.next) {
792
810
  case 0:
793
- this.throwIfFetchingInProgress();
811
+ if (!(this.fetchingState || this.hasLatest)) {
812
+ _context3.next = 2;
813
+ break;
814
+ }
815
+ return _context3.abrupt("return");
816
+ case 2:
794
817
  this.fetchingState = WindowState.PAST;
795
- _context3.prev = 2;
796
- _context3.next = 5;
818
+ _context3.prev = 3;
819
+ _context3.next = 6;
797
820
  return this.fetchItemsAfter();
798
- case 5:
799
- result = _context3.sent;
800
821
  case 6:
801
- _context3.prev = 6;
822
+ result = _context3.sent;
823
+ case 7:
824
+ _context3.prev = 7;
802
825
  this.fetchingState = undefined;
803
- return _context3.finish(6);
804
- case 9:
826
+ return _context3.finish(7);
827
+ case 10:
805
828
  if (result) {
806
- _context3.next = 13;
829
+ _context3.next = 14;
807
830
  break;
808
831
  }
809
- _context3.next = 12;
832
+ _context3.next = 13;
810
833
  return this.resetToLatest();
811
- case 12:
812
- return _context3.abrupt("return");
813
834
  case 13:
835
+ return _context3.abrupt("return");
836
+ case 14:
814
837
  if (!result.length) {
815
- _context3.next = 17;
838
+ _context3.next = 19;
816
839
  break;
817
840
  }
818
841
  this.addItems(result, 'tail');
819
- _context3.next = 17;
842
+ _context3.next = 18;
820
843
  return this.refreshFetchedState();
821
- case 17:
844
+ case 18:
845
+ return _context3.abrupt("return");
846
+ case 19:
822
847
  case "end":
823
848
  return _context3.stop();
824
849
  }
825
850
  }
826
- }, _callee3, this, [[2,, 6, 9]]);
851
+ }, _callee3, this, [[3,, 7, 10]]);
827
852
  }));
828
853
  function fetchNext() {
829
854
  return _fetchNext.apply(this, arguments);
@@ -877,13 +902,6 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
877
902
  this.deleteAll();
878
903
  this.set.apply(this, TopicHistoryWindow_toConsumableArray(result));
879
904
  }
880
- }, {
881
- key: "throwIfFetchingInProgress",
882
- value: function throwIfFetchingInProgress() {
883
- if (this.fetchingState) {
884
- throw new Error("Items fetching in progress: ".concat(WindowState[this.fetchingState]));
885
- }
886
- }
887
905
 
888
906
  /**
889
907
  * Return array with messages of count that matching limit.
@@ -2320,7 +2338,7 @@ var RoomsManager = /*#__PURE__*/function () {
2320
2338
  key: "handleNewMessage",
2321
2339
  value: function handleNewMessage(ev) {
2322
2340
  var topics = this.topics.get(ev.location.roomId);
2323
- var topic = topics.get(ev.location.topicId);
2341
+ var topic = topics === null || topics === void 0 ? void 0 : topics.get(ev.location.topicId);
2324
2342
  if (topic) {
2325
2343
  topics.set(RoomsManager_objectSpread(RoomsManager_objectSpread({}, topic), {}, {
2326
2344
  messageCount: topic.messageCount + 1,