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 +73 -55
- package/build/index.js.map +1 -1
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +3 -1
- package/package.json +1 -1
- package/src/state-tracker/RoomsManager.ts +1 -1
- package/src/state-tracker/TopicHistoryWindow.ts +26 -14
- package/tests/history-window.test.ts +28 -1
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.
|
|
697
|
-
|
|
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
|
|
712
|
+
case 2:
|
|
703
713
|
this.fetchingState = WindowState.LATEST;
|
|
704
|
-
_context.prev =
|
|
705
|
-
_context.next =
|
|
714
|
+
_context.prev = 3;
|
|
715
|
+
_context.next = 6;
|
|
706
716
|
return this.fetchLatestItems();
|
|
707
|
-
case
|
|
717
|
+
case 6:
|
|
708
718
|
result = _context.sent;
|
|
709
|
-
case
|
|
710
|
-
_context.prev =
|
|
719
|
+
case 7:
|
|
720
|
+
_context.prev = 7;
|
|
711
721
|
this.fetchingState = undefined;
|
|
712
|
-
return _context.finish(
|
|
713
|
-
case
|
|
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
|
|
727
|
+
case 13:
|
|
718
728
|
case "end":
|
|
719
729
|
return _context.stop();
|
|
720
730
|
}
|
|
721
731
|
}
|
|
722
|
-
}, _callee, this, [[
|
|
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.
|
|
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 =
|
|
747
|
-
_context2.next =
|
|
755
|
+
_context2.prev = 3;
|
|
756
|
+
_context2.next = 6;
|
|
748
757
|
return this.fetchItemsBefore();
|
|
749
|
-
case
|
|
758
|
+
case 6:
|
|
750
759
|
result = _context2.sent;
|
|
751
|
-
case
|
|
752
|
-
_context2.prev =
|
|
760
|
+
case 7:
|
|
761
|
+
_context2.prev = 7;
|
|
753
762
|
this.fetchingState = undefined;
|
|
754
|
-
return _context2.finish(
|
|
755
|
-
case
|
|
763
|
+
return _context2.finish(7);
|
|
764
|
+
case 10:
|
|
756
765
|
if (result) {
|
|
757
|
-
_context2.next =
|
|
766
|
+
_context2.next = 12;
|
|
758
767
|
break;
|
|
759
768
|
}
|
|
760
769
|
return _context2.abrupt("return", this.resetToLatest());
|
|
761
|
-
case
|
|
770
|
+
case 12:
|
|
762
771
|
if (result.length) {
|
|
763
|
-
_context2.next =
|
|
772
|
+
_context2.next = 20;
|
|
764
773
|
break;
|
|
765
774
|
}
|
|
766
|
-
|
|
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
|
|
786
|
+
case 20:
|
|
769
787
|
this.addItems(result, 'head');
|
|
770
|
-
_context2.next =
|
|
788
|
+
_context2.next = 23;
|
|
771
789
|
return this.refreshFetchedState();
|
|
772
|
-
case
|
|
790
|
+
case 23:
|
|
773
791
|
case "end":
|
|
774
792
|
return _context2.stop();
|
|
775
793
|
}
|
|
776
794
|
}
|
|
777
|
-
}, _callee2, this, [[
|
|
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.
|
|
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 =
|
|
796
|
-
_context3.next =
|
|
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
|
-
|
|
822
|
+
result = _context3.sent;
|
|
823
|
+
case 7:
|
|
824
|
+
_context3.prev = 7;
|
|
802
825
|
this.fetchingState = undefined;
|
|
803
|
-
return _context3.finish(
|
|
804
|
-
case
|
|
826
|
+
return _context3.finish(7);
|
|
827
|
+
case 10:
|
|
805
828
|
if (result) {
|
|
806
|
-
_context3.next =
|
|
829
|
+
_context3.next = 14;
|
|
807
830
|
break;
|
|
808
831
|
}
|
|
809
|
-
_context3.next =
|
|
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 =
|
|
838
|
+
_context3.next = 19;
|
|
816
839
|
break;
|
|
817
840
|
}
|
|
818
841
|
this.addItems(result, 'tail');
|
|
819
|
-
_context3.next =
|
|
842
|
+
_context3.next = 18;
|
|
820
843
|
return this.refreshFetchedState();
|
|
821
|
-
case
|
|
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, [[
|
|
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,
|