polfan-server-js-client 0.2.109 → 0.2.111
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 +22 -29
- package/build/index.cjs.js +513 -106
- 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 +6 -0
- package/build/types/IndexedObjectCollection.d.ts +8 -0
- package/build/types/WebSocketChatClient.d.ts +12 -1
- package/build/types/state-tracker/FollowedTopicsManager.d.ts +19 -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 +18 -0
- package/src/IndexedObjectCollection.ts +31 -0
- package/src/WebSocketChatClient.ts +58 -7
- package/src/state-tracker/AsyncUtils.ts +6 -0
- package/src/state-tracker/EmoticonsManager.ts +7 -3
- package/src/state-tracker/FollowedTopicsManager.ts +62 -7
- 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 +35 -8
- 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 +339 -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,26 @@ 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
|
+
* Call this whenever the transport can no longer deliver an answer (the
|
|
200
|
+
* connection dropped).
|
|
201
|
+
*/
|
|
202
|
+
}, {
|
|
203
|
+
key: "failAwaitingResponses",
|
|
204
|
+
value: function failAwaitingResponses(error) {
|
|
205
|
+
if (!this.awaitingResponse.size) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
var pending = Array.from(this.awaitingResponse.values());
|
|
209
|
+
this.awaitingResponse.clear();
|
|
210
|
+
for (var _i = 0, _pending = pending; _i < _pending.length; _i++) {
|
|
211
|
+
var _pending$_i = _slicedToArray(_pending[_i], 2),
|
|
212
|
+
reject = _pending$_i[1];
|
|
213
|
+
reject(error);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
190
216
|
}]);
|
|
191
217
|
}(EventTarget);
|
|
192
218
|
|
|
@@ -209,17 +235,17 @@ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !==
|
|
|
209
235
|
function IndexedObjectCollection_getPrototypeOf(t) { return IndexedObjectCollection_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, IndexedObjectCollection_getPrototypeOf(t); }
|
|
210
236
|
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
237
|
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) ||
|
|
238
|
+
function IndexedObjectCollection_slicedToArray(r, e) { return IndexedObjectCollection_arrayWithHoles(r) || IndexedObjectCollection_iterableToArrayLimit(r, e) || IndexedObjectCollection_unsupportedIterableToArray(r, e) || IndexedObjectCollection_nonIterableRest(); }
|
|
239
|
+
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."); }
|
|
240
|
+
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; } }
|
|
241
|
+
function IndexedObjectCollection_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
242
|
+
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; } } }; }
|
|
243
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || IndexedObjectCollection_unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
218
244
|
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
|
|
245
|
+
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
246
|
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
|
|
247
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return IndexedObjectCollection_arrayLikeToArray(r); }
|
|
248
|
+
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
249
|
function IndexedObjectCollection_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
224
250
|
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
251
|
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 +316,7 @@ var IndexedCollection = /*#__PURE__*/function () {
|
|
|
290
316
|
_step;
|
|
291
317
|
try {
|
|
292
318
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
293
|
-
var _step$value =
|
|
319
|
+
var _step$value = IndexedObjectCollection_slicedToArray(_step.value, 2),
|
|
294
320
|
key = _step$value[0],
|
|
295
321
|
value = _step$value[1];
|
|
296
322
|
if (result.length >= limit) {
|
|
@@ -547,6 +573,53 @@ var ObservableIndexedObjectCollection = /*#__PURE__*/function (_IndexedObjectCol
|
|
|
547
573
|
});
|
|
548
574
|
}
|
|
549
575
|
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Bring the collection to exactly match the provided items: upsert every
|
|
579
|
+
* provided item and remove any existing item whose id is not present in the
|
|
580
|
+
* provided set. Emits at most a single `change` event describing both the
|
|
581
|
+
* set and the deleted ids, so bound consumers can update in place without
|
|
582
|
+
* ever observing an intermediate empty state (unlike deleteAll + set).
|
|
583
|
+
*/
|
|
584
|
+
}, {
|
|
585
|
+
key: "reconcile",
|
|
586
|
+
value: function reconcile() {
|
|
587
|
+
var _this8 = this,
|
|
588
|
+
_this$_items3;
|
|
589
|
+
for (var _len8 = arguments.length, items = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
590
|
+
items[_key8] = arguments[_key8];
|
|
591
|
+
}
|
|
592
|
+
var incomingIds = new Set(items.map(function (item) {
|
|
593
|
+
return _this8.getId(item);
|
|
594
|
+
}));
|
|
595
|
+
var deletedItems = [];
|
|
596
|
+
var _iterator3 = _createForOfIteratorHelper(this.items),
|
|
597
|
+
_step3;
|
|
598
|
+
try {
|
|
599
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
600
|
+
var existing = _step3.value;
|
|
601
|
+
var _id2 = this.getId(existing);
|
|
602
|
+
if (!incomingIds.has(_id2)) {
|
|
603
|
+
deletedItems.push(_id2);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
} catch (err) {
|
|
607
|
+
_iterator3.e(err);
|
|
608
|
+
} finally {
|
|
609
|
+
_iterator3.f();
|
|
610
|
+
}
|
|
611
|
+
if (!items.length && !deletedItems.length) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
(_this$_items3 = this._items)["delete"].apply(_this$_items3, deletedItems);
|
|
615
|
+
_superPropGet(ObservableIndexedObjectCollection, "set", this, 3)(items);
|
|
616
|
+
this.eventTarget.emit('change', {
|
|
617
|
+
setItems: items.map(function (item) {
|
|
618
|
+
return _this8.getId(item);
|
|
619
|
+
}),
|
|
620
|
+
deletedItems: deletedItems
|
|
621
|
+
});
|
|
622
|
+
}
|
|
550
623
|
}, {
|
|
551
624
|
key: "createMirror",
|
|
552
625
|
value: function createMirror() {
|
|
@@ -601,7 +674,13 @@ var PromiseRegistry = /*#__PURE__*/function () {
|
|
|
601
674
|
return AsyncUtils_createClass(PromiseRegistry, [{
|
|
602
675
|
key: "register",
|
|
603
676
|
value: function register(promise, key) {
|
|
677
|
+
var _this2 = this;
|
|
604
678
|
this.promises.set([key, promise]);
|
|
679
|
+
promise["catch"](function () {
|
|
680
|
+
if (_this2.promises.get(key) === promise) {
|
|
681
|
+
_this2.promises["delete"](key);
|
|
682
|
+
}
|
|
683
|
+
});
|
|
605
684
|
}
|
|
606
685
|
}, {
|
|
607
686
|
key: "registerByFunction",
|
|
@@ -781,11 +860,15 @@ var TraversableRemoteCollection = /*#__PURE__*/function (_ObservableIndexedObj)
|
|
|
781
860
|
key: "resetToLatest",
|
|
782
861
|
value: function () {
|
|
783
862
|
var _resetToLatest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
784
|
-
var
|
|
863
|
+
var force,
|
|
864
|
+
result,
|
|
865
|
+
originalState,
|
|
866
|
+
_args = arguments;
|
|
785
867
|
return _regenerator().w(function (_context) {
|
|
786
868
|
while (1) switch (_context.p = _context.n) {
|
|
787
869
|
case 0:
|
|
788
|
-
|
|
870
|
+
force = _args.length > 0 && _args[0] !== undefined ? _args[0] : false;
|
|
871
|
+
if (!(this.internalState.ongoing || !force && this.internalState.current === WindowState.LATEST)) {
|
|
789
872
|
_context.n = 1;
|
|
790
873
|
break;
|
|
791
874
|
}
|
|
@@ -1133,16 +1216,19 @@ var TopicHistoryWindow = /*#__PURE__*/function (_TraversableRemoteCol) {
|
|
|
1133
1216
|
key: "resetToLatest",
|
|
1134
1217
|
value: function () {
|
|
1135
1218
|
var _resetToLatest2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
|
|
1219
|
+
var force,
|
|
1220
|
+
_args7 = arguments;
|
|
1136
1221
|
return _regenerator().w(function (_context7) {
|
|
1137
1222
|
while (1) switch (_context7.n) {
|
|
1138
1223
|
case 0:
|
|
1224
|
+
force = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : false;
|
|
1139
1225
|
if (!this.internalState.traverseLock) {
|
|
1140
1226
|
_context7.n = 1;
|
|
1141
1227
|
break;
|
|
1142
1228
|
}
|
|
1143
1229
|
return _context7.a(2);
|
|
1144
1230
|
case 1:
|
|
1145
|
-
return _context7.a(2, TopicHistoryWindow_superPropGet(TopicHistoryWindow, "resetToLatest", this, 3)([]));
|
|
1231
|
+
return _context7.a(2, TopicHistoryWindow_superPropGet(TopicHistoryWindow, "resetToLatest", this, 3)([force]));
|
|
1146
1232
|
}
|
|
1147
1233
|
}, _callee7, this);
|
|
1148
1234
|
}));
|
|
@@ -1618,17 +1704,85 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
|
|
|
1618
1704
|
return _getMessagesWindow.apply(this, arguments);
|
|
1619
1705
|
}
|
|
1620
1706
|
return getMessagesWindow;
|
|
1707
|
+
}()
|
|
1708
|
+
/**
|
|
1709
|
+
* Re-synchronise this room's history after a reconnect without discarding
|
|
1710
|
+
* the existing window objects (which would blank the UI and, for ephemeral
|
|
1711
|
+
* rooms, permanently drop live-only history).
|
|
1712
|
+
*
|
|
1713
|
+
* The window bindings are preserved; only windows that the application had
|
|
1714
|
+
* actually pulled to the latest page (state === LATEST) are refreshed, with
|
|
1715
|
+
* a single resetToLatest instead of a chain of catch-up requests. Windows
|
|
1716
|
+
* that were never pulled (LIVE) or belong to an ephemeral room are left
|
|
1717
|
+
* untouched so their in-memory context survives the reconnect.
|
|
1718
|
+
*/
|
|
1719
|
+
)
|
|
1720
|
+
}, {
|
|
1721
|
+
key: "resync",
|
|
1722
|
+
value: (function () {
|
|
1723
|
+
var _resync = RoomMessagesHistory_asyncToGenerator(/*#__PURE__*/RoomMessagesHistory_regenerator().m(function _callee2(room) {
|
|
1724
|
+
var _i, _Array$from, _Array$from$_i, window, _t;
|
|
1725
|
+
return RoomMessagesHistory_regenerator().w(function (_context2) {
|
|
1726
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
1727
|
+
case 0:
|
|
1728
|
+
this.room = room;
|
|
1729
|
+
this.updateTraverseLock(room);
|
|
1730
|
+
if (this.room.defaultTopic) {
|
|
1731
|
+
this.createHistoryWindowForTopic(this.room.defaultTopic);
|
|
1732
|
+
}
|
|
1733
|
+
_i = 0, _Array$from = Array.from(this.historyWindows.items);
|
|
1734
|
+
case 1:
|
|
1735
|
+
if (!(_i < _Array$from.length)) {
|
|
1736
|
+
_context2.n = 8;
|
|
1737
|
+
break;
|
|
1738
|
+
}
|
|
1739
|
+
_Array$from$_i = RoomMessagesHistory_slicedToArray(_Array$from[_i], 2), window = _Array$from$_i[1];
|
|
1740
|
+
_context2.p = 2;
|
|
1741
|
+
_context2.n = 3;
|
|
1742
|
+
return window.setTraverseLock(this.traverseLock);
|
|
1743
|
+
case 3:
|
|
1744
|
+
if (!this.traverseLock) {
|
|
1745
|
+
_context2.n = 4;
|
|
1746
|
+
break;
|
|
1747
|
+
}
|
|
1748
|
+
return _context2.a(3, 7);
|
|
1749
|
+
case 4:
|
|
1750
|
+
if (!(window.state === WindowState.LATEST)) {
|
|
1751
|
+
_context2.n = 5;
|
|
1752
|
+
break;
|
|
1753
|
+
}
|
|
1754
|
+
_context2.n = 5;
|
|
1755
|
+
return window.resetToLatest(true);
|
|
1756
|
+
case 5:
|
|
1757
|
+
_context2.n = 7;
|
|
1758
|
+
break;
|
|
1759
|
+
case 6:
|
|
1760
|
+
_context2.p = 6;
|
|
1761
|
+
_t = _context2.v;
|
|
1762
|
+
case 7:
|
|
1763
|
+
_i++;
|
|
1764
|
+
_context2.n = 1;
|
|
1765
|
+
break;
|
|
1766
|
+
case 8:
|
|
1767
|
+
return _context2.a(2);
|
|
1768
|
+
}
|
|
1769
|
+
}, _callee2, this, [[2, 6]]);
|
|
1770
|
+
}));
|
|
1771
|
+
function resync(_x2) {
|
|
1772
|
+
return _resync.apply(this, arguments);
|
|
1773
|
+
}
|
|
1774
|
+
return resync;
|
|
1621
1775
|
}())
|
|
1622
1776
|
}, {
|
|
1623
1777
|
key: "handleRoomUpdated",
|
|
1624
1778
|
value: function () {
|
|
1625
|
-
var _handleRoomUpdated = RoomMessagesHistory_asyncToGenerator(/*#__PURE__*/RoomMessagesHistory_regenerator().m(function
|
|
1626
|
-
var
|
|
1627
|
-
return RoomMessagesHistory_regenerator().w(function (
|
|
1628
|
-
while (1) switch (
|
|
1779
|
+
var _handleRoomUpdated = RoomMessagesHistory_asyncToGenerator(/*#__PURE__*/RoomMessagesHistory_regenerator().m(function _callee3(ev) {
|
|
1780
|
+
var _i2, _Array$from2, _Array$from2$_i, window;
|
|
1781
|
+
return RoomMessagesHistory_regenerator().w(function (_context3) {
|
|
1782
|
+
while (1) switch (_context3.n) {
|
|
1629
1783
|
case 0:
|
|
1630
1784
|
if (!(this.room.id === ev.room.id)) {
|
|
1631
|
-
|
|
1785
|
+
_context3.n = 3;
|
|
1632
1786
|
break;
|
|
1633
1787
|
}
|
|
1634
1788
|
this.room = ev.room;
|
|
@@ -1636,25 +1790,25 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
|
|
|
1636
1790
|
if (ev.room.defaultTopic) {
|
|
1637
1791
|
this.createHistoryWindowForTopic(ev.room.defaultTopic);
|
|
1638
1792
|
}
|
|
1639
|
-
|
|
1793
|
+
_i2 = 0, _Array$from2 = Array.from(this.historyWindows.items);
|
|
1640
1794
|
case 1:
|
|
1641
|
-
if (!(
|
|
1642
|
-
|
|
1795
|
+
if (!(_i2 < _Array$from2.length)) {
|
|
1796
|
+
_context3.n = 3;
|
|
1643
1797
|
break;
|
|
1644
1798
|
}
|
|
1645
|
-
_Array$
|
|
1646
|
-
|
|
1799
|
+
_Array$from2$_i = RoomMessagesHistory_slicedToArray(_Array$from2[_i2], 2), window = _Array$from2$_i[1];
|
|
1800
|
+
_context3.n = 2;
|
|
1647
1801
|
return window.setTraverseLock(this.traverseLock);
|
|
1648
1802
|
case 2:
|
|
1649
|
-
|
|
1650
|
-
|
|
1803
|
+
_i2++;
|
|
1804
|
+
_context3.n = 1;
|
|
1651
1805
|
break;
|
|
1652
1806
|
case 3:
|
|
1653
|
-
return
|
|
1807
|
+
return _context3.a(2);
|
|
1654
1808
|
}
|
|
1655
|
-
},
|
|
1809
|
+
}, _callee3, this);
|
|
1656
1810
|
}));
|
|
1657
|
-
function handleRoomUpdated(
|
|
1811
|
+
function handleRoomUpdated(_x3) {
|
|
1658
1812
|
return _handleRoomUpdated.apply(this, arguments);
|
|
1659
1813
|
}
|
|
1660
1814
|
return handleRoomUpdated;
|
|
@@ -1718,6 +1872,9 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
|
|
|
1718
1872
|
}();
|
|
1719
1873
|
;// ./src/state-tracker/MessagesManager.ts
|
|
1720
1874
|
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); }
|
|
1875
|
+
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; } } }; }
|
|
1876
|
+
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; } }
|
|
1877
|
+
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
1878
|
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
1879
|
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
1880
|
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 +1997,38 @@ var MessagesManager = /*#__PURE__*/function () {
|
|
|
1840
1997
|
}, {
|
|
1841
1998
|
key: "handleSession",
|
|
1842
1999
|
value: function handleSession(ev) {
|
|
1843
|
-
var
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
2000
|
+
var stateRoomIds = new Set(ev.state.rooms.map(function (room) {
|
|
2001
|
+
return room.id;
|
|
2002
|
+
}));
|
|
2003
|
+
|
|
2004
|
+
// Drop histories only for rooms that no longer exist server-side.
|
|
2005
|
+
for (var _i = 0, _Array$from = Array.from(this.roomHistories.items.keys()); _i < _Array$from.length; _i++) {
|
|
2006
|
+
var roomId = _Array$from[_i];
|
|
2007
|
+
if (!stateRoomIds.has(roomId)) {
|
|
2008
|
+
this.roomHistories["delete"](roomId);
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// Keep existing histories (preserving loaded messages and, crucially,
|
|
2013
|
+
// live-only ephemeral history), create histories for newly joined
|
|
2014
|
+
// rooms, and resync survivors against the fresh room snapshot.
|
|
2015
|
+
var _iterator = MessagesManager_createForOfIteratorHelper(ev.state.rooms),
|
|
2016
|
+
_step;
|
|
2017
|
+
try {
|
|
2018
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2019
|
+
var room = _step.value;
|
|
2020
|
+
var history = this.roomHistories.get(room.id);
|
|
2021
|
+
if (history) {
|
|
2022
|
+
void history.resync(room);
|
|
2023
|
+
} else {
|
|
2024
|
+
this.createHistoryForNewRoom(room);
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
} catch (err) {
|
|
2028
|
+
_iterator.e(err);
|
|
2029
|
+
} finally {
|
|
2030
|
+
_iterator.f();
|
|
2031
|
+
}
|
|
1848
2032
|
this.deferredSession.resolve();
|
|
1849
2033
|
}
|
|
1850
2034
|
}]);
|
|
@@ -1889,6 +2073,11 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
1889
2073
|
FollowedTopicsManager_defineProperty(_this, "followedTopicsPromises", new PromiseRegistry());
|
|
1890
2074
|
FollowedTopicsManager_defineProperty(_this, "deferredSession", new DeferredTask());
|
|
1891
2075
|
FollowedTopicsManager_defineProperty(_this, "summariesCache", new Map());
|
|
2076
|
+
/**
|
|
2077
|
+
* Rooms whose cached followed-topics are stale after a reconnect and must
|
|
2078
|
+
* be refetched (and reconciled in place) the next time they are accessed.
|
|
2079
|
+
*/
|
|
2080
|
+
FollowedTopicsManager_defineProperty(_this, "staleRooms", new Set());
|
|
1892
2081
|
_this.tracker = tracker;
|
|
1893
2082
|
_this.tracker.client.on('Session', function (ev) {
|
|
1894
2083
|
return _this.handleSession(ev);
|
|
@@ -1934,7 +2123,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
1934
2123
|
value: (function () {
|
|
1935
2124
|
var _cacheForSpace = FollowedTopicsManager_asyncToGenerator(/*#__PURE__*/FollowedTopicsManager_regenerator().m(function _callee2(spaceId) {
|
|
1936
2125
|
var _this2 = this;
|
|
1937
|
-
var rooms, roomIds,
|
|
2126
|
+
var rooms, roomIds, needsFetch, spaceRegistryKey, _t;
|
|
1938
2127
|
return FollowedTopicsManager_regenerator().w(function (_context2) {
|
|
1939
2128
|
while (1) switch (_context2.n) {
|
|
1940
2129
|
case 0:
|
|
@@ -1971,10 +2160,10 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
1971
2160
|
}
|
|
1972
2161
|
return _context2.a(2);
|
|
1973
2162
|
case 5:
|
|
1974
|
-
|
|
1975
|
-
return _this2.followedTopics.has(roomId);
|
|
2163
|
+
needsFetch = roomIds.some(function (roomId) {
|
|
2164
|
+
return !_this2.followedTopics.has(roomId) || _this2.staleRooms.has(roomId);
|
|
1976
2165
|
});
|
|
1977
|
-
if (
|
|
2166
|
+
if (needsFetch) {
|
|
1978
2167
|
_context2.n = 6;
|
|
1979
2168
|
break;
|
|
1980
2169
|
}
|
|
@@ -2001,7 +2190,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2001
2190
|
}
|
|
2002
2191
|
throw result.error;
|
|
2003
2192
|
case 2:
|
|
2004
|
-
_this2.
|
|
2193
|
+
_this2.reconcileRoomsFollowedTopics(roomIds, result.data.followedTopics);
|
|
2005
2194
|
case 3:
|
|
2006
2195
|
return _context.a(2);
|
|
2007
2196
|
}
|
|
@@ -2042,7 +2231,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2042
2231
|
}
|
|
2043
2232
|
return _context4.a(2, undefined);
|
|
2044
2233
|
case 2:
|
|
2045
|
-
if (this.followedTopics.has(roomId)) {
|
|
2234
|
+
if (!(!this.followedTopics.has(roomId) || this.staleRooms.has(roomId))) {
|
|
2046
2235
|
_context4.n = 3;
|
|
2047
2236
|
break;
|
|
2048
2237
|
}
|
|
@@ -2066,7 +2255,8 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2066
2255
|
}
|
|
2067
2256
|
throw result.error;
|
|
2068
2257
|
case 2:
|
|
2069
|
-
_this3.
|
|
2258
|
+
_this3.applyRoomFollowedTopics(roomId, result.data.followedTopics);
|
|
2259
|
+
_this3.invalidateUnreadSummaries(roomId);
|
|
2070
2260
|
case 3:
|
|
2071
2261
|
return _context3.a(2);
|
|
2072
2262
|
}
|
|
@@ -2159,7 +2349,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2159
2349
|
key: "summarize",
|
|
2160
2350
|
value: (function () {
|
|
2161
2351
|
var _summarize = FollowedTopicsManager_asyncToGenerator(/*#__PURE__*/FollowedTopicsManager_regenerator().m(function _callee6(location) {
|
|
2162
|
-
var cacheKey, roomIds, targetTopicId, rooms, mentionCount, unreadTopicCount, _iterator2, _step2, roomId, collection, _iterator3, _step3, _topic$mentionCount, topic, result, _t3, _t4;
|
|
2352
|
+
var cacheKey, roomIds, targetTopicId, rooms, mentionCount, unreadTopicCount, unreadRoomCount, _iterator2, _step2, roomId, collection, isRoomUnreadCount, _iterator3, _step3, _topic$mentionCount, topic, result, _t3, _t4;
|
|
2163
2353
|
return FollowedTopicsManager_regenerator().w(function (_context6) {
|
|
2164
2354
|
while (1) switch (_context6.p = _context6.n) {
|
|
2165
2355
|
case 0:
|
|
@@ -2222,6 +2412,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2222
2412
|
case 9:
|
|
2223
2413
|
mentionCount = 0;
|
|
2224
2414
|
unreadTopicCount = 0;
|
|
2415
|
+
unreadRoomCount = 0;
|
|
2225
2416
|
_iterator2 = FollowedTopicsManager_createForOfIteratorHelper(roomIds);
|
|
2226
2417
|
_context6.p = 10;
|
|
2227
2418
|
_iterator2.s();
|
|
@@ -2241,6 +2432,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2241
2432
|
}
|
|
2242
2433
|
return _context6.a(3, 21);
|
|
2243
2434
|
case 13:
|
|
2435
|
+
isRoomUnreadCount = false;
|
|
2244
2436
|
_iterator3 = FollowedTopicsManager_createForOfIteratorHelper(collection.items);
|
|
2245
2437
|
_context6.p = 14;
|
|
2246
2438
|
_iterator3.s();
|
|
@@ -2257,6 +2449,10 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2257
2449
|
return _context6.a(3, 17);
|
|
2258
2450
|
case 16:
|
|
2259
2451
|
if (topic.isUnread) {
|
|
2452
|
+
if (!isRoomUnreadCount) {
|
|
2453
|
+
unreadRoomCount++;
|
|
2454
|
+
isRoomUnreadCount = true;
|
|
2455
|
+
}
|
|
2260
2456
|
unreadTopicCount++;
|
|
2261
2457
|
}
|
|
2262
2458
|
mentionCount += (_topic$mentionCount = topic.mentionCount) !== null && _topic$mentionCount !== void 0 ? _topic$mentionCount : 0;
|
|
@@ -2292,6 +2488,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2292
2488
|
result = {
|
|
2293
2489
|
mentionCount: mentionCount,
|
|
2294
2490
|
unreadTopicCount: unreadTopicCount,
|
|
2491
|
+
unreadRoomCount: unreadRoomCount,
|
|
2295
2492
|
isUnread: unreadTopicCount > 0
|
|
2296
2493
|
};
|
|
2297
2494
|
this.summariesCache.set(cacheKey, result);
|
|
@@ -2325,7 +2522,22 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2325
2522
|
}, {
|
|
2326
2523
|
key: "handleSession",
|
|
2327
2524
|
value: function handleSession(ev) {
|
|
2328
|
-
|
|
2525
|
+
// Keep cached followed-topic collections (they drive unread indicators
|
|
2526
|
+
// that would otherwise blank on reconnect), but mark them stale and drop
|
|
2527
|
+
// the fetch guards so the next access/caching refetches and reconciles
|
|
2528
|
+
// them in place.
|
|
2529
|
+
var _iterator4 = FollowedTopicsManager_createForOfIteratorHelper(this.followedTopics.items.keys()),
|
|
2530
|
+
_step4;
|
|
2531
|
+
try {
|
|
2532
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
2533
|
+
var roomId = _step4.value;
|
|
2534
|
+
this.staleRooms.add(roomId);
|
|
2535
|
+
}
|
|
2536
|
+
} catch (err) {
|
|
2537
|
+
_iterator4.e(err);
|
|
2538
|
+
} finally {
|
|
2539
|
+
_iterator4.f();
|
|
2540
|
+
}
|
|
2329
2541
|
this.followedTopicsPromises.forgetAll();
|
|
2330
2542
|
this.invalidateUnreadSummaries();
|
|
2331
2543
|
this.deferredSession.resolve();
|
|
@@ -2425,34 +2637,34 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2425
2637
|
if (topicId) {
|
|
2426
2638
|
this.summariesCache["delete"]("topic:".concat(roomId, ":").concat(topicId));
|
|
2427
2639
|
} else {
|
|
2428
|
-
var
|
|
2429
|
-
|
|
2640
|
+
var _iterator5 = FollowedTopicsManager_createForOfIteratorHelper(this.summariesCache.keys()),
|
|
2641
|
+
_step5;
|
|
2430
2642
|
try {
|
|
2431
|
-
for (
|
|
2432
|
-
var key =
|
|
2643
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
2644
|
+
var key = _step5.value;
|
|
2433
2645
|
if (key.startsWith("topic:".concat(roomId, ":"))) {
|
|
2434
2646
|
this.summariesCache["delete"](key);
|
|
2435
2647
|
}
|
|
2436
2648
|
}
|
|
2437
2649
|
} catch (err) {
|
|
2438
|
-
|
|
2650
|
+
_iterator5.e(err);
|
|
2439
2651
|
} finally {
|
|
2440
|
-
|
|
2652
|
+
_iterator5.f();
|
|
2441
2653
|
}
|
|
2442
2654
|
}
|
|
2443
|
-
var
|
|
2444
|
-
|
|
2655
|
+
var _iterator6 = FollowedTopicsManager_createForOfIteratorHelper(this.summariesCache.keys()),
|
|
2656
|
+
_step6;
|
|
2445
2657
|
try {
|
|
2446
|
-
for (
|
|
2447
|
-
var _key2 =
|
|
2658
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
2659
|
+
var _key2 = _step6.value;
|
|
2448
2660
|
if (_key2.startsWith('space:') || _key2 === 'spaceless') {
|
|
2449
2661
|
this.summariesCache["delete"](_key2);
|
|
2450
2662
|
}
|
|
2451
2663
|
}
|
|
2452
2664
|
} catch (err) {
|
|
2453
|
-
|
|
2665
|
+
_iterator6.e(err);
|
|
2454
2666
|
} finally {
|
|
2455
|
-
|
|
2667
|
+
_iterator6.f();
|
|
2456
2668
|
}
|
|
2457
2669
|
} else {
|
|
2458
2670
|
this.summariesCache.clear();
|
|
@@ -2467,11 +2679,11 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2467
2679
|
roomIds.forEach(function (roomId) {
|
|
2468
2680
|
_this5.summariesCache["delete"]("room:".concat(roomId));
|
|
2469
2681
|
});
|
|
2470
|
-
var
|
|
2471
|
-
|
|
2682
|
+
var _iterator7 = FollowedTopicsManager_createForOfIteratorHelper(this.summariesCache.keys()),
|
|
2683
|
+
_step7;
|
|
2472
2684
|
try {
|
|
2473
|
-
for (
|
|
2474
|
-
var key =
|
|
2685
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
2686
|
+
var key = _step7.value;
|
|
2475
2687
|
if (key.startsWith('space:') || key === 'spaceless') {
|
|
2476
2688
|
this.summariesCache["delete"](key);
|
|
2477
2689
|
continue;
|
|
@@ -2484,9 +2696,9 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2484
2696
|
}
|
|
2485
2697
|
}
|
|
2486
2698
|
} catch (err) {
|
|
2487
|
-
|
|
2699
|
+
_iterator7.e(err);
|
|
2488
2700
|
} finally {
|
|
2489
|
-
|
|
2701
|
+
_iterator7.f();
|
|
2490
2702
|
}
|
|
2491
2703
|
this.emit('change');
|
|
2492
2704
|
}
|
|
@@ -2564,27 +2776,66 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2564
2776
|
}
|
|
2565
2777
|
return updateLocallyFollowedTopicOnNewMessage;
|
|
2566
2778
|
}()
|
|
2779
|
+
/**
|
|
2780
|
+
* Reconcile the followed-topics collection for a single room to exactly
|
|
2781
|
+
* match the provided list (upsert present, drop absent) without emitting an
|
|
2782
|
+
* intermediate empty state, and clear its stale marker. Does not touch the
|
|
2783
|
+
* unread summaries cache - callers decide how to invalidate it.
|
|
2784
|
+
*/
|
|
2785
|
+
}, {
|
|
2786
|
+
key: "applyRoomFollowedTopics",
|
|
2787
|
+
value: function applyRoomFollowedTopics(roomId, followedTopics) {
|
|
2788
|
+
var _this$followedTopics$5;
|
|
2789
|
+
if (!this.followedTopics.has(roomId)) {
|
|
2790
|
+
this.followedTopics.set([roomId, new ObservableIndexedObjectCollection(function (followedTopic) {
|
|
2791
|
+
return followedTopic.location.topicId;
|
|
2792
|
+
})]);
|
|
2793
|
+
}
|
|
2794
|
+
(_this$followedTopics$5 = this.followedTopics.get(roomId)).reconcile.apply(_this$followedTopics$5, FollowedTopicsManager_toConsumableArray(followedTopics));
|
|
2795
|
+
this.staleRooms["delete"](roomId);
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
/**
|
|
2799
|
+
* Reconcile a batch of rooms from a single bulk GetFollowedTopics response.
|
|
2800
|
+
* Rooms with no followed topics in the response are reconciled to empty, so
|
|
2801
|
+
* topics unfollowed/removed during the downtime are correctly dropped.
|
|
2802
|
+
*/
|
|
2803
|
+
}, {
|
|
2804
|
+
key: "reconcileRoomsFollowedTopics",
|
|
2805
|
+
value: function reconcileRoomsFollowedTopics(roomIds, followedTopics) {
|
|
2806
|
+
var _this6 = this;
|
|
2807
|
+
var roomToTopics = {};
|
|
2808
|
+
followedTopics.forEach(function (followedTopic) {
|
|
2809
|
+
var _followedTopic$locati, _roomToTopics$_follow;
|
|
2810
|
+
((_roomToTopics$_follow = roomToTopics[_followedTopic$locati = followedTopic.location.roomId]) !== null && _roomToTopics$_follow !== void 0 ? _roomToTopics$_follow : roomToTopics[_followedTopic$locati] = []).push(followedTopic);
|
|
2811
|
+
});
|
|
2812
|
+
roomIds.forEach(function (roomId) {
|
|
2813
|
+
var _roomToTopics$roomId;
|
|
2814
|
+
return _this6.applyRoomFollowedTopics(roomId, (_roomToTopics$roomId = roomToTopics[roomId]) !== null && _roomToTopics$roomId !== void 0 ? _roomToTopics$roomId : []);
|
|
2815
|
+
});
|
|
2816
|
+
this.invalidateUnreadSummariesForRooms(roomIds);
|
|
2817
|
+
}
|
|
2567
2818
|
}, {
|
|
2568
2819
|
key: "setFollowedTopicsArray",
|
|
2569
2820
|
value: function setFollowedTopicsArray(roomIds, followedTopics) {
|
|
2570
|
-
var
|
|
2821
|
+
var _this7 = this;
|
|
2571
2822
|
var roomToTopics = {};
|
|
2572
2823
|
|
|
2573
2824
|
// Reassign followed topics to limit collection change event emit
|
|
2574
2825
|
followedTopics.forEach(function (followedTopic) {
|
|
2575
|
-
var _followedTopic$
|
|
2576
|
-
(_roomToTopics$
|
|
2826
|
+
var _followedTopic$locati2, _roomToTopics$_follow2;
|
|
2827
|
+
(_roomToTopics$_follow2 = roomToTopics[_followedTopic$locati2 = followedTopic.location.roomId]) !== null && _roomToTopics$_follow2 !== void 0 ? _roomToTopics$_follow2 : roomToTopics[_followedTopic$locati2] = [];
|
|
2577
2828
|
roomToTopics[followedTopic.location.roomId].push(followedTopic);
|
|
2578
2829
|
});
|
|
2579
2830
|
roomIds.forEach(function (roomId) {
|
|
2580
|
-
if (!
|
|
2581
|
-
|
|
2831
|
+
if (!_this7.followedTopics.has(roomId)) {
|
|
2832
|
+
_this7.followedTopics.set([roomId, new ObservableIndexedObjectCollection(function (followedTopic) {
|
|
2582
2833
|
return followedTopic.location.topicId;
|
|
2583
2834
|
})]);
|
|
2584
2835
|
}
|
|
2585
2836
|
if (roomToTopics[roomId]) {
|
|
2586
|
-
var
|
|
2587
|
-
(
|
|
2837
|
+
var _this7$followedTopics;
|
|
2838
|
+
(_this7$followedTopics = _this7.followedTopics.get(roomId)).set.apply(_this7$followedTopics, FollowedTopicsManager_toConsumableArray(roomToTopics[roomId]));
|
|
2588
2839
|
}
|
|
2589
2840
|
});
|
|
2590
2841
|
this.invalidateUnreadSummariesForRooms(roomIds);
|
|
@@ -2594,6 +2845,7 @@ var FollowedTopicsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
2594
2845
|
value: function clearRoomFollowedTopicsStructures(roomId) {
|
|
2595
2846
|
this.followedTopics["delete"](roomId);
|
|
2596
2847
|
this.followedTopicsPromises.forget(roomId);
|
|
2848
|
+
this.staleRooms["delete"](roomId);
|
|
2597
2849
|
this.invalidateUnreadSummaries(roomId);
|
|
2598
2850
|
}
|
|
2599
2851
|
}]);
|
|
@@ -3109,16 +3361,39 @@ var RoomsManager = /*#__PURE__*/function () {
|
|
|
3109
3361
|
var _member$user$id2, _member$user2;
|
|
3110
3362
|
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;
|
|
3111
3363
|
}, ev.members)]);
|
|
3364
|
+
} else {
|
|
3365
|
+
var _this$members$get;
|
|
3366
|
+
// Reconcile into the existing (bound) collection so a reconnect
|
|
3367
|
+
// refetch updates it in place instead of leaving stale members.
|
|
3368
|
+
(_this$members$get = this.members.get(ev.id)).reconcile.apply(_this$members$get, RoomsManager_toConsumableArray(ev.members));
|
|
3112
3369
|
}
|
|
3113
3370
|
}
|
|
3114
3371
|
}, {
|
|
3115
3372
|
key: "handleSession",
|
|
3116
3373
|
value: function handleSession(ev) {
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3374
|
+
var stateRoomIds = new Set(ev.state.rooms.map(function (room) {
|
|
3375
|
+
return room.id;
|
|
3376
|
+
}));
|
|
3377
|
+
|
|
3378
|
+
// Remove only rooms that were left/deleted on the server during the
|
|
3379
|
+
// downtime, reusing the cascade cleanup (members, topics, followed
|
|
3380
|
+
// topics). Surviving rooms keep their identity and bindings.
|
|
3381
|
+
var removedRoomIds = this.list.items.filter(function (room) {
|
|
3382
|
+
return !stateRoomIds.has(room.id);
|
|
3383
|
+
}).map(function (room) {
|
|
3384
|
+
return room.id;
|
|
3385
|
+
});
|
|
3386
|
+
if (removedRoomIds.length) {
|
|
3387
|
+
this.deleteRoom.apply(this, RoomsManager_toConsumableArray(removedRoomIds));
|
|
3388
|
+
}
|
|
3389
|
+
|
|
3390
|
+
// Invalidate lazy caches so the next access refetches fresh data, but
|
|
3391
|
+
// keep the collection objects: handleRoomMembers reconciles into them,
|
|
3392
|
+
// so bound views refresh in place without blanking.
|
|
3121
3393
|
this.membersPromises.forgetAll();
|
|
3394
|
+
this.topicsPromises.forgetAll();
|
|
3395
|
+
|
|
3396
|
+
// Upsert surviving/new rooms from the authoritative snapshot.
|
|
3122
3397
|
this.addJoinedRooms.apply(this, RoomsManager_toConsumableArray(ev.state.rooms));
|
|
3123
3398
|
this.deferredSession.resolve();
|
|
3124
3399
|
}
|
|
@@ -3252,6 +3527,7 @@ function extractUserFromMember(member) {
|
|
|
3252
3527
|
}
|
|
3253
3528
|
;// ./src/state-tracker/SpacesManager.ts
|
|
3254
3529
|
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); }
|
|
3530
|
+
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; } } }; }
|
|
3255
3531
|
function SpacesManager_toConsumableArray(r) { return SpacesManager_arrayWithoutHoles(r) || SpacesManager_iterableToArray(r) || SpacesManager_unsupportedIterableToArray(r) || SpacesManager_nonIterableSpread(); }
|
|
3256
3532
|
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."); }
|
|
3257
3533
|
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; } }
|
|
@@ -3655,6 +3931,11 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3655
3931
|
this.members.set([ev.id, new ObservableIndexedObjectCollection(function (member) {
|
|
3656
3932
|
return member === null || member === void 0 ? void 0 : member.user.id;
|
|
3657
3933
|
}, ev.members)]);
|
|
3934
|
+
} else {
|
|
3935
|
+
var _this$members$get;
|
|
3936
|
+
// Reconcile into the existing (bound) collection so a reconnect
|
|
3937
|
+
// refetch updates it in place instead of leaving stale members.
|
|
3938
|
+
(_this$members$get = this.members.get(ev.id)).reconcile.apply(_this$members$get, SpacesManager_toConsumableArray(ev.members));
|
|
3658
3939
|
}
|
|
3659
3940
|
}
|
|
3660
3941
|
}, {
|
|
@@ -3663,10 +3944,13 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3663
3944
|
var _this4 = this;
|
|
3664
3945
|
if (!this.rooms.has(ev.id)) {
|
|
3665
3946
|
this.rooms.set([ev.id, new ObservableIndexedObjectCollection('id', ev.summaries)]);
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3947
|
+
} else {
|
|
3948
|
+
var _this$rooms$get4;
|
|
3949
|
+
(_this$rooms$get4 = this.rooms.get(ev.id)).reconcile.apply(_this$rooms$get4, SpacesManager_toConsumableArray(ev.summaries));
|
|
3669
3950
|
}
|
|
3951
|
+
ev.summaries.forEach(function (summary) {
|
|
3952
|
+
return _this4.roomIdToSpaceId.set([summary.id, ev.id]);
|
|
3953
|
+
});
|
|
3670
3954
|
}
|
|
3671
3955
|
}, {
|
|
3672
3956
|
key: "handleRoomSummaryUpdated",
|
|
@@ -3734,14 +4018,58 @@ var SpacesManager = /*#__PURE__*/function () {
|
|
|
3734
4018
|
}, {
|
|
3735
4019
|
key: "handleSession",
|
|
3736
4020
|
value: function handleSession(ev) {
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
4021
|
+
var _this$list2;
|
|
4022
|
+
var stateSpaceIds = new Set(ev.state.spaces.map(function (space) {
|
|
4023
|
+
return space.id;
|
|
4024
|
+
}));
|
|
4025
|
+
|
|
4026
|
+
// Remove only spaces that were left/deleted on the server during the
|
|
4027
|
+
// downtime, reusing the cascade cleanup (roles, rooms, members, index).
|
|
4028
|
+
var removedSpaceIds = this.list.items.filter(function (space) {
|
|
4029
|
+
return !stateSpaceIds.has(space.id);
|
|
4030
|
+
}).map(function (space) {
|
|
4031
|
+
return space.id;
|
|
4032
|
+
});
|
|
4033
|
+
var _iterator = SpacesManager_createForOfIteratorHelper(removedSpaceIds),
|
|
4034
|
+
_step;
|
|
4035
|
+
try {
|
|
4036
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
4037
|
+
var spaceId = _step.value;
|
|
4038
|
+
this.handleSpaceDeleted({
|
|
4039
|
+
id: spaceId
|
|
4040
|
+
});
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
// Invalidate lazy caches (rooms/members) but keep their objects so the
|
|
4044
|
+
// next access refetches and reconciles them in place.
|
|
4045
|
+
} catch (err) {
|
|
4046
|
+
_iterator.e(err);
|
|
4047
|
+
} finally {
|
|
4048
|
+
_iterator.f();
|
|
4049
|
+
}
|
|
3740
4050
|
this.roomsPromises.forgetAll();
|
|
3741
|
-
this.members.deleteAll();
|
|
3742
4051
|
this.membersPromises.forgetAll();
|
|
3743
|
-
|
|
3744
|
-
|
|
4052
|
+
|
|
4053
|
+
// Reconcile roles in place (kept, possibly bound object) and upsert the
|
|
4054
|
+
// spaces from the authoritative snapshot.
|
|
4055
|
+
var _iterator2 = SpacesManager_createForOfIteratorHelper(ev.state.spaces),
|
|
4056
|
+
_step2;
|
|
4057
|
+
try {
|
|
4058
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
4059
|
+
var space = _step2.value;
|
|
4060
|
+
if (this.roles.has(space.id)) {
|
|
4061
|
+
var _this$roles$get2;
|
|
4062
|
+
(_this$roles$get2 = this.roles.get(space.id)).reconcile.apply(_this$roles$get2, SpacesManager_toConsumableArray(space.roles));
|
|
4063
|
+
} else {
|
|
4064
|
+
this.roles.set([space.id, new ObservableIndexedObjectCollection('id', space.roles)]);
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4067
|
+
} catch (err) {
|
|
4068
|
+
_iterator2.e(err);
|
|
4069
|
+
} finally {
|
|
4070
|
+
_iterator2.f();
|
|
4071
|
+
}
|
|
4072
|
+
(_this$list2 = this.list).set.apply(_this$list2, SpacesManager_toConsumableArray(ev.state.spaces));
|
|
3745
4073
|
this.deferredSession.resolve();
|
|
3746
4074
|
}
|
|
3747
4075
|
}, {
|
|
@@ -4465,8 +4793,12 @@ var PermissionsManager = /*#__PURE__*/function (_EventTarget) {
|
|
|
4465
4793
|
}, {
|
|
4466
4794
|
key: "handleSession",
|
|
4467
4795
|
value: function handleSession(ev) {
|
|
4468
|
-
|
|
4796
|
+
// Drop the fetch guards so permission checks recompute against fresh
|
|
4797
|
+
// overwrites (getOverwrites refetches and upserts on the next access),
|
|
4798
|
+
// and notify consumers to recompute so bound permission UI is never
|
|
4799
|
+
// left showing stale results after a reconnect.
|
|
4469
4800
|
this.overwritesPromises.forgetAll();
|
|
4801
|
+
this.emit('change');
|
|
4470
4802
|
}
|
|
4471
4803
|
}]);
|
|
4472
4804
|
}(EventTarget);
|
|
@@ -4564,13 +4896,16 @@ var EmoticonsManager = /*#__PURE__*/function () {
|
|
|
4564
4896
|
}, {
|
|
4565
4897
|
key: "handleEmoticons",
|
|
4566
4898
|
value: function handleEmoticons(event) {
|
|
4567
|
-
var _event$location$space;
|
|
4899
|
+
var _event$location$space, _this$list$get;
|
|
4568
4900
|
var spaceId = (_event$location$space = event.location.spaceId) !== null && _event$location$space !== void 0 ? _event$location$space : GLOBAL_KEY;
|
|
4569
4901
|
if (!this.list.has(spaceId)) {
|
|
4570
4902
|
this.list.set([spaceId, new ObservableIndexedObjectCollection('id')]);
|
|
4571
4903
|
}
|
|
4572
|
-
|
|
4573
|
-
|
|
4904
|
+
|
|
4905
|
+
// handleEmoticons always carries the full list for a location, so
|
|
4906
|
+
// reconcile in place: a reconnect refetch drops removed emoticons and
|
|
4907
|
+
// adds new ones without blanking a bound (visible) collection.
|
|
4908
|
+
(_this$list$get = this.list.get(spaceId)).reconcile.apply(_this$list$get, EmoticonsManager_toConsumableArray(event.emoticons));
|
|
4574
4909
|
}
|
|
4575
4910
|
}, {
|
|
4576
4911
|
key: "handleNewEmoticon",
|
|
@@ -4594,7 +4929,9 @@ var EmoticonsManager = /*#__PURE__*/function () {
|
|
|
4594
4929
|
}, {
|
|
4595
4930
|
key: "handleSession",
|
|
4596
4931
|
value: function handleSession() {
|
|
4597
|
-
|
|
4932
|
+
// Keep cached emoticon collections (they may be bound to visible
|
|
4933
|
+
// pickers); just drop the fetch guards so the next access refetches and
|
|
4934
|
+
// reconciles them in place.
|
|
4598
4935
|
this.emoticonsPromises.forgetAll();
|
|
4599
4936
|
}
|
|
4600
4937
|
}]);
|
|
@@ -4683,7 +5020,9 @@ var UsersManager = /*#__PURE__*/function () {
|
|
|
4683
5020
|
}, {
|
|
4684
5021
|
key: "handleSession",
|
|
4685
5022
|
value: function handleSession(session) {
|
|
4686
|
-
|
|
5023
|
+
// Keep the "seen users" cache across reconnects so bound user lists do
|
|
5024
|
+
// not blank out; just ensure our own user is present/updated. Stale
|
|
5025
|
+
// entries are refreshed as member/message collections refetch.
|
|
4687
5026
|
this.handleUsers([session.user]);
|
|
4688
5027
|
}
|
|
4689
5028
|
}, {
|
|
@@ -4703,6 +5042,12 @@ var UsersManager = /*#__PURE__*/function () {
|
|
|
4703
5042
|
}();
|
|
4704
5043
|
;// ./src/state-tracker/RelationshipsManager.ts
|
|
4705
5044
|
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); }
|
|
5045
|
+
function RelationshipsManager_toConsumableArray(r) { return RelationshipsManager_arrayWithoutHoles(r) || RelationshipsManager_iterableToArray(r) || RelationshipsManager_unsupportedIterableToArray(r) || RelationshipsManager_nonIterableSpread(); }
|
|
5046
|
+
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."); }
|
|
5047
|
+
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; } }
|
|
5048
|
+
function RelationshipsManager_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
5049
|
+
function RelationshipsManager_arrayWithoutHoles(r) { if (Array.isArray(r)) return RelationshipsManager_arrayLikeToArray(r); }
|
|
5050
|
+
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; }
|
|
4706
5051
|
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 }; })(); }
|
|
4707
5052
|
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); }
|
|
4708
5053
|
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); }
|
|
@@ -4804,11 +5149,10 @@ var RelationshipsManager = /*#__PURE__*/function () {
|
|
|
4804
5149
|
}, {
|
|
4805
5150
|
key: "handleRelationships",
|
|
4806
5151
|
value: function handleRelationships(ev) {
|
|
4807
|
-
var
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
});
|
|
5152
|
+
var _this$relationships;
|
|
5153
|
+
// Full list from the server: reconcile in place so a reconnect refetch
|
|
5154
|
+
// updates a bound (visible) list without an intermediate empty state.
|
|
5155
|
+
(_this$relationships = this.relationships).reconcile.apply(_this$relationships, RelationshipsManager_toConsumableArray(ev.relationships));
|
|
4812
5156
|
}
|
|
4813
5157
|
}, {
|
|
4814
5158
|
key: "handleNewRelationship",
|
|
@@ -4827,8 +5171,9 @@ var RelationshipsManager = /*#__PURE__*/function () {
|
|
|
4827
5171
|
}, {
|
|
4828
5172
|
key: "handleSession",
|
|
4829
5173
|
value: function handleSession() {
|
|
5174
|
+
// Keep the (possibly bound) collection; just drop the fetch guard so the
|
|
5175
|
+
// next get() refetches and reconciles it in place.
|
|
4830
5176
|
this.promises.forgetAll();
|
|
4831
|
-
this.relationships.deleteAll();
|
|
4832
5177
|
}
|
|
4833
5178
|
}]);
|
|
4834
5179
|
}();
|
|
@@ -4927,6 +5272,9 @@ var ChatStateTracker = /*#__PURE__*/function () {
|
|
|
4927
5272
|
}();
|
|
4928
5273
|
;// ./src/WebSocketChatClient.ts
|
|
4929
5274
|
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); }
|
|
5275
|
+
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; } } }; }
|
|
5276
|
+
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; } }
|
|
5277
|
+
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; }
|
|
4930
5278
|
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 }; })(); }
|
|
4931
5279
|
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); }
|
|
4932
5280
|
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); }
|
|
@@ -4965,7 +5313,8 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
4965
5313
|
WebSocketChatClient_defineProperty(_this, "sendQueue", []);
|
|
4966
5314
|
WebSocketChatClient_defineProperty(_this, "connectingTimeoutId", void 0);
|
|
4967
5315
|
WebSocketChatClient_defineProperty(_this, "authenticated", void 0);
|
|
4968
|
-
WebSocketChatClient_defineProperty(_this, "authenticatedResolvers",
|
|
5316
|
+
WebSocketChatClient_defineProperty(_this, "authenticatedResolvers", null);
|
|
5317
|
+
WebSocketChatClient_defineProperty(_this, "connectPromise", null);
|
|
4969
5318
|
WebSocketChatClient_defineProperty(_this, "pingMonitorInterval", void 0);
|
|
4970
5319
|
WebSocketChatClient_defineProperty(_this, "inFlightPingTimeout", void 0);
|
|
4971
5320
|
WebSocketChatClient_defineProperty(_this, "lastReceivedMessageAt", void 0);
|
|
@@ -4984,10 +5333,11 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
4984
5333
|
key: "connect",
|
|
4985
5334
|
value: function () {
|
|
4986
5335
|
var _connect = WebSocketChatClient_asyncToGenerator(/*#__PURE__*/WebSocketChatClient_regenerator().m(function _callee() {
|
|
4987
|
-
var _this$
|
|
5336
|
+
var _this$connectPromise2,
|
|
4988
5337
|
_this2 = this,
|
|
5338
|
+
_this$options$queryPa,
|
|
4989
5339
|
_this$options$connect;
|
|
4990
|
-
var params;
|
|
5340
|
+
var _this$connectPromise, params;
|
|
4991
5341
|
return WebSocketChatClient_regenerator().w(function (_context) {
|
|
4992
5342
|
while (1) switch (_context.n) {
|
|
4993
5343
|
case 0:
|
|
@@ -4995,8 +5345,17 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
4995
5345
|
_context.n = 1;
|
|
4996
5346
|
break;
|
|
4997
5347
|
}
|
|
4998
|
-
return _context.a(2);
|
|
5348
|
+
return _context.a(2, (_this$connectPromise = this.connectPromise) !== null && _this$connectPromise !== void 0 ? _this$connectPromise : undefined);
|
|
4999
5349
|
case 1:
|
|
5350
|
+
// Reuse the promise of an attempt that has not settled yet (an
|
|
5351
|
+
// automatic reconnect), so the caller that started connecting is
|
|
5352
|
+
// resolved by whichever attempt eventually authenticates.
|
|
5353
|
+
(_this$connectPromise2 = this.connectPromise) !== null && _this$connectPromise2 !== void 0 ? _this$connectPromise2 : this.connectPromise = new Promise(function () {
|
|
5354
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5355
|
+
args[_key] = arguments[_key];
|
|
5356
|
+
}
|
|
5357
|
+
return _this2.authenticatedResolvers = args;
|
|
5358
|
+
});
|
|
5000
5359
|
params = new URLSearchParams((_this$options$queryPa = this.options.queryParams) !== null && _this$options$queryPa !== void 0 ? _this$options$queryPa : {});
|
|
5001
5360
|
params.set('token', this.options.token);
|
|
5002
5361
|
this.ws = new WebSocket("".concat(this.options.url, "?").concat(params));
|
|
@@ -5010,12 +5369,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5010
5369
|
return _this2.triggerConnectionTimeout();
|
|
5011
5370
|
}, (_this$options$connect = this.options.connectingTimeoutMs) !== null && _this$options$connect !== void 0 ? _this$options$connect : 10000);
|
|
5012
5371
|
this.authenticated = false;
|
|
5013
|
-
return _context.a(2,
|
|
5014
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5015
|
-
args[_key] = arguments[_key];
|
|
5016
|
-
}
|
|
5017
|
-
return _this2.authenticatedResolvers = args;
|
|
5018
|
-
}));
|
|
5372
|
+
return _context.a(2, this.connectPromise);
|
|
5019
5373
|
}
|
|
5020
5374
|
}, _callee, this);
|
|
5021
5375
|
}));
|
|
@@ -5028,7 +5382,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5028
5382
|
key: "disconnect",
|
|
5029
5383
|
value: function disconnect() {
|
|
5030
5384
|
var _this$ws;
|
|
5031
|
-
this.
|
|
5385
|
+
this.failPendingCommands(new Error('Client disconnected before the command was answered'));
|
|
5032
5386
|
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.close(1000); // Normal closure
|
|
5033
5387
|
this.ws = null;
|
|
5034
5388
|
}
|
|
@@ -5089,11 +5443,11 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5089
5443
|
this.authenticated = isAuthenticated;
|
|
5090
5444
|
if (isAuthenticated) {
|
|
5091
5445
|
this.startConnectionMonitor();
|
|
5092
|
-
this.
|
|
5446
|
+
this.settleConnect();
|
|
5093
5447
|
this.emit(this.Event.connect);
|
|
5094
5448
|
this.sendFromQueue();
|
|
5095
5449
|
} else {
|
|
5096
|
-
this.
|
|
5450
|
+
this.settleConnect(envelope.data);
|
|
5097
5451
|
}
|
|
5098
5452
|
}
|
|
5099
5453
|
}
|
|
@@ -5103,11 +5457,59 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5103
5457
|
this.stopConnectionMonitor();
|
|
5104
5458
|
clearTimeout(this.connectingTimeoutId);
|
|
5105
5459
|
var reconnect = event.code !== 1000; // Connection was closed because of error
|
|
5460
|
+
|
|
5461
|
+
// The server can no longer answer anything that was queued or in
|
|
5462
|
+
// flight, so settle those promises instead of leaving them pending.
|
|
5463
|
+
this.failPendingCommands(new Error('Connection closed before the command was answered'));
|
|
5106
5464
|
if (reconnect) {
|
|
5465
|
+
// Keep a pending connect() promise unsettled - the retry below is
|
|
5466
|
+
// expected to authenticate and will resolve it.
|
|
5107
5467
|
void this.connect();
|
|
5468
|
+
} else {
|
|
5469
|
+
this.settleConnect(new Error('Connection closed before authentication'));
|
|
5108
5470
|
}
|
|
5109
5471
|
this.emit(this.Event.disconnect, reconnect);
|
|
5110
5472
|
}
|
|
5473
|
+
|
|
5474
|
+
/**
|
|
5475
|
+
* Resolve (or reject, when an error is given) a pending connect() promise.
|
|
5476
|
+
* No-op when there is nothing pending.
|
|
5477
|
+
*/
|
|
5478
|
+
}, {
|
|
5479
|
+
key: "settleConnect",
|
|
5480
|
+
value: function settleConnect(error) {
|
|
5481
|
+
var resolvers = this.authenticatedResolvers;
|
|
5482
|
+
this.authenticatedResolvers = null;
|
|
5483
|
+
this.connectPromise = null;
|
|
5484
|
+
if (!resolvers) {
|
|
5485
|
+
return;
|
|
5486
|
+
}
|
|
5487
|
+
error ? resolvers[1](error) : resolvers[0]();
|
|
5488
|
+
}
|
|
5489
|
+
|
|
5490
|
+
/**
|
|
5491
|
+
* Reject every command that has not been answered yet - both the ones still
|
|
5492
|
+
* waiting in the send queue and the ones already sent to the server.
|
|
5493
|
+
*/
|
|
5494
|
+
}, {
|
|
5495
|
+
key: "failPendingCommands",
|
|
5496
|
+
value: function failPendingCommands(error) {
|
|
5497
|
+
var queued = this.sendQueue;
|
|
5498
|
+
this.sendQueue = [];
|
|
5499
|
+
var _iterator = WebSocketChatClient_createForOfIteratorHelper(queued),
|
|
5500
|
+
_step;
|
|
5501
|
+
try {
|
|
5502
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
5503
|
+
var envelope = _step.value;
|
|
5504
|
+
this.handleEnvelopeSendError(envelope, error);
|
|
5505
|
+
}
|
|
5506
|
+
} catch (err) {
|
|
5507
|
+
_iterator.e(err);
|
|
5508
|
+
} finally {
|
|
5509
|
+
_iterator.f();
|
|
5510
|
+
}
|
|
5511
|
+
this.failAwaitingResponses(error);
|
|
5512
|
+
}
|
|
5111
5513
|
}, {
|
|
5112
5514
|
key: "sendFromQueue",
|
|
5113
5515
|
value: function sendFromQueue() {
|
|
@@ -5172,7 +5574,12 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
|
|
|
5172
5574
|
_this4.inFlightPingTimeout = undefined;
|
|
5173
5575
|
_this4.ws.close(3000); // Service Restart (reconnect)
|
|
5174
5576
|
}, _this4.options.ping.pongBackTimeoutMs);
|
|
5175
|
-
|
|
5577
|
+
|
|
5578
|
+
// A rejection here means the connection dropped while the ping was
|
|
5579
|
+
// in flight; onClose already handles that, so just stop waiting.
|
|
5580
|
+
_this4.send('Ping', {})["catch"](function () {
|
|
5581
|
+
return undefined;
|
|
5582
|
+
}).then(function () {
|
|
5176
5583
|
clearTimeout(_this4.inFlightPingTimeout);
|
|
5177
5584
|
_this4.inFlightPingTimeout = undefined;
|
|
5178
5585
|
});
|