polfan-server-js-client 0.2.105 → 0.2.107
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/.idea/workspace.xml +32 -33
- package/build/index.cjs.js +533 -118
- package/build/index.cjs.js.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/AbstractChatClient.d.ts +10 -0
- package/build/types/IndexedObjectCollection.d.ts +8 -0
- package/build/types/WebSocketChatClient.d.ts +17 -1
- package/build/types/state-tracker/FollowedTopicsManager.d.ts +18 -0
- package/build/types/state-tracker/RoomMessagesHistory.d.ts +12 -0
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +2 -2
- package/package.json +1 -1
- package/src/AbstractChatClient.ts +22 -0
- package/src/IndexedObjectCollection.ts +31 -0
- package/src/WebSocketChatClient.ts +63 -7
- package/src/state-tracker/AsyncUtils.ts +52 -41
- package/src/state-tracker/EmoticonsManager.ts +72 -68
- package/src/state-tracker/FollowedTopicsManager.ts +54 -6
- package/src/state-tracker/MessagesManager.ts +21 -2
- package/src/state-tracker/PermissionsManager.ts +5 -1
- package/src/state-tracker/RelationshipsManager.ts +5 -5
- package/src/state-tracker/RoomMessagesHistory.ts +41 -1
- package/src/state-tracker/RoomsManager.ts +21 -4
- package/src/state-tracker/SpacesManager.ts +340 -313
- package/src/state-tracker/TopicHistoryWindow.ts +4 -4
- package/src/state-tracker/UsersManager.ts +3 -1
- package/tests/collections.test.ts +92 -0
- package/tests/pending-commands.test.ts +171 -0
- package/tests/state-reconnect.test.ts +257 -0
package/build/index.cjs.js
CHANGED
|
@@ -118,6 +118,12 @@ var EventTarget = /*#__PURE__*/function () {
|
|
|
118
118
|
}();
|
|
119
119
|
;// ./src/AbstractChatClient.ts
|
|
120
120
|
function AbstractChatClient_typeof(o) { "@babel/helpers - typeof"; return AbstractChatClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, AbstractChatClient_typeof(o); }
|
|
121
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
122
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
123
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
124
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
125
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
126
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
121
127
|
function AbstractChatClient_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
122
128
|
function AbstractChatClient_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, AbstractChatClient_toPropertyKey(o.key), o); } }
|
|
123
129
|
function AbstractChatClient_createClass(e, r, t) { return r && AbstractChatClient_defineProperties(e.prototype, r), t && AbstractChatClient_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -187,6 +193,30 @@ var AbstractChatClient = /*#__PURE__*/function (_EventTarget) {
|
|
|
187
193
|
this.awaitingResponse.get(envelope.ref)[1](error);
|
|
188
194
|
this.awaitingResponse["delete"](envelope.ref);
|
|
189
195
|
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Reject every command that is still waiting for a response.
|
|
199
|
+
*
|
|
200
|
+
* Call this whenever the transport can no longer deliver an answer (the
|
|
201
|
+
* connection dropped). The server will never reply to those commands, so
|
|
202
|
+
* leaving them pending would hang every caller awaiting them forever -
|
|
203
|
+
* including cached lookups in the state tracker, which would then keep a
|
|
204
|
+
* view stuck on a loader even after a successful reconnect.
|
|
205
|
+
*/
|
|
206
|
+
}, {
|
|
207
|
+
key: "failAwaitingResponses",
|
|
208
|
+
value: function failAwaitingResponses(error) {
|
|
209
|
+
if (!this.awaitingResponse.size) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
var pending = Array.from(this.awaitingResponse.values());
|
|
213
|
+
this.awaitingResponse.clear();
|
|
214
|
+
for (var _i = 0, _pending = pending; _i < _pending.length; _i++) {
|
|
215
|
+
var _pending$_i = _slicedToArray(_pending[_i], 2),
|
|
216
|
+
reject = _pending$_i[1];
|
|
217
|
+
reject(error);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
190
220
|
}]);
|
|
191
221
|
}(EventTarget);
|
|
192
222
|
|
|
@@ -209,17 +239,17 @@ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !==
|
|
|
209
239
|
function IndexedObjectCollection_getPrototypeOf(t) { return IndexedObjectCollection_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, IndexedObjectCollection_getPrototypeOf(t); }
|
|
210
240
|
function IndexedObjectCollection_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && IndexedObjectCollection_setPrototypeOf(t, e); }
|
|
211
241
|
function IndexedObjectCollection_setPrototypeOf(t, e) { return IndexedObjectCollection_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, IndexedObjectCollection_setPrototypeOf(t, e); }
|
|
212
|
-
function
|
|
213
|
-
function
|
|
214
|
-
function
|
|
215
|
-
function
|
|
216
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t =
|
|
217
|
-
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) ||
|
|
242
|
+
function IndexedObjectCollection_slicedToArray(r, e) { return IndexedObjectCollection_arrayWithHoles(r) || IndexedObjectCollection_iterableToArrayLimit(r, e) || IndexedObjectCollection_unsupportedIterableToArray(r, e) || IndexedObjectCollection_nonIterableRest(); }
|
|
243
|
+
function IndexedObjectCollection_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
244
|
+
function IndexedObjectCollection_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
245
|
+
function IndexedObjectCollection_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
246
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = IndexedObjectCollection_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
247
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || IndexedObjectCollection_unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
218
248
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
219
|
-
function
|
|
249
|
+
function IndexedObjectCollection_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return IndexedObjectCollection_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? IndexedObjectCollection_arrayLikeToArray(r, a) : void 0; } }
|
|
220
250
|
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
221
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return
|
|
222
|
-
function
|
|
251
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return IndexedObjectCollection_arrayLikeToArray(r); }
|
|
252
|
+
function IndexedObjectCollection_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
223
253
|
function IndexedObjectCollection_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
224
254
|
function IndexedObjectCollection_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, IndexedObjectCollection_toPropertyKey(o.key), o); } }
|
|
225
255
|
function IndexedObjectCollection_createClass(e, r, t) { return r && IndexedObjectCollection_defineProperties(e.prototype, r), t && IndexedObjectCollection_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -290,7 +320,7 @@ var IndexedCollection = /*#__PURE__*/function () {
|
|
|
290
320
|
_step;
|
|
291
321
|
try {
|
|
292
322
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
293
|
-
var _step$value =
|
|
323
|
+
var _step$value = IndexedObjectCollection_slicedToArray(_step.value, 2),
|
|
294
324
|
key = _step$value[0],
|
|
295
325
|
value = _step$value[1];
|
|
296
326
|
if (result.length >= limit) {
|
|
@@ -547,6 +577,53 @@ var ObservableIndexedObjectCollection = /*#__PURE__*/function (_IndexedObjectCol
|
|
|
547
577
|
});
|
|
548
578
|
}
|
|
549
579
|
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* Bring the collection to exactly match the provided items: upsert every
|
|
583
|
+
* provided item and remove any existing item whose id is not present in the
|
|
584
|
+
* provided set. Emits at most a single `change` event describing both the
|
|
585
|
+
* set and the deleted ids, so bound consumers can update in place without
|
|
586
|
+
* ever observing an intermediate empty state (unlike deleteAll + set).
|
|
587
|
+
*/
|
|
588
|
+
}, {
|
|
589
|
+
key: "reconcile",
|
|
590
|
+
value: function reconcile() {
|
|
591
|
+
var _this8 = this,
|
|
592
|
+
_this$_items3;
|
|
593
|
+
for (var _len8 = arguments.length, items = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
594
|
+
items[_key8] = arguments[_key8];
|
|
595
|
+
}
|
|
596
|
+
var incomingIds = new Set(items.map(function (item) {
|
|
597
|
+
return _this8.getId(item);
|
|
598
|
+
}));
|
|
599
|
+
var deletedItems = [];
|
|
600
|
+
var _iterator3 = _createForOfIteratorHelper(this.items),
|
|
601
|
+
_step3;
|
|
602
|
+
try {
|
|
603
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
604
|
+
var existing = _step3.value;
|
|
605
|
+
var _id2 = this.getId(existing);
|
|
606
|
+
if (!incomingIds.has(_id2)) {
|
|
607
|
+
deletedItems.push(_id2);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
} catch (err) {
|
|
611
|
+
_iterator3.e(err);
|
|
612
|
+
} finally {
|
|
613
|
+
_iterator3.f();
|
|
614
|
+
}
|
|
615
|
+
if (!items.length && !deletedItems.length) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
(_this$_items3 = this._items)["delete"].apply(_this$_items3, deletedItems);
|
|
619
|
+
_superPropGet(ObservableIndexedObjectCollection, "set", this, 3)(items);
|
|
620
|
+
this.eventTarget.emit('change', {
|
|
621
|
+
setItems: items.map(function (item) {
|
|
622
|
+
return _this8.getId(item);
|
|
623
|
+
}),
|
|
624
|
+
deletedItems: deletedItems
|
|
625
|
+
});
|
|
626
|
+
}
|
|
550
627
|
}, {
|
|
551
628
|
key: "createMirror",
|
|
552
629
|
value: function createMirror() {
|
|
@@ -601,7 +678,19 @@ var PromiseRegistry = /*#__PURE__*/function () {
|
|
|
601
678
|
return AsyncUtils_createClass(PromiseRegistry, [{
|
|
602
679
|
key: "register",
|
|
603
680
|
value: function register(promise, key) {
|
|
681
|
+
var _this2 = this;
|
|
604
682
|
this.promises.set([key, promise]);
|
|
683
|
+
|
|
684
|
+
// Never cache a failed lookup: drop it so the next access retries
|
|
685
|
+
// instead of replaying the same rejection forever (a request issued
|
|
686
|
+
// while the client was offline would otherwise poison the key). The
|
|
687
|
+
// handler also keeps the cached promise from surfacing as an unhandled
|
|
688
|
+
// rejection - callers still receive the rejection from their own await.
|
|
689
|
+
promise["catch"](function () {
|
|
690
|
+
if (_this2.promises.get(key) === promise) {
|
|
691
|
+
_this2.promises["delete"](key);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
605
694
|
}
|
|
606
695
|
}, {
|
|
607
696
|
key: "registerByFunction",
|
|
@@ -781,11 +870,15 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
781
870
|
key: "resetToLatest",
|
|
782
871
|
value: function () {
|
|
783
872
|
var _resetToLatest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
784
|
-
var
|
|
873
|
+
var force,
|
|
874
|
+
result,
|
|
875
|
+
originalState,
|
|
876
|
+
_args = arguments;
|
|
785
877
|
return _regenerator().w(function (_context) {
|
|
786
878
|
while (1) switch (_context.p = _context.n) {
|
|
787
879
|
case 0:
|
|
788
|
-
|
|
880
|
+
force = _args.length > 0 && _args[0] !== undefined ? _args[0] : false;
|
|
881
|
+
if (!(this.internalState.ongoing || !force && this.internalState.current === WindowState.LATEST)) {
|
|
789
882
|
_context.n = 1;
|
|
790
883
|
break;
|
|
791
884
|
}
|
|
@@ -1133,16 +1226,19 @@ var TopicHistoryWindow = /*#__PURE__*/function (_TraversableRemoteCol) {
|
|
|
1133
1226
|
key: "resetToLatest",
|
|
1134
1227
|
value: function () {
|
|
1135
1228
|
var _resetToLatest2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
|
|
1229
|
+
var force,
|
|
1230
|
+
_args7 = arguments;
|
|
1136
1231
|
return _regenerator().w(function (_context7) {
|
|
1137
1232
|
while (1) switch (_context7.n) {
|
|
1138
1233
|
case 0:
|
|
1234
|
+
force = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : false;
|
|
1139
1235
|
if (!this.internalState.traverseLock) {
|
|
1140
1236
|
_context7.n = 1;
|
|
1141
1237
|
break;
|
|
1142
1238
|
}
|
|
1143
1239
|
return _context7.a(2);
|
|
1144
1240
|
case 1:
|
|
1145
|
-
return _context7.a(2, TopicHistoryWindow_superPropGet(TopicHistoryWindow, "resetToLatest", this, 3)([]));
|
|
1241
|
+
return _context7.a(2, TopicHistoryWindow_superPropGet(TopicHistoryWindow, "resetToLatest", this, 3)([force]));
|
|
1146
1242
|
}
|
|
1147
1243
|
}, _callee7, this);
|
|
1148
1244
|
}));
|
|
@@ -1618,17 +1714,85 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
|
|
|
1618
1714
|
return _getMessagesWindow.apply(this, arguments);
|
|
1619
1715
|
}
|
|
1620
1716
|
return getMessagesWindow;
|
|
1717
|
+
}()
|
|
1718
|
+
/**
|
|
1719
|
+
* Re-synchronise this room's history after a reconnect without discarding
|
|
1720
|
+
* the existing window objects (which would blank the UI and, for ephemeral
|
|
1721
|
+
* rooms, permanently drop live-only history).
|
|
1722
|
+
*
|
|
1723
|
+
* The window bindings are preserved; only windows that the application had
|
|
1724
|
+
* actually pulled to the latest page (state === LATEST) are refreshed, with
|
|
1725
|
+
* a single resetToLatest instead of a chain of catch-up requests. Windows
|
|
1726
|
+
* that were never pulled (LIVE) or belong to an ephemeral room are left
|
|
1727
|
+
* untouched so their in-memory context survives the reconnect.
|
|
1728
|
+
*/
|
|
1729
|
+
)
|
|
1730
|
+
}, {
|
|
1731
|
+
key: "resync",
|
|
1732
|
+
value: (function () {
|
|
1733
|
+
var _resync = RoomMessagesHistory_asyncToGenerator(/*#__PURE__*/RoomMessagesHistory_regenerator().m(function _callee2(room) {
|
|
1734
|
+
var _i, _Array$from, _Array$from$_i, window, _t;
|
|
1735
|
+
return RoomMessagesHistory_regenerator().w(function (_context2) {
|
|
1736
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
1737
|
+
case 0:
|
|
1738
|
+
this.room = room;
|
|
1739
|
+
this.updateTraverseLock(room);
|
|
1740
|
+
if (this.room.defaultTopic) {
|
|
1741
|
+
this.createHistoryWindowForTopic(this.room.defaultTopic);
|
|
1742
|
+
}
|
|
1743
|
+
_i = 0, _Array$from = Array.from(this.historyWindows.items);
|
|
1744
|
+
case 1:
|
|
1745
|
+
if (!(_i < _Array$from.length)) {
|
|
1746
|
+
_context2.n = 8;
|
|
1747
|
+
break;
|
|
1748
|
+
}
|
|
1749
|
+
_Array$from$_i = RoomMessagesHistory_slicedToArray(_Array$from[_i], 2), window = _Array$from$_i[1];
|
|
1750
|
+
_context2.p = 2;
|
|
1751
|
+
_context2.n = 3;
|
|
1752
|
+
return window.setTraverseLock(this.traverseLock);
|
|
1753
|
+
case 3:
|
|
1754
|
+
if (!this.traverseLock) {
|
|
1755
|
+
_context2.n = 4;
|
|
1756
|
+
break;
|
|
1757
|
+
}
|
|
1758
|
+
return _context2.a(3, 7);
|
|
1759
|
+
case 4:
|
|
1760
|
+
if (!(window.state === WindowState.LATEST)) {
|
|
1761
|
+
_context2.n = 5;
|
|
1762
|
+
break;
|
|
1763
|
+
}
|
|
1764
|
+
_context2.n = 5;
|
|
1765
|
+
return window.resetToLatest(true);
|
|
1766
|
+
case 5:
|
|
1767
|
+
_context2.n = 7;
|
|
1768
|
+
break;
|
|
1769
|
+
case 6:
|
|
1770
|
+
_context2.p = 6;
|
|
1771
|
+
_t = _context2.v;
|
|
1772
|
+
case 7:
|
|
1773
|
+
_i++;
|
|
1774
|
+
_context2.n = 1;
|
|
1775
|
+
break;
|
|
1776
|
+
case 8:
|
|
1777
|
+
return _context2.a(2);
|
|
1778
|
+
}
|
|
1779
|
+
}, _callee2, this, [[2, 6]]);
|
|
1780
|
+
}));
|
|
1781
|
+
function resync(_x2) {
|
|
1782
|
+
return _resync.apply(this, arguments);
|
|
1783
|
+
}
|
|
1784
|
+
return resync;
|
|
1621
1785
|
}())
|
|
1622
1786
|
}, {
|
|
1623
1787
|
key: "handleRoomUpdated",
|
|
1624
1788
|
value: function () {
|
|
1625
|
-
var _handleRoomUpdated = RoomMessagesHistory_asyncToGenerator(/*#__PURE__*/RoomMessagesHistory_regenerator().m(function
|
|
1626
|
-
var
|
|
1627
|
-
return RoomMessagesHistory_regenerator().w(function (
|
|
1628
|
-
while (1) switch (
|
|
1789
|
+
var _handleRoomUpdated = RoomMessagesHistory_asyncToGenerator(/*#__PURE__*/RoomMessagesHistory_regenerator().m(function _callee3(ev) {
|
|
1790
|
+
var _i2, _Array$from2, _Array$from2$_i, window;
|
|
1791
|
+
return RoomMessagesHistory_regenerator().w(function (_context3) {
|
|
1792
|
+
while (1) switch (_context3.n) {
|
|
1629
1793
|
case 0:
|
|
1630
1794
|
if (!(this.room.id === ev.room.id)) {
|
|
1631
|
-
|
|
1795
|
+
_context3.n = 3;
|
|
1632
1796
|
break;
|
|
1633
1797
|
}
|
|
1634
1798
|
this.room = ev.room;
|
|
@@ -1636,25 +1800,25 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
|
|
|
1636
1800
|
if (ev.room.defaultTopic) {
|
|
1637
1801
|
this.createHistoryWindowForTopic(ev.room.defaultTopic);
|
|
1638
1802
|
}
|
|
1639
|
-
|
|
1803
|
+
_i2 = 0, _Array$from2 = Array.from(this.historyWindows.items);
|
|
1640
1804
|
case 1:
|
|
1641
|
-
if (!(
|
|
1642
|
-
|
|
1805
|
+
if (!(_i2 < _Array$from2.length)) {
|
|
1806
|
+
_context3.n = 3;
|
|
1643
1807
|
break;
|
|
1644
1808
|
}
|
|
1645
|
-
_Array$
|
|
1646
|
-
|
|
1809
|
+
_Array$from2$_i = RoomMessagesHistory_slicedToArray(_Array$from2[_i2], 2), window = _Array$from2$_i[1];
|
|
1810
|
+
_context3.n = 2;
|
|
1647
1811
|
return window.setTraverseLock(this.traverseLock);
|
|
1648
1812
|
case 2:
|
|
1649
|
-
|
|
1650
|
-
|
|
1813
|
+
_i2++;
|
|
1814
|
+
_context3.n = 1;
|
|
1651
1815
|
break;
|
|
1652
1816
|
case 3:
|
|
1653
|
-
return
|
|
1817
|
+
return _context3.a(2);
|
|
1654
1818
|
}
|
|
1655
|
-
},
|
|
1819
|
+
}, _callee3, this);
|
|
1656
1820
|
}));
|
|
1657
|
-
function handleRoomUpdated(
|
|
1821
|
+
function handleRoomUpdated(_x3) {
|
|
1658
1822
|
return _handleRoomUpdated.apply(this, arguments);
|
|
1659
1823
|
}
|
|
1660
1824
|
return handleRoomUpdated;
|
|
@@ -1718,6 +1882,9 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
|
|
|
1718
1882
|
}();
|
|
1719
1883
|
;// ./src/state-tracker/MessagesManager.ts
|
|
1720
1884
|
function MessagesManager_typeof(o) { "@babel/helpers - typeof"; return MessagesManager_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, MessagesManager_typeof(o); }
|
|
1885
|
+
function MessagesManager_createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = MessagesManager_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
1886
|
+
function MessagesManager_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return MessagesManager_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? MessagesManager_arrayLikeToArray(r, a) : void 0; } }
|
|
1887
|
+
function MessagesManager_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
1721
1888
|
function MessagesManager_regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return MessagesManager_regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (MessagesManager_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, MessagesManager_regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, MessagesManager_regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), MessagesManager_regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", MessagesManager_regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), MessagesManager_regeneratorDefine2(u), MessagesManager_regeneratorDefine2(u, o, "Generator"), MessagesManager_regeneratorDefine2(u, n, function () { return this; }), MessagesManager_regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (MessagesManager_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
1722
1889
|
function MessagesManager_regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } MessagesManager_regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { MessagesManager_regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, MessagesManager_regeneratorDefine2(e, r, n, t); }
|
|
1723
1890
|
function MessagesManager_asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
@@ -1840,11 +2007,38 @@ var MessagesManager = /*#__PURE__*/function () {
|
|
|
1840
2007
|
}, {
|
|
1841
2008
|
key: "handleSession",
|
|
1842
2009
|
value: function handleSession(ev) {
|
|
1843
|
-
var
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
2010
|
+
var stateRoomIds = new Set(ev.state.rooms.map(function (room) {
|
|
2011
|
+
return room.id;
|
|
2012
|
+
}));
|
|
2013
|
+
|
|
2014
|
+
// Drop histories only for rooms that no longer exist server-side.
|
|
2015
|
+
for (var _i = 0, _Array$from = Array.from(this.roomHistories.items.keys()); _i < _Array$from.length; _i++) {
|
|
2016
|
+
var roomId = _Array$from[_i];
|
|
2017
|
+
if (!stateRoomIds.has(roomId)) {
|
|
2018
|
+
this.roomHistories["delete"](roomId);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
// Keep existing histories (preserving loaded messages and, crucially,
|
|
2023
|
+
// live-only ephemeral history), create histories for newly joined
|
|
2024
|
+
// rooms, and resync survivors against the fresh room snapshot.
|
|
2025
|
+
var _iterator = MessagesManager_createForOfIteratorHelper(ev.state.rooms),
|
|
2026
|
+
_step;
|
|
2027
|
+
try {
|
|
2028
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2029
|
+
var room = _step.value;
|
|
2030
|
+
var history = this.roomHistories.get(room.id);
|
|
2031
|
+
if (history) {
|
|
2032
|
+
void history.resync(room);
|
|
2033
|
+
} else {
|
|
2034
|
+
this.createHistoryForNewRoom(room);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
} catch (err) {
|
|
2038
|
+
_iterator.e(err);
|
|
2039
|
+
} finally {
|
|
2040
|
+
_iterator.f();
|
|
2041
|
+
}
|
|
1848
2042
|
this.deferredSession.resolve();
|
|
1849
2043
|
}
|
|
1850
2044
|
}]);
|
|
@@ -1889,6 +2083,11 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
1889
2083
|
FollowedTopicsManager_defineProperty(_this, "followedTopicsPromises", new PromiseRegistry());
|
|
1890
2084
|
FollowedTopicsManager_defineProperty(_this, "deferredSession", new DeferredTask());
|
|
1891
2085
|
FollowedTopicsManager_defineProperty(_this, "summariesCache", new Map());
|
|
2086
|
+
/**
|
|
2087
|
+
* Rooms whose cached followed-topics are stale after a reconnect and must
|
|
2088
|
+
* be refetched (and reconciled in place) the next time they are accessed.
|
|
2089
|
+
*/
|
|
2090
|
+
FollowedTopicsManager_defineProperty(_this, "staleRooms", new Set());
|
|
1892
2091
|
_this.tracker = tracker;
|
|
1893
2092
|
_this.tracker.client.on('Session', function (ev) {
|
|
1894
2093
|
return _this.handleSession(ev);
|
|
@@ -1934,7 +2133,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
1934
2133
|
value: (function () {
|
|
1935
2134
|
var _cacheForSpace = FollowedTopicsManager_asyncToGenerator(/*#__PURE__*/FollowedTopicsManager_regenerator().m(function _callee2(spaceId) {
|
|
1936
2135
|
var _this2 = this;
|
|
1937
|
-
var rooms, roomIds,
|
|
2136
|
+
var rooms, roomIds, needsFetch, spaceRegistryKey, _t;
|
|
1938
2137
|
return FollowedTopicsManager_regenerator().w(function (_context2) {
|
|
1939
2138
|
while (1) switch (_context2.n) {
|
|
1940
2139
|
case 0:
|
|
@@ -1971,10 +2170,10 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
1971
2170
|
}
|
|
1972
2171
|
return _context2.a(2);
|
|
1973
2172
|
case 5:
|
|
1974
|
-
|
|
1975
|
-
return _this2.followedTopics.has(roomId);
|
|
2173
|
+
needsFetch = roomIds.some(function (roomId) {
|
|
2174
|
+
return !_this2.followedTopics.has(roomId) || _this2.staleRooms.has(roomId);
|
|
1976
2175
|
});
|
|
1977
|
-
if (
|
|
2176
|
+
if (needsFetch) {
|
|
1978
2177
|
_context2.n = 6;
|
|
1979
2178
|
break;
|
|
1980
2179
|
}
|
|
@@ -2001,7 +2200,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2001
2200
|
}
|
|
2002
2201
|
throw result.error;
|
|
2003
2202
|
case 2:
|
|
2004
|
-
_this2.
|
|
2203
|
+
_this2.reconcileRoomsFollowedTopics(roomIds, result.data.followedTopics);
|
|
2005
2204
|
case 3:
|
|
2006
2205
|
return _context.a(2);
|
|
2007
2206
|
}
|
|
@@ -2042,7 +2241,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2042
2241
|
}
|
|
2043
2242
|
return _context4.a(2, undefined);
|
|
2044
2243
|
case 2:
|
|
2045
|
-
if (this.followedTopics.has(roomId)) {
|
|
2244
|
+
if (!(!this.followedTopics.has(roomId) || this.staleRooms.has(roomId))) {
|
|
2046
2245
|
_context4.n = 3;
|
|
2047
2246
|
break;
|
|
2048
2247
|
}
|
|
@@ -2066,7 +2265,8 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2066
2265
|
}
|
|
2067
2266
|
throw result.error;
|
|
2068
2267
|
case 2:
|
|
2069
|
-
_this3.
|
|
2268
|
+
_this3.applyRoomFollowedTopics(roomId, result.data.followedTopics);
|
|
2269
|
+
_this3.invalidateUnreadSummaries(roomId);
|
|
2070
2270
|
case 3:
|
|
2071
2271
|
return _context3.a(2);
|
|
2072
2272
|
}
|
|
@@ -2324,7 +2524,22 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2324
2524
|
}, {
|
|
2325
2525
|
key: "handleSession",
|
|
2326
2526
|
value: function handleSession(ev) {
|
|
2327
|
-
|
|
2527
|
+
// Keep cached followed-topic collections (they drive unread indicators
|
|
2528
|
+
// that would otherwise blank on reconnect), but mark them stale and drop
|
|
2529
|
+
// the fetch guards so the next access/caching refetches and reconciles
|
|
2530
|
+
// them in place.
|
|
2531
|
+
var _iterator4 = FollowedTopicsManager_createForOfIteratorHelper(this.followedTopics.items.keys()),
|
|
2532
|
+
_step4;
|
|
2533
|
+
try {
|
|
2534
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
2535
|
+
var roomId = _step4.value;
|
|
2536
|
+
this.staleRooms.add(roomId);
|
|
2537
|
+
}
|
|
2538
|
+
} catch (err) {
|
|
2539
|
+
_iterator4.e(err);
|
|
2540
|
+
} finally {
|
|
2541
|
+
_iterator4.f();
|
|
2542
|
+
}
|
|
2328
2543
|
this.followedTopicsPromises.forgetAll();
|
|
2329
2544
|
this.invalidateUnreadSummaries();
|
|
2330
2545
|
this.deferredSession.resolve();
|
|
@@ -2424,34 +2639,34 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2424
2639
|
if (topicId) {
|
|
2425
2640
|
this.summariesCache["delete"]("topic:".concat(roomId, ":").concat(topicId));
|
|
2426
2641
|
} else {
|
|
2427
|
-
var
|
|
2428
|
-
|
|
2642
|
+
var _iterator5 = FollowedTopicsManager_createForOfIteratorHelper(this.summariesCache.keys()),
|
|
2643
|
+
_step5;
|
|
2429
2644
|
try {
|
|
2430
|
-
for (
|
|
2431
|
-
var key =
|
|
2645
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
2646
|
+
var key = _step5.value;
|
|
2432
2647
|
if (key.startsWith("topic:".concat(roomId, ":"))) {
|
|
2433
2648
|
this.summariesCache["delete"](key);
|
|
2434
2649
|
}
|
|
2435
2650
|
}
|
|
2436
2651
|
} catch (err) {
|
|
2437
|
-
|
|
2652
|
+
_iterator5.e(err);
|
|
2438
2653
|
} finally {
|
|
2439
|
-
|
|
2654
|
+
_iterator5.f();
|
|
2440
2655
|
}
|
|
2441
2656
|
}
|
|
2442
|
-
var
|
|
2443
|
-
|
|
2657
|
+
var _iterator6 = FollowedTopicsManager_createForOfIteratorHelper(this.summariesCache.keys()),
|
|
2658
|
+
_step6;
|
|
2444
2659
|
try {
|
|
2445
|
-
for (
|
|
2446
|
-
var _key2 =
|
|
2660
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
2661
|
+
var _key2 = _step6.value;
|
|
2447
2662
|
if (_key2.startsWith('space:') || _key2 === 'spaceless') {
|
|
2448
2663
|
this.summariesCache["delete"](_key2);
|
|
2449
2664
|
}
|
|
2450
2665
|
}
|
|
2451
2666
|
} catch (err) {
|
|
2452
|
-
|
|
2667
|
+
_iterator6.e(err);
|
|
2453
2668
|
} finally {
|
|
2454
|
-
|
|
2669
|
+
_iterator6.f();
|
|
2455
2670
|
}
|
|
2456
2671
|
} else {
|
|
2457
2672
|
this.summariesCache.clear();
|
|
@@ -2466,11 +2681,11 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2466
2681
|
roomIds.forEach(function (roomId) {
|
|
2467
2682
|
_this5.summariesCache["delete"]("room:".concat(roomId));
|
|
2468
2683
|
});
|
|
2469
|
-
var
|
|
2470
|
-
|
|
2684
|
+
var _iterator7 = FollowedTopicsManager_createForOfIteratorHelper(this.summariesCache.keys()),
|
|
2685
|
+
_step7;
|
|
2471
2686
|
try {
|
|
2472
|
-
for (
|
|
2473
|
-
var key =
|
|
2687
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
2688
|
+
var key = _step7.value;
|
|
2474
2689
|
if (key.startsWith('space:') || key === 'spaceless') {
|
|
2475
2690
|
this.summariesCache["delete"](key);
|
|
2476
2691
|
continue;
|
|
@@ -2483,9 +2698,9 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2483
2698
|
}
|
|
2484
2699
|
}
|
|
2485
2700
|
} catch (err) {
|
|
2486
|
-
|
|
2701
|
+
_iterator7.e(err);
|
|
2487
2702
|
} finally {
|
|
2488
|
-
|
|
2703
|
+
_iterator7.f();
|
|
2489
2704
|
}
|
|
2490
2705
|
this.emit('change');
|
|
2491
2706
|
}
|
|
@@ -2563,27 +2778,66 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2563
2778
|
}
|
|
2564
2779
|
return updateLocallyFollowedTopicOnNewMessage;
|
|
2565
2780
|
}()
|
|
2781
|
+
/**
|
|
2782
|
+
* Reconcile the followed-topics collection for a single room to exactly
|
|
2783
|
+
* match the provided list (upsert present, drop absent) without emitting an
|
|
2784
|
+
* intermediate empty state, and clear its stale marker. Does not touch the
|
|
2785
|
+
* unread summaries cache - callers decide how to invalidate it.
|
|
2786
|
+
*/
|
|
2787
|
+
}, {
|
|
2788
|
+
key: "applyRoomFollowedTopics",
|
|
2789
|
+
value: function applyRoomFollowedTopics(roomId, followedTopics) {
|
|
2790
|
+
var _this$followedTopics$5;
|
|
2791
|
+
if (!this.followedTopics.has(roomId)) {
|
|
2792
|
+
this.followedTopics.set([roomId, new ObservableIndexedObjectCollection(function (followedTopic) {
|
|
2793
|
+
return followedTopic.location.topicId;
|
|
2794
|
+
})]);
|
|
2795
|
+
}
|
|
2796
|
+
(_this$followedTopics$5 = this.followedTopics.get(roomId)).reconcile.apply(_this$followedTopics$5, FollowedTopicsManager_toConsumableArray(followedTopics));
|
|
2797
|
+
this.staleRooms["delete"](roomId);
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
/**
|
|
2801
|
+
* Reconcile a batch of rooms from a single bulk GetFollowedTopics response.
|
|
2802
|
+
* Rooms with no followed topics in the response are reconciled to empty, so
|
|
2803
|
+
* topics unfollowed/removed during the downtime are correctly dropped.
|
|
2804
|
+
*/
|
|
2805
|
+
}, {
|
|
2806
|
+
key: "reconcileRoomsFollowedTopics",
|
|
2807
|
+
value: function reconcileRoomsFollowedTopics(roomIds, followedTopics) {
|
|
2808
|
+
var _this6 = this;
|
|
2809
|
+
var roomToTopics = {};
|
|
2810
|
+
followedTopics.forEach(function (followedTopic) {
|
|
2811
|
+
var _followedTopic$locati, _roomToTopics$_follow;
|
|
2812
|
+
((_roomToTopics$_follow = roomToTopics[_followedTopic$locati = followedTopic.location.roomId]) !== null && _roomToTopics$_follow !== void 0 ? _roomToTopics$_follow : roomToTopics[_followedTopic$locati] = []).push(followedTopic);
|
|
2813
|
+
});
|
|
2814
|
+
roomIds.forEach(function (roomId) {
|
|
2815
|
+
var _roomToTopics$roomId;
|
|
2816
|
+
return _this6.applyRoomFollowedTopics(roomId, (_roomToTopics$roomId = roomToTopics[roomId]) !== null && _roomToTopics$roomId !== void 0 ? _roomToTopics$roomId : []);
|
|
2817
|
+
});
|
|
2818
|
+
this.invalidateUnreadSummariesForRooms(roomIds);
|
|
2819
|
+
}
|
|
2566
2820
|
}, {
|
|
2567
2821
|
key: "setFollowedTopicsArray",
|
|
2568
2822
|
value: function setFollowedTopicsArray(roomIds, followedTopics) {
|
|
2569
|
-
var
|
|
2823
|
+
var _this7 = this;
|
|
2570
2824
|
var roomToTopics = {};
|
|
2571
2825
|
|
|
2572
2826
|
// Reassign followed topics to limit collection change event emit
|
|
2573
2827
|
followedTopics.forEach(function (followedTopic) {
|
|
2574
|
-
var _followedTopic$
|
|
2575
|
-
(_roomToTopics$
|
|
2828
|
+
var _followedTopic$locati2, _roomToTopics$_follow2;
|
|
2829
|
+
(_roomToTopics$_follow2 = roomToTopics[_followedTopic$locati2 = followedTopic.location.roomId]) !== null && _roomToTopics$_follow2 !== void 0 ? _roomToTopics$_follow2 : roomToTopics[_followedTopic$locati2] = [];
|
|
2576
2830
|
roomToTopics[followedTopic.location.roomId].push(followedTopic);
|
|
2577
2831
|
});
|
|
2578
2832
|
roomIds.forEach(function (roomId) {
|
|
2579
|
-
if (!
|
|
2580
|
-
|
|
2833
|
+
if (!_this7.followedTopics.has(roomId)) {
|
|
2834
|
+
_this7.followedTopics.set([roomId, new ObservableIndexedObjectCollection(function (followedTopic) {
|
|
2581
2835
|
return followedTopic.location.topicId;
|
|
2582
2836
|
})]);
|
|
2583
2837
|
}
|
|
2584
2838
|
if (roomToTopics[roomId]) {
|
|
2585
|
-
var
|
|
2586
|
-
(
|
|
2839
|
+
var _this7$followedTopics;
|
|
2840
|
+
(_this7$followedTopics = _this7.followedTopics.get(roomId)).set.apply(_this7$followedTopics, FollowedTopicsManager_toConsumableArray(roomToTopics[roomId]));
|
|
2587
2841
|
}
|
|
2588
2842
|
});
|
|
2589
2843
|
this.invalidateUnreadSummariesForRooms(roomIds);
|
|
@@ -2593,6 +2847,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2593
2847
|
value: function clearRoomFollowedTopicsStructures(roomId) {
|
|
2594
2848
|
this.followedTopics["delete"](roomId);
|
|
2595
2849
|
this.followedTopicsPromises.forget(roomId);
|
|
2850
|
+
this.staleRooms["delete"](roomId);
|
|
2596
2851
|
this.invalidateUnreadSummaries(roomId);
|
|
2597
2852
|
}
|
|
2598
2853
|
}]);
|
|
@@ -3108,16 +3363,39 @@ var RoomsManager = /*#__PURE__*/function () {
|
|
|
3108
3363
|
var _member$user$id2, _member$user2;
|
|
3109
3364
|
return (_member$user$id2 = (_member$user2 = member.user) === null || _member$user2 === void 0 ? void 0 : _member$user2.id) !== null && _member$user$id2 !== void 0 ? _member$user$id2 : member.spaceMember.user.id;
|
|
3110
3365
|
}, ev.members)]);
|
|
3366
|
+
} else {
|
|
3367
|
+
var _this$members$get;
|
|
3368
|
+
// Reconcile into the existing (bound) collection so a reconnect
|
|
3369
|
+
// refetch updates it in place instead of leaving stale members.
|
|
3370
|
+
(_this$members$get = this.members.get(ev.id)).reconcile.apply(_this$members$get, RoomsManager_toConsumableArray(ev.members));
|
|
3111
3371
|
}
|
|
3112
3372
|
}
|
|
3113
3373
|
}, {
|
|
3114
3374
|
key: "handleSession",
|
|
3115
3375
|
value: function handleSession(ev) {
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3376
|
+
var stateRoomIds = new Set(ev.state.rooms.map(function (room) {
|
|
3377
|
+
return room.id;
|
|
3378
|
+
}));
|
|
3379
|
+
|
|
3380
|
+
// Remove only rooms that were left/deleted on the server during the
|
|
3381
|
+
// downtime, reusing the cascade cleanup (members, topics, followed
|
|
3382
|
+
// topics). Surviving rooms keep their identity and bindings.
|
|
3383
|
+
var removedRoomIds = this.list.items.filter(function (room) {
|
|
3384
|
+
return !stateRoomIds.has(room.id);
|
|
3385
|
+
}).map(function (room) {
|
|
3386
|
+
return room.id;
|
|
3387
|
+
});
|
|
3388
|
+
if (removedRoomIds.length) {
|
|
3389
|
+
this.deleteRoom.apply(this, RoomsManager_toConsumableArray(removedRoomIds));
|
|
3390
|
+
}
|
|
3391
|
+
|
|
3392
|
+
// Invalidate lazy caches so the next access refetches fresh data, but
|
|
3393
|
+
// keep the collection objects: handleRoomMembers reconciles into them,
|
|
3394
|
+
// so bound views refresh in place without blanking.
|
|
3120
3395
|
this.membersPromises.forgetAll();
|
|
3396
|
+
this.topicsPromises.forgetAll();
|
|
3397
|
+
|
|
3398
|
+
// Upsert surviving/new rooms from the authoritative snapshot.
|
|
3121
3399
|
this.addJoinedRooms.apply(this, RoomsManager_toConsumableArray(ev.state.rooms));
|
|
3122
3400
|
this.deferredSession.resolve();
|
|
3123
3401
|
}
|
|
@@ -3251,6 +3529,7 @@ function extractUserFromMember(member) {
|
|
|
3251
3529
|
}
|
|
3252
3530
|
;// ./src/state-tracker/SpacesManager.ts
|
|
3253
3531
|
function SpacesManager_typeof(o) { "@babel/helpers - typeof"; return SpacesManager_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, SpacesManager_typeof(o); }
|
|
3532
|
+
function SpacesManager_createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = SpacesManager_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
3254
3533
|
function SpacesManager_toConsumableArray(r) { return SpacesManager_arrayWithoutHoles(r) || SpacesManager_iterableToArray(r) || SpacesManager_unsupportedIterableToArray(r) || SpacesManager_nonIterableSpread(); }
|
|
3255
3534
|
function SpacesManager_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3256
3535
|
function SpacesManager_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return SpacesManager_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? SpacesManager_arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -3341,8 +3620,8 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3341
3620
|
});
|
|
3342
3621
|
}
|
|
3343
3622
|
|
|
3344
|
-
/**
|
|
3345
|
-
* Get collection of all the spaces you are in.
|
|
3623
|
+
/**
|
|
3624
|
+
* Get collection of all the spaces you are in.
|
|
3346
3625
|
*/
|
|
3347
3626
|
return SpacesManager_createClass(SpacesManager, [{
|
|
3348
3627
|
key: "get",
|
|
@@ -3363,8 +3642,8 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3363
3642
|
}
|
|
3364
3643
|
return get;
|
|
3365
3644
|
}()
|
|
3366
|
-
/**
|
|
3367
|
-
* Get collection of space roles.
|
|
3645
|
+
/**
|
|
3646
|
+
* Get collection of space roles.
|
|
3368
3647
|
*/
|
|
3369
3648
|
)
|
|
3370
3649
|
}, {
|
|
@@ -3386,8 +3665,8 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3386
3665
|
}
|
|
3387
3666
|
return getRoles;
|
|
3388
3667
|
}()
|
|
3389
|
-
/**
|
|
3390
|
-
* Get collection of the all available rooms inside given space.
|
|
3668
|
+
/**
|
|
3669
|
+
* Get collection of the all available rooms inside given space.
|
|
3391
3670
|
*/
|
|
3392
3671
|
)
|
|
3393
3672
|
}, {
|
|
@@ -3435,8 +3714,8 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3435
3714
|
}
|
|
3436
3715
|
return getRooms;
|
|
3437
3716
|
}()
|
|
3438
|
-
/**
|
|
3439
|
-
* Get collection of space members.
|
|
3717
|
+
/**
|
|
3718
|
+
* Get collection of space members.
|
|
3440
3719
|
*/
|
|
3441
3720
|
)
|
|
3442
3721
|
}, {
|
|
@@ -3484,8 +3763,8 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3484
3763
|
}
|
|
3485
3764
|
return getMembers;
|
|
3486
3765
|
}()
|
|
3487
|
-
/**
|
|
3488
|
-
* Get a space member representing the current user.
|
|
3766
|
+
/**
|
|
3767
|
+
* Get a space member representing the current user.
|
|
3489
3768
|
*/
|
|
3490
3769
|
)
|
|
3491
3770
|
}, {
|
|
@@ -3654,6 +3933,11 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3654
3933
|
this.members.set([ev.id, new ObservableIndexedObjectCollection(function (member) {
|
|
3655
3934
|
return member === null || member === void 0 ? void 0 : member.user.id;
|
|
3656
3935
|
}, ev.members)]);
|
|
3936
|
+
} else {
|
|
3937
|
+
var _this$members$get;
|
|
3938
|
+
// Reconcile into the existing (bound) collection so a reconnect
|
|
3939
|
+
// refetch updates it in place instead of leaving stale members.
|
|
3940
|
+
(_this$members$get = this.members.get(ev.id)).reconcile.apply(_this$members$get, SpacesManager_toConsumableArray(ev.members));
|
|
3657
3941
|
}
|
|
3658
3942
|
}
|
|
3659
3943
|
}, {
|
|
@@ -3662,10 +3946,13 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3662
3946
|
var _this4 = this;
|
|
3663
3947
|
if (!this.rooms.has(ev.id)) {
|
|
3664
3948
|
this.rooms.set([ev.id, new ObservableIndexedObjectCollection('id', ev.summaries)]);
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3949
|
+
} else {
|
|
3950
|
+
var _this$rooms$get4;
|
|
3951
|
+
(_this$rooms$get4 = this.rooms.get(ev.id)).reconcile.apply(_this$rooms$get4, SpacesManager_toConsumableArray(ev.summaries));
|
|
3668
3952
|
}
|
|
3953
|
+
ev.summaries.forEach(function (summary) {
|
|
3954
|
+
return _this4.roomIdToSpaceId.set([summary.id, ev.id]);
|
|
3955
|
+
});
|
|
3669
3956
|
}
|
|
3670
3957
|
}, {
|
|
3671
3958
|
key: "handleRoomSummaryUpdated",
|
|
@@ -3677,9 +3964,9 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3677
3964
|
case 0:
|
|
3678
3965
|
spaceId = this.roomIdToSpaceId.get(ev.summary.id);
|
|
3679
3966
|
summariesPromise = this.roomsPromises.get(spaceId);
|
|
3680
|
-
/**
|
|
3681
|
-
* Update summary only if the list was already loaded.
|
|
3682
|
-
* RoomSummaryUpdated event has a partial summary, so we need to update the existing summary by merging it.
|
|
3967
|
+
/**
|
|
3968
|
+
* Update summary only if the list was already loaded.
|
|
3969
|
+
* RoomSummaryUpdated event has a partial summary, so we need to update the existing summary by merging it.
|
|
3683
3970
|
*/
|
|
3684
3971
|
if (!(spaceId && summariesPromise)) {
|
|
3685
3972
|
_context9.n = 2;
|
|
@@ -3733,14 +4020,58 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3733
4020
|
}, {
|
|
3734
4021
|
key: "handleSession",
|
|
3735
4022
|
value: function handleSession(ev) {
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
4023
|
+
var _this$list2;
|
|
4024
|
+
var stateSpaceIds = new Set(ev.state.spaces.map(function (space) {
|
|
4025
|
+
return space.id;
|
|
4026
|
+
}));
|
|
4027
|
+
|
|
4028
|
+
// Remove only spaces that were left/deleted on the server during the
|
|
4029
|
+
// downtime, reusing the cascade cleanup (roles, rooms, members, index).
|
|
4030
|
+
var removedSpaceIds = this.list.items.filter(function (space) {
|
|
4031
|
+
return !stateSpaceIds.has(space.id);
|
|
4032
|
+
}).map(function (space) {
|
|
4033
|
+
return space.id;
|
|
4034
|
+
});
|
|
4035
|
+
var _iterator = SpacesManager_createForOfIteratorHelper(removedSpaceIds),
|
|
4036
|
+
_step;
|
|
4037
|
+
try {
|
|
4038
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
4039
|
+
var spaceId = _step.value;
|
|
4040
|
+
this.handleSpaceDeleted({
|
|
4041
|
+
id: spaceId
|
|
4042
|
+
});
|
|
4043
|
+
}
|
|
4044
|
+
|
|
4045
|
+
// Invalidate lazy caches (rooms/members) but keep their objects so the
|
|
4046
|
+
// next access refetches and reconciles them in place.
|
|
4047
|
+
} catch (err) {
|
|
4048
|
+
_iterator.e(err);
|
|
4049
|
+
} finally {
|
|
4050
|
+
_iterator.f();
|
|
4051
|
+
}
|
|
3739
4052
|
this.roomsPromises.forgetAll();
|
|
3740
|
-
this.members.deleteAll();
|
|
3741
4053
|
this.membersPromises.forgetAll();
|
|
3742
|
-
|
|
3743
|
-
|
|
4054
|
+
|
|
4055
|
+
// Reconcile roles in place (kept, possibly bound object) and upsert the
|
|
4056
|
+
// spaces from the authoritative snapshot.
|
|
4057
|
+
var _iterator2 = SpacesManager_createForOfIteratorHelper(ev.state.spaces),
|
|
4058
|
+
_step2;
|
|
4059
|
+
try {
|
|
4060
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
4061
|
+
var space = _step2.value;
|
|
4062
|
+
if (this.roles.has(space.id)) {
|
|
4063
|
+
var _this$roles$get2;
|
|
4064
|
+
(_this$roles$get2 = this.roles.get(space.id)).reconcile.apply(_this$roles$get2, SpacesManager_toConsumableArray(space.roles));
|
|
4065
|
+
} else {
|
|
4066
|
+
this.roles.set([space.id, new ObservableIndexedObjectCollection('id', space.roles)]);
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4069
|
+
} catch (err) {
|
|
4070
|
+
_iterator2.e(err);
|
|
4071
|
+
} finally {
|
|
4072
|
+
_iterator2.f();
|
|
4073
|
+
}
|
|
4074
|
+
(_this$list2 = this.list).set.apply(_this$list2, SpacesManager_toConsumableArray(ev.state.spaces));
|
|
3744
4075
|
this.deferredSession.resolve();
|
|
3745
4076
|
}
|
|
3746
4077
|
}, {
|
|
@@ -4464,8 +4795,12 @@ var PermissionsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
4464
4795
|
}, {
|
|
4465
4796
|
key: "handleSession",
|
|
4466
4797
|
value: function handleSession(ev) {
|
|
4467
|
-
|
|
4798
|
+
// Drop the fetch guards so permission checks recompute against fresh
|
|
4799
|
+
// overwrites (getOverwrites refetches and upserts on the next access),
|
|
4800
|
+
// and notify consumers to recompute so bound permission UI is never
|
|
4801
|
+
// left showing stale results after a reconnect.
|
|
4468
4802
|
this.overwritesPromises.forgetAll();
|
|
4803
|
+
this.emit('change');
|
|
4469
4804
|
}
|
|
4470
4805
|
}]);
|
|
4471
4806
|
}(EventTarget);
|
|
@@ -4563,13 +4898,16 @@ var EmoticonsManager = /*#__PURE__*/function () {
|
|
|
4563
4898
|
}, {
|
|
4564
4899
|
key: "handleEmoticons",
|
|
4565
4900
|
value: function handleEmoticons(event) {
|
|
4566
|
-
var _event$location$space;
|
|
4901
|
+
var _event$location$space, _this$list$get;
|
|
4567
4902
|
var spaceId = (_event$location$space = event.location.spaceId) !== null && _event$location$space !== void 0 ? _event$location$space : GLOBAL_KEY;
|
|
4568
4903
|
if (!this.list.has(spaceId)) {
|
|
4569
4904
|
this.list.set([spaceId, new ObservableIndexedObjectCollection('id')]);
|
|
4570
4905
|
}
|
|
4571
|
-
|
|
4572
|
-
|
|
4906
|
+
|
|
4907
|
+
// handleEmoticons always carries the full list for a location, so
|
|
4908
|
+
// reconcile in place: a reconnect refetch drops removed emoticons and
|
|
4909
|
+
// adds new ones without blanking a bound (visible) collection.
|
|
4910
|
+
(_this$list$get = this.list.get(spaceId)).reconcile.apply(_this$list$get, EmoticonsManager_toConsumableArray(event.emoticons));
|
|
4573
4911
|
}
|
|
4574
4912
|
}, {
|
|
4575
4913
|
key: "handleNewEmoticon",
|
|
@@ -4593,7 +4931,9 @@ var EmoticonsManager = /*#__PURE__*/function () {
|
|
|
4593
4931
|
}, {
|
|
4594
4932
|
key: "handleSession",
|
|
4595
4933
|
value: function handleSession() {
|
|
4596
|
-
|
|
4934
|
+
// Keep cached emoticon collections (they may be bound to visible
|
|
4935
|
+
// pickers); just drop the fetch guards so the next access refetches and
|
|
4936
|
+
// reconciles them in place.
|
|
4597
4937
|
this.emoticonsPromises.forgetAll();
|
|
4598
4938
|
}
|
|
4599
4939
|
}]);
|
|
@@ -4682,7 +5022,9 @@ var UsersManager = /*#__PURE__*/function () {
|
|
|
4682
5022
|
}, {
|
|
4683
5023
|
key: "handleSession",
|
|
4684
5024
|
value: function handleSession(session) {
|
|
4685
|
-
|
|
5025
|
+
// Keep the "seen users" cache across reconnects so bound user lists do
|
|
5026
|
+
// not blank out; just ensure our own user is present/updated. Stale
|
|
5027
|
+
// entries are refreshed as member/message collections refetch.
|
|
4686
5028
|
this.handleUsers([session.user]);
|
|
4687
5029
|
}
|
|
4688
5030
|
}, {
|
|
@@ -4702,6 +5044,12 @@ var UsersManager = /*#__PURE__*/function () {
|
|
|
4702
5044
|
}();
|
|
4703
5045
|
;// ./src/state-tracker/RelationshipsManager.ts
|
|
4704
5046
|
function RelationshipsManager_typeof(o) { "@babel/helpers - typeof"; return RelationshipsManager_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, RelationshipsManager_typeof(o); }
|
|
5047
|
+
function RelationshipsManager_toConsumableArray(r) { return RelationshipsManager_arrayWithoutHoles(r) || RelationshipsManager_iterableToArray(r) || RelationshipsManager_unsupportedIterableToArray(r) || RelationshipsManager_nonIterableSpread(); }
|
|
5048
|
+
function RelationshipsManager_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5049
|
+
function RelationshipsManager_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return RelationshipsManager_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? RelationshipsManager_arrayLikeToArray(r, a) : void 0; } }
|
|
5050
|
+
function RelationshipsManager_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
5051
|
+
function RelationshipsManager_arrayWithoutHoles(r) { if (Array.isArray(r)) return RelationshipsManager_arrayLikeToArray(r); }
|
|
5052
|
+
function RelationshipsManager_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4705
5053
|
function RelationshipsManager_regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return RelationshipsManager_regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (RelationshipsManager_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, RelationshipsManager_regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, RelationshipsManager_regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), RelationshipsManager_regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", RelationshipsManager_regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), RelationshipsManager_regeneratorDefine2(u), RelationshipsManager_regeneratorDefine2(u, o, "Generator"), RelationshipsManager_regeneratorDefine2(u, n, function () { return this; }), RelationshipsManager_regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (RelationshipsManager_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
4706
5054
|
function RelationshipsManager_regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } RelationshipsManager_regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { RelationshipsManager_regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, RelationshipsManager_regeneratorDefine2(e, r, n, t); }
|
|
4707
5055
|
function RelationshipsManager_asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
@@ -4803,11 +5151,10 @@ var RelationshipsManager = /*#__PURE__*/function () {
|
|
|
4803
5151
|
}, {
|
|
4804
5152
|
key: "handleRelationships",
|
|
4805
5153
|
value: function handleRelationships(ev) {
|
|
4806
|
-
var
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
});
|
|
5154
|
+
var _this$relationships;
|
|
5155
|
+
// Full list from the server: reconcile in place so a reconnect refetch
|
|
5156
|
+
// updates a bound (visible) list without an intermediate empty state.
|
|
5157
|
+
(_this$relationships = this.relationships).reconcile.apply(_this$relationships, RelationshipsManager_toConsumableArray(ev.relationships));
|
|
4811
5158
|
}
|
|
4812
5159
|
}, {
|
|
4813
5160
|
key: "handleNewRelationship",
|
|
@@ -4826,8 +5173,9 @@ var RelationshipsManager = /*#__PURE__*/function () {
|
|
|
4826
5173
|
}, {
|
|
4827
5174
|
key: "handleSession",
|
|
4828
5175
|
value: function handleSession() {
|
|
5176
|
+
// Keep the (possibly bound) collection; just drop the fetch guard so the
|
|
5177
|
+
// next get() refetches and reconciles it in place.
|
|
4829
5178
|
this.promises.forgetAll();
|
|
4830
|
-
this.relationships.deleteAll();
|
|
4831
5179
|
}
|
|
4832
5180
|
}]);
|
|
4833
5181
|
}();
|
|
@@ -4926,6 +5274,9 @@ var ChatStateTracker = /*#__PURE__*/function () {
|
|
|
4926
5274
|
}();
|
|
4927
5275
|
;// ./src/WebSocketChatClient.ts
|
|
4928
5276
|
function WebSocketChatClient_typeof(o) { "@babel/helpers - typeof"; return WebSocketChatClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, WebSocketChatClient_typeof(o); }
|
|
5277
|
+
function WebSocketChatClient_createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = WebSocketChatClient_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
5278
|
+
function WebSocketChatClient_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return WebSocketChatClient_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? WebSocketChatClient_arrayLikeToArray(r, a) : void 0; } }
|
|
5279
|
+
function WebSocketChatClient_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4929
5280
|
function WebSocketChatClient_regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return WebSocketChatClient_regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (WebSocketChatClient_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, WebSocketChatClient_regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, WebSocketChatClient_regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), WebSocketChatClient_regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", WebSocketChatClient_regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), WebSocketChatClient_regeneratorDefine2(u), WebSocketChatClient_regeneratorDefine2(u, o, "Generator"), WebSocketChatClient_regeneratorDefine2(u, n, function () { return this; }), WebSocketChatClient_regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (WebSocketChatClient_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
4930
5281
|
function WebSocketChatClient_regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } WebSocketChatClient_regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { WebSocketChatClient_regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, WebSocketChatClient_regeneratorDefine2(e, r, n, t); }
|
|
4931
5282
|
function WebSocketChatClient_asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
@@ -4964,7 +5315,13 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
4964
5315
|
WebSocketChatClient_defineProperty(_this, "sendQueue", []);
|
|
4965
5316
|
WebSocketChatClient_defineProperty(_this, "connectingTimeoutId", void 0);
|
|
4966
5317
|
WebSocketChatClient_defineProperty(_this, "authenticated", void 0);
|
|
4967
|
-
WebSocketChatClient_defineProperty(_this, "authenticatedResolvers",
|
|
5318
|
+
WebSocketChatClient_defineProperty(_this, "authenticatedResolvers", null);
|
|
5319
|
+
/**
|
|
5320
|
+
* Pending promise returned by connect(). Kept until the client is either
|
|
5321
|
+
* authenticated or gives up, so that an automatic reconnect settles the
|
|
5322
|
+
* original caller instead of stranding it on a superseded promise.
|
|
5323
|
+
*/
|
|
5324
|
+
WebSocketChatClient_defineProperty(_this, "connectPromise", null);
|
|
4968
5325
|
WebSocketChatClient_defineProperty(_this, "pingMonitorInterval", void 0);
|
|
4969
5326
|
WebSocketChatClient_defineProperty(_this, "inFlightPingTimeout", void 0);
|
|
4970
5327
|
WebSocketChatClient_defineProperty(_this, "lastReceivedMessageAt", void 0);
|
|
@@ -4983,10 +5340,11 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
4983
5340
|
key: "connect",
|
|
4984
5341
|
value: function () {
|
|
4985
5342
|
var _connect = WebSocketChatClient_asyncToGenerator(/*#__PURE__*/WebSocketChatClient_regenerator().m(function _callee() {
|
|
4986
|
-
var _this$
|
|
5343
|
+
var _this$connectPromise2,
|
|
4987
5344
|
_this2 = this,
|
|
5345
|
+
_this$options$queryPa,
|
|
4988
5346
|
_this$options$connect;
|
|
4989
|
-
var params;
|
|
5347
|
+
var _this$connectPromise, params;
|
|
4990
5348
|
return WebSocketChatClient_regenerator().w(function (_context) {
|
|
4991
5349
|
while (1) switch (_context.n) {
|
|
4992
5350
|
case 0:
|
|
@@ -4994,8 +5352,17 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
4994
5352
|
_context.n = 1;
|
|
4995
5353
|
break;
|
|
4996
5354
|
}
|
|
4997
|
-
return _context.a(2);
|
|
5355
|
+
return _context.a(2, (_this$connectPromise = this.connectPromise) !== null && _this$connectPromise !== void 0 ? _this$connectPromise : undefined);
|
|
4998
5356
|
case 1:
|
|
5357
|
+
// Reuse the promise of an attempt that has not settled yet (an
|
|
5358
|
+
// automatic reconnect), so the caller that started connecting is
|
|
5359
|
+
// resolved by whichever attempt eventually authenticates.
|
|
5360
|
+
(_this$connectPromise2 = this.connectPromise) !== null && _this$connectPromise2 !== void 0 ? _this$connectPromise2 : this.connectPromise = new Promise(function () {
|
|
5361
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5362
|
+
args[_key] = arguments[_key];
|
|
5363
|
+
}
|
|
5364
|
+
return _this2.authenticatedResolvers = args;
|
|
5365
|
+
});
|
|
4999
5366
|
params = new URLSearchParams((_this$options$queryPa = this.options.queryParams) !== null && _this$options$queryPa !== void 0 ? _this$options$queryPa : {});
|
|
5000
5367
|
params.set('token', this.options.token);
|
|
5001
5368
|
this.ws = new WebSocket("".concat(this.options.url, "?").concat(params));
|
|
@@ -5009,12 +5376,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5009
5376
|
return _this2.triggerConnectionTimeout();
|
|
5010
5377
|
}, (_this$options$connect = this.options.connectingTimeoutMs) !== null && _this$options$connect !== void 0 ? _this$options$connect : 10000);
|
|
5011
5378
|
this.authenticated = false;
|
|
5012
|
-
return _context.a(2,
|
|
5013
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5014
|
-
args[_key] = arguments[_key];
|
|
5015
|
-
}
|
|
5016
|
-
return _this2.authenticatedResolvers = args;
|
|
5017
|
-
}));
|
|
5379
|
+
return _context.a(2, this.connectPromise);
|
|
5018
5380
|
}
|
|
5019
5381
|
}, _callee, this);
|
|
5020
5382
|
}));
|
|
@@ -5027,7 +5389,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5027
5389
|
key: "disconnect",
|
|
5028
5390
|
value: function disconnect() {
|
|
5029
5391
|
var _this$ws;
|
|
5030
|
-
this.
|
|
5392
|
+
this.failPendingCommands(new Error('Client disconnected before the command was answered'));
|
|
5031
5393
|
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.close(1000); // Normal closure
|
|
5032
5394
|
this.ws = null;
|
|
5033
5395
|
}
|
|
@@ -5088,11 +5450,11 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5088
5450
|
this.authenticated = isAuthenticated;
|
|
5089
5451
|
if (isAuthenticated) {
|
|
5090
5452
|
this.startConnectionMonitor();
|
|
5091
|
-
this.
|
|
5453
|
+
this.settleConnect();
|
|
5092
5454
|
this.emit(this.Event.connect);
|
|
5093
5455
|
this.sendFromQueue();
|
|
5094
5456
|
} else {
|
|
5095
|
-
this.
|
|
5457
|
+
this.settleConnect(envelope.data);
|
|
5096
5458
|
}
|
|
5097
5459
|
}
|
|
5098
5460
|
}
|
|
@@ -5102,11 +5464,59 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5102
5464
|
this.stopConnectionMonitor();
|
|
5103
5465
|
clearTimeout(this.connectingTimeoutId);
|
|
5104
5466
|
var reconnect = event.code !== 1000; // Connection was closed because of error
|
|
5467
|
+
|
|
5468
|
+
// The server can no longer answer anything that was queued or in
|
|
5469
|
+
// flight, so settle those promises instead of leaving them pending.
|
|
5470
|
+
this.failPendingCommands(new Error('Connection closed before the command was answered'));
|
|
5105
5471
|
if (reconnect) {
|
|
5472
|
+
// Keep a pending connect() promise unsettled - the retry below is
|
|
5473
|
+
// expected to authenticate and will resolve it.
|
|
5106
5474
|
void this.connect();
|
|
5475
|
+
} else {
|
|
5476
|
+
this.settleConnect(new Error('Connection closed before authentication'));
|
|
5107
5477
|
}
|
|
5108
5478
|
this.emit(this.Event.disconnect, reconnect);
|
|
5109
5479
|
}
|
|
5480
|
+
|
|
5481
|
+
/**
|
|
5482
|
+
* Resolve (or reject, when an error is given) a pending connect() promise.
|
|
5483
|
+
* No-op when there is nothing pending.
|
|
5484
|
+
*/
|
|
5485
|
+
}, {
|
|
5486
|
+
key: "settleConnect",
|
|
5487
|
+
value: function settleConnect(error) {
|
|
5488
|
+
var resolvers = this.authenticatedResolvers;
|
|
5489
|
+
this.authenticatedResolvers = null;
|
|
5490
|
+
this.connectPromise = null;
|
|
5491
|
+
if (!resolvers) {
|
|
5492
|
+
return;
|
|
5493
|
+
}
|
|
5494
|
+
error ? resolvers[1](error) : resolvers[0]();
|
|
5495
|
+
}
|
|
5496
|
+
|
|
5497
|
+
/**
|
|
5498
|
+
* Reject every command that has not been answered yet - both the ones still
|
|
5499
|
+
* waiting in the send queue and the ones already sent to the server.
|
|
5500
|
+
*/
|
|
5501
|
+
}, {
|
|
5502
|
+
key: "failPendingCommands",
|
|
5503
|
+
value: function failPendingCommands(error) {
|
|
5504
|
+
var queued = this.sendQueue;
|
|
5505
|
+
this.sendQueue = [];
|
|
5506
|
+
var _iterator = WebSocketChatClient_createForOfIteratorHelper(queued),
|
|
5507
|
+
_step;
|
|
5508
|
+
try {
|
|
5509
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
5510
|
+
var envelope = _step.value;
|
|
5511
|
+
this.handleEnvelopeSendError(envelope, error);
|
|
5512
|
+
}
|
|
5513
|
+
} catch (err) {
|
|
5514
|
+
_iterator.e(err);
|
|
5515
|
+
} finally {
|
|
5516
|
+
_iterator.f();
|
|
5517
|
+
}
|
|
5518
|
+
this.failAwaitingResponses(error);
|
|
5519
|
+
}
|
|
5110
5520
|
}, {
|
|
5111
5521
|
key: "sendFromQueue",
|
|
5112
5522
|
value: function sendFromQueue() {
|
|
@@ -5171,7 +5581,12 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5171
5581
|
_this4.inFlightPingTimeout = undefined;
|
|
5172
5582
|
_this4.ws.close(3000); // Service Restart (reconnect)
|
|
5173
5583
|
}, _this4.options.ping.pongBackTimeoutMs);
|
|
5174
|
-
|
|
5584
|
+
|
|
5585
|
+
// A rejection here means the connection dropped while the ping was
|
|
5586
|
+
// in flight; onClose already handles that, so just stop waiting.
|
|
5587
|
+
_this4.send('Ping', {})["catch"](function () {
|
|
5588
|
+
return undefined;
|
|
5589
|
+
}).then(function () {
|
|
5175
5590
|
clearTimeout(_this4.inFlightPingTimeout);
|
|
5176
5591
|
_this4.inFlightPingTimeout = undefined;
|
|
5177
5592
|
});
|