polfan-server-js-client 0.2.108 → 0.2.109
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/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26_[Changes]/shelved.patch +174 -0
- package/.idea/shelf/Uncommitted_changes_before_Checkout_at_26_07_2026_21_26__Changes_.xml +4 -0
- package/.idea/workspace.xml +8 -3
- package/build/index.cjs.js +105 -520
- 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 +0 -10
- package/build/types/IndexedObjectCollection.d.ts +0 -8
- package/build/types/WebSocketChatClient.d.ts +1 -17
- package/build/types/state-tracker/FollowedTopicsManager.d.ts +0 -18
- package/build/types/state-tracker/RoomMessagesHistory.d.ts +0 -12
- package/build/types/state-tracker/TopicHistoryWindow.d.ts +2 -2
- package/package.json +1 -1
- package/src/AbstractChatClient.ts +0 -22
- package/src/IndexedObjectCollection.ts +0 -31
- package/src/WebSocketChatClient.ts +7 -63
- package/src/state-tracker/AsyncUtils.ts +0 -11
- package/src/state-tracker/EmoticonsManager.ts +3 -7
- package/src/state-tracker/FollowedTopicsManager.ts +6 -54
- package/src/state-tracker/MessagesManager.ts +2 -21
- package/src/state-tracker/PermissionsManager.ts +1 -5
- package/src/state-tracker/RelationshipsManager.ts +5 -5
- package/src/state-tracker/RoomMessagesHistory.ts +1 -41
- package/src/state-tracker/RoomsManager.ts +4 -21
- package/src/state-tracker/SpacesManager.ts +8 -35
- package/src/state-tracker/TopicHistoryWindow.ts +4 -4
- package/src/state-tracker/UsersManager.ts +1 -3
- package/tests/collections.test.ts +0 -92
- package/tests/pending-commands.test.ts +0 -171
- package/tests/state-reconnect.test.ts +0 -257
package/build/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.PservClient=t():e.PservClient=t()}(this,()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,i(n.key),n)}}function o(e,t,r){return(t=i(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e){var t=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==r(t)?t:t+""}e.r(t),e.d(t,{AbstractRestClient:()=>Wn,FilesClient:()=>no,IndexedCollection:()=>x,IndexedObjectCollection:()=>G,Layer:()=>Jt,ObservableIndexedCollection:()=>U,ObservableIndexedObjectCollection:()=>D,PermissionDefinition:()=>Ht,Permissions:()=>$t,WebApiChatClient:()=>_n,WebSocketChatClient:()=>vn,extractUserFromMember:()=>kt});var a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,"events",new Map),o(this,"onceEvents",new Map)},(t=[{key:"on",value:function(e,t){return this.addHandler(this.events,e,t),this}},{key:"once",value:function(e,t){return this.addHandler(this.onceEvents,e,t),this}},{key:"off",value:function(e,t){var r,n,o=null===(r=this.events.get(e))||void 0===r?void 0:r.indexOf(t);return void 0===o||o<0||null===(n=this.events.get(e))||void 0===n||n.splice(o,1),this}},{key:"emit",value:function(e,t){return this.callHandlers(this.events,e,t),this.callHandlers(this.onceEvents,e,t),this.onceEvents.delete(e),this}},{key:"addHandler",value:function(e,t,r){var n,o=null!==(n=e.get(t))&&void 0!==n?n:[];o.push(r),e.set(t,o)}},{key:"callHandlers",value:function(e,t,r){var n;null===(n=e.get(t))||void 0===n||n.forEach(function(e){return e(r)})}}])&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function l(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,m(n.key),n)}}function f(e,t,r){return t=p(t),function(e,t){if(t&&("object"==c(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,h()?Reflect.construct(t,r||[],p(e).constructor):t.apply(e,r))}function h(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(h=function(){return!!e})()}function p(e){return p=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},p(e)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function y(e,t,r){return(t=m(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e){var t=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==c(t)?t:t+""}var v=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return y(e=f(this,t,[].concat(n)),"awaitingResponse",new Map),y(e,"sentCounter",0),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}(t,e),r=t,n=[{key:"createEnvelope",value:function(e,t){return{type:e,data:t,ref:(++this.sentCounter).toString()}}},{key:"createPromiseFromCommandEnvelope",value:function(e){var t=this;return new Promise(function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return t.awaitingResponse.set(e.ref,n)})}},{key:"handleIncomingEnvelope",value:function(e){if(this.awaitingResponse.has(e.ref)){var t="Error"===e.type;this.awaitingResponse.get(e.ref)[0]({data:t?null:e.data,error:t?e.data:null}),this.awaitingResponse.delete(e.ref)}}},{key:"handleEnvelopeSendError",value:function(e,t){this.awaitingResponse.has(e.ref)&&(this.awaitingResponse.get(e.ref)[1](t),this.awaitingResponse.delete(e.ref))}},{key:"failAwaitingResponses",value:function(e){if(this.awaitingResponse.size){var t=Array.from(this.awaitingResponse.values());this.awaitingResponse.clear();for(var r=0,n=t;r<n.length;r++)(0,u(n[r],2)[1])(e)}}}],n&&l(r.prototype,n),o&&l(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(a);function b(e){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b(e)}function g(e,t,r){return t=O(t),function(e,t){if(t&&("object"==b(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,w()?Reflect.construct(t,r||[],O(e).constructor):t.apply(e,r))}function w(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(w=function(){return!!e})()}function k(e,t,r,n){var o=S(O(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function S(){return S="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=O(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},S.apply(null,arguments)}function O(e){return O=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},O(e)}function j(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&T(e,t)}function T(e,t){return T=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},T(e,t)}function P(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||R(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=R(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function E(e){return function(e){if(Array.isArray(e))return A(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||R(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function R(e,t){if(e){if("string"==typeof e)return A(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?A(e,t):void 0}}function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function _(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function M(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,L(n.key),n)}}function C(e,t,r){return t&&M(e.prototype,t),r&&M(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function F(e,t,r){return(t=L(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function L(e){var t=function(e,t){if("object"!=b(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=b(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==b(t)?t:t+""}var x=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];_(this,e),F(this,"_items",new Map),this.set.apply(this,E(t))}return C(e,[{key:"items",get:function(){return this._items}},{key:"length",get:function(){return this._items.size}},{key:"set",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this._items.set(i[0],i[1])}}},{key:"get",value:function(e){return this.items.get(e)}},{key:"has",value:function(e){return this.items.has(e)}},{key:"delete",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this.items.delete(i)}}},{key:"deleteAll",value:function(){this.items.clear()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0,i=new e,a=I(this.items.entries());try{for(a.s();!(n=a.n()).done;){var c=P(n.value,2),u=c[0],s=c[1];if(i.length>=o)break;s[t]===r&&i.set([u,s])}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e;return t._items=this._items,t}}])}(),G=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];_(this,e),F(this,"_items",void 0),this.id=t,this._items=new x,this.set.apply(this,E(r))}return C(e,[{key:"items",get:function(){return Array.from(this._items.items.values())}},{key:"length",get:function(){return this._items.length}},{key:"set",value:function(){for(var e,t=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this._items).set.apply(e,E(n.map(function(e){return[t.getId(e),e]})))}},{key:"get",value:function(e){return this._items.get(e)}},{key:"getAt",value:function(e){return this.items[e]}},{key:"has",value:function(e){return this._items.has(e)}},{key:"delete",value:function(){var e;(e=this._items).delete.apply(e,arguments)}},{key:"deleteAll",value:function(){this._items.deleteAll()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new e(this.id),a=I(this.items);try{for(a.s();!(n=a.n()).done;){var c=n.value;if(o&&i.length===o)break;c[t]===r&&i.set(c)}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e(this.id);return t._items=this._items,t}},{key:"getId",value:function(e){return"function"==typeof this.id?this.id(e):e[this.id]}}])}(),U=function(e){function t(){var e,r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return _(this,t),F(r=g(this,t),"eventTarget",void 0),r.eventTarget=new a,(e=r).set.apply(e,E(n)),r}return j(t,e),C(t,[{key:"set",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(k(t,"set",this,3)(r),this.eventTarget.emit("change",{setItems:r.map(function(e){return e[0]})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(k(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){if(this.length){var e=Array.from(this._items.keys());k(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:Array.from(e)})}}},{key:"createMirror",value:function(){var e=new t;return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(x),D=function(e){function t(e){var r,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return _(this,t),F(n=g(this,t,[e]),"eventTarget",void 0),n.eventTarget=new a,(r=n).set.apply(r,E(o)),n}return j(t,e),C(t,[{key:"set",value:function(){for(var e=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];n.length&&(k(t,"set",this,3)(n),this.eventTarget.emit("change",{setItems:n.map(function(t){return e.getId(t)})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(k(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){var e=this;if(this.length){var r=this.items.map(function(t){return e.getId(t)});k(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:r})}}},{key:"reconcile",value:function(){for(var e,r=this,n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];var a,c=new Set(o.map(function(e){return r.getId(e)})),u=[],s=I(this.items);try{for(s.s();!(a=s.n()).done;){var l=a.value,f=this.getId(l);c.has(f)||u.push(f)}}catch(e){s.e(e)}finally{s.f()}(o.length||u.length)&&((e=this._items).delete.apply(e,u),k(t,"set",this,3)(o),this.eventTarget.emit("change",{setItems:o.map(function(e){return r.getId(e)}),deletedItems:u}))}},{key:"createMirror",value:function(){var e=new t(this.id);return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(G);function N(e){return N="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},N(e)}function B(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,$(n.key),n)}}function W(e,t,r){return t&&B(e.prototype,t),r&&B(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function J(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function H(e,t,r){return(t=$(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function $(e){var t=function(e,t){if("object"!=N(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=N(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==N(t)?t:t+""}var Q=W(function e(){var t=this;J(this,e),H(this,"promise",void 0),H(this,"resolve",void 0),this.promise=new Promise(function(e){return t.resolve=e})}),V=function(){return W(function e(){J(this,e),H(this,"promises",new x)},[{key:"register",value:function(e,t){var r=this;this.promises.set([t,e]),e.catch(function(){r.promises.get(t)===e&&r.promises.delete(t)})}},{key:"registerByFunction",value:function(e,t){this.register(e(),t)}},{key:"get",value:function(e){return this.promises.get(e)}},{key:"has",value:function(e){return this.promises.has(e)}},{key:"notExist",value:function(e){return!this.has(e)}},{key:"forget",value:function(){var e;(e=this.promises).delete.apply(e,arguments)}},{key:"forgetAll",value:function(){this.promises.deleteAll()}}])}();function z(e){return z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},z(e)}function q(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function K(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?q(Object(r),!0).forEach(function(t){pe(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):q(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Y(e,t,r,n){var o=X(le(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function X(){return X="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=le(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},X.apply(null,arguments)}function Z(e){return function(e){if(Array.isArray(e))return ee(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return ee(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ee(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ee(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function te(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return re(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(re(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,re(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,re(f,"constructor",s),re(s,"constructor",u),u.displayName="GeneratorFunction",re(s,o,"GeneratorFunction"),re(f),re(f,o,"Generator"),re(f,n,function(){return this}),re(f,"toString",function(){return"[object Generator]"}),(te=function(){return{w:i,m:h}})()}function re(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}re=function(e,t,r,n){function i(t,r){re(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},re(e,t,r,n)}function ne(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function oe(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){ne(i,n,o,a,c,"next",e)}function c(e){ne(i,n,o,a,c,"throw",e)}a(void 0)})}}function ie(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ae(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,de(n.key),n)}}function ce(e,t,r){return t&&ae(e.prototype,t),r&&ae(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function ue(e,t,r){return t=le(t),function(e,t){if(t&&("object"==z(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,se()?Reflect.construct(t,r||[],le(e).constructor):t.apply(e,r))}function se(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(se=function(){return!!e})()}function le(e){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},le(e)}function fe(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&he(e,t)}function he(e,t){return he=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},he(e,t)}function pe(e,t,r){return(t=de(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function de(e){var t=function(e,t){if("object"!=z(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==z(t)?t:t+""}var ye=function(e){return e[e.LIVE=0]="LIVE",e[e.LATEST=1]="LATEST",e[e.PAST=2]="PAST",e[e.OLDEST=3]="OLDEST",e}({}),me=function(e){function t(e,r,n){var o,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return ie(this,t),pe(o=ue(this,t,["id"]),"WindowState",ye),o.roomId=e,o.topicId=r,o.tracker=n,o.internalState.traverseLock=!1,i&&(o.tracker.client.on("NewMessage",function(e){return o.handleNewMessage(e)}),o.tracker.client.on("MessagesRedacted",function(e){return o.handleMessagesRedacted(e)})),o}return fe(t,e),ce(t,[{key:"createMirror",value:function(){var e=new t(this.roomId,this.topicId,this.tracker,!1);return e.eventTarget=this.eventTarget,e._items=this._items,e.internalState=this.internalState,e}},{key:"isTraverseLocked",get:function(){return this.internalState.traverseLock}},{key:"setTraverseLock",value:(y=oe(te().m(function e(r){return te().w(function(e){for(;;)switch(e.n){case 0:if(this.internalState.traverseLock=r,!r||this.state===ye.LIVE||this.state===ye.LATEST){e.n=1;break}return e.n=1,Y(t,"resetToLatest",this,3)([]);case 1:return e.a(2)}},e,this)})),function(e){return y.apply(this,arguments)})},{key:"resetToLatest",value:(d=oe(te().m(function e(){var r,n=arguments;return te().w(function(e){for(;;)switch(e.n){case 0:if(r=n.length>0&&void 0!==n[0]&&n[0],!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,Y(t,"resetToLatest",this,3)([r]))}},e,this)})),function(){return d.apply(this,arguments)})},{key:"fetchNext",value:(p=oe(te().m(function e(){return te().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,Y(t,"fetchNext",this,3)([]))}},e,this)})),function(){return p.apply(this,arguments)})},{key:"fetchPrevious",value:(h=oe(te().m(function e(){return te().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,Y(t,"fetchPrevious",this,3)([]))}},e,this)})),function(){return h.apply(this,arguments)})},{key:"jumpTo",value:(f=oe(te().m(function e(r){return te().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,Y(t,"jumpTo",this,3)([r]))}},e,this)})),function(e){return f.apply(this,arguments)})},{key:"_updateMessageReference",value:function(e){var t=this.get(e.refMessage.id);t&&this.set(K(K({},t),{},{topicRef:e.id}))}},{key:"fetchItemsAfter",value:(l=oe(te().m(function e(){var t,r,n;return te().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(this.length-1))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},after:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return l.apply(this,arguments)})},{key:"fetchItemsAround",value:(s=oe(te().m(function e(t){var r;return te().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},around:t,limit:this.internalState.fetchLimit});case 1:if(!(r=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(r.error.message));case 2:return e.a(2,r.data.messages)}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"fetchItemsBefore",value:(u=oe(te().m(function e(){var t,r,n;return te().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(0))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},before:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return u.apply(this,arguments)})},{key:"fetchLatestItems",value:(c=oe(te().m(function e(){var t;return te().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},limit:this.internalState.fetchLimit});case 1:if(!(t=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(t.error.message));case 2:return e.a(2,t.data.messages)}},e,this)})),function(){return c.apply(this,arguments)})},{key:"getTopic",value:(a=oe(te().m(function e(){return te().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.getTopics(this.roomId,[this.topicId]);case 1:return e.a(2,e.v.get(this.topicId))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"getLatestMessageId",value:(i=oe(te().m(function e(){var t,r,n,o,i;return te().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getTopic();case 1:if(o=t=e.v,n=null===o){e.n=2;break}n=void 0===t;case 2:if(r=n){e.n=3;break}r=null===(t=t.lastMessage)||void 0===t;case 3:if(!r){e.n=4;break}i=void 0,e.n=5;break;case 4:i=t.id;case 5:return e.a(2,i)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"isLatestItemLoaded",value:(o=oe(te().m(function e(){var t;return te().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getLatestMessageId();case 1:return t=e.v,e.a(2,!t||this.has(t))}},e,this)})),function(){return o.apply(this,arguments)})},{key:"handleNewMessage",value:(n=oe(te().m(function e(t){var r;return te().w(function(e){for(;;)switch(e.n){case 0:[ye.LATEST,ye.LIVE].includes(this.state)&&t.message.location.roomId===this.roomId&&t.message.location.topicId===this.topicId&&(r=this.state,this.addItems([t.message],"tail"),this.emitChangeWithDiff(!0,r));case 1:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleMessagesRedacted",value:(r=oe(te().m(function e(t){var r;return te().w(function(e){for(;;)switch(e.n){case 0:if(t.location.topicId===this.topicId&&t.location.roomId===this.roomId){e.n=1;break}return e.a(2);case 1:if(r=this.items.filter(function(e){return e.topicRef&&t.ids.includes(e.id)}).map(function(e){return e.topicRef}),this.delete.apply(this,Z(t.ids)),0!==this.length){e.n=2;break}return e.n=2,this.resetToLatest();case 2:r.length>0&&this.eventTarget.emit("reftopicsdeleted",r);case 3:return e.a(2)}},e,this)})),function(e){return r.apply(this,arguments)})}]);var r,n,o,i,a,c,u,s,l,f,h,p,d,y}(function(e){function t(){var e;ie(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return pe(e=ue(this,t,[].concat(n)),"internalState",{current:ye.LIVE,ongoing:void 0,limit:1e3,retainRatio:1,fetchLimit:50,lastFetchCount:0,oldestId:null}),e}return fe(t,e),ce(t,[{key:"state",get:function(){return this.internalState.current}},{key:"fetchLimit",get:function(){return this.internalState.fetchLimit},set:function(e){this.internalState.fetchLimit=e}},{key:"limit",get:function(){return this.internalState.limit},set:function(e){this.internalState.limit=e}},{key:"retainRatio",get:function(){return this.internalState.retainRatio},set:function(e){this.internalState.retainRatio=e}},{key:"hasLatest",get:function(){return[ye.LATEST,ye.LIVE].includes(this.state)}},{key:"hasOldest",get:function(){return this.state===ye.OLDEST||this.state===ye.LATEST&&this.length<this.fetchLimit||null!==this.internalState.oldestId&&this.has(this.internalState.oldestId)}},{key:"resetToLatest",value:(a=oe(te().m(function e(){var t,r,n,o=arguments;return te().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t=o.length>0&&void 0!==o[0]&&o[0],!this.internalState.ongoing&&(t||this.internalState.current!==ye.LATEST)){e.n=1;break}return e.a(2);case 1:return n=this.state,this.internalState.ongoing=ye.LATEST,e.p=2,e.n=3,this.fetchLatestItems();case 3:r=e.v,this.internalState.lastFetchCount=r.length;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:this._items.deleteAll(),this.addItems(r,"tail"),this.internalState.current=ye.LATEST,this.emitChangeWithDiff(!0,n);case 6:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return a.apply(this,arguments)})},{key:"fetchPrevious",value:(i=oe(te().m(function e(){var t,r,n;return te().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasOldest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=ye.PAST,e.p=2,e.n=3,this.fetchItemsBefore();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=6;break}return e.a(2,this.resetToLatest());case 6:if(t.length){e.n=8;break}return n=this.getAt(0),this.internalState.oldestId=n?this.getId(n):null,e.n=7,this.refreshFetchedState();case 7:return this.internalState.current===ye.PAST&&(this.internalState.current=ye.OLDEST),this.emitChangeWithDiff(!1,r),e.a(2);case 8:return this.addItems(t,"head"),e.n=9,this.refreshFetchedState();case 9:this.emitChangeWithDiff(!0,r);case 10:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return i.apply(this,arguments)})},{key:"fetchNext",value:(o=oe(te().m(function e(){var t,r;return te().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasLatest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=ye.PAST,e.p=2,e.n=3,this.fetchItemsAfter();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=7;break}return e.n=6,this.resetToLatest();case 6:return e.a(2);case 7:if(!t.length){e.n=9;break}return this.addItems(t,"tail"),e.n=8,this.refreshFetchedState();case 8:return this.emitChangeWithDiff(!0,r),e.a(2);case 9:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return o.apply(this,arguments)})},{key:"jumpTo",value:(n=oe(te().m(function e(t){var r,n;return te().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!(this.internalState.ongoing||this.state!==ye.LIVE&&this._items.has(t))){e.n=1;break}return e.a(2);case 1:return n=this.state,this.internalState.ongoing=ye.PAST,e.p=2,e.n=3,this.fetchItemsAround(t);case 3:if(r=e.v,this.internalState.lastFetchCount=r?r.length:0,!r){e.n=4;break}return this._items.deleteAll(),this.addItems(r,"tail"),e.n=4,this.refreshFetchedState();case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:this.emitChangeWithDiff(!!r,n);case 6:return e.a(2)}},e,this,[[2,,4,5]])})),function(e){return n.apply(this,arguments)})},{key:"refreshFetchedState",value:(r=oe(te().m(function e(){var t;return te().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.isLatestItemLoaded();case 1:if(!e.v){e.n=2;break}t=ye.LATEST,e.n=3;break;case 2:t=ye.PAST;case 3:this.internalState.current=t;case 4:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"addItems",value:function(e,t){var r,n,o=this;"head"===t&&(n=this.trimItemsArrayToLimit([].concat(Z(e),Z(this.items)),"tail")),"tail"===t&&(n=this.trimItemsArrayToLimit([].concat(Z(this.items),Z(e)),"head")),this._items.deleteAll(),(r=this._items).set.apply(r,Z(n.map(function(e){return[o.getId(e),e]})))}},{key:"emitChangeWithDiff",value:function(e,t){(e||t!==this.state)&&this.eventTarget.emit("change",{setItems:Array.from(this._items.items.keys())})}},{key:"trimItemsArrayToLimit",value:function(e,t){var r=this.limit;if(null===r||e.length<=r)return e;var n=Math.floor(r*this.internalState.retainRatio);return"head"===t?e.slice(-n):"tail"===t?e.slice(0,n):e}}]);var r,n,o,i,a}(D));function ve(e){return ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ve(e)}function be(e){return function(e){if(Array.isArray(e))return ke(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||we(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ge(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||we(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function we(e,t){if(e){if("string"==typeof e)return ke(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ke(e,t):void 0}}function ke(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Se(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Oe(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Oe(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Oe(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Oe(f,"constructor",s),Oe(s,"constructor",u),u.displayName="GeneratorFunction",Oe(s,o,"GeneratorFunction"),Oe(f),Oe(f,o,"Generator"),Oe(f,n,function(){return this}),Oe(f,"toString",function(){return"[object Generator]"}),(Se=function(){return{w:i,m:h}})()}function Oe(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Oe=function(e,t,r,n){function i(t,r){Oe(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Oe(e,t,r,n)}function je(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Te(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){je(i,n,o,a,c,"next",e)}function c(e){je(i,n,o,a,c,"throw",e)}a(void 0)})}}function Pe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Ee(n.key),n)}}function Ie(e,t,r){return(t=Ee(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ee(e){var t=function(e,t){if("object"!=ve(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ve(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ve(t)?t:t+""}var Re=function(){return e=function e(t,r){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Ie(this,"historyWindows",new x),Ie(this,"traverseLock",!1),this.room=t,this.tracker=r,this.tracker.client.on("RoomUpdated",function(e){return n.handleRoomUpdated(e)}),this.tracker.client.on("NewTopic",function(e){return n.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return n.handleTopicDeleted(e)}),this.updateTraverseLock(this.room),this.room.defaultTopic&&this.createHistoryWindowForTopic(this.room.defaultTopic)},t=[{key:"getMessagesWindow",value:(i=Te(Se().m(function e(t){var r,n,o=arguments;return Se().w(function(e){for(;;)switch(e.n){case 0:if(r=o.length>1&&void 0!==o[1]&&o[1],this.historyWindows.has(t)||r){e.n=2;break}return e.n=1,this.tracker.rooms.getTopics(this.room.id,[t]);case 1:(n=e.v.get(t))&&this.createHistoryWindowForTopic(n);case 2:return e.a(2,this.historyWindows.get(t))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"resync",value:(o=Te(Se().m(function e(t){var r,n,o,i;return Se().w(function(e){for(;;)switch(e.p=e.n){case 0:this.room=t,this.updateTraverseLock(t),this.room.defaultTopic&&this.createHistoryWindowForTopic(this.room.defaultTopic),r=0,n=Array.from(this.historyWindows.items);case 1:if(!(r<n.length)){e.n=8;break}return o=ge(n[r],2),i=o[1],e.p=2,e.n=3,i.setTraverseLock(this.traverseLock);case 3:if(!this.traverseLock){e.n=4;break}return e.a(3,7);case 4:if(i.state!==ye.LATEST){e.n=5;break}return e.n=5,i.resetToLatest(!0);case 5:e.n=7;break;case 6:e.p=6,e.v;case 7:r++,e.n=1;break;case 8:return e.a(2)}},e,this,[[2,6]])})),function(e){return o.apply(this,arguments)})},{key:"handleRoomUpdated",value:(n=Te(Se().m(function e(t){var r,n,o,i;return Se().w(function(e){for(;;)switch(e.n){case 0:if(this.room.id!==t.room.id){e.n=3;break}this.room=t.room,this.updateTraverseLock(t.room),t.room.defaultTopic&&this.createHistoryWindowForTopic(t.room.defaultTopic),r=0,n=Array.from(this.historyWindows.items);case 1:if(!(r<n.length)){e.n=3;break}return o=ge(n[r],2),i=o[1],e.n=2,i.setTraverseLock(this.traverseLock);case 2:r++,e.n=1;break;case 3:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleNewTopic",value:function(e){this.room.id===e.roomId&&this.createHistoryWindowForTopic(e.topic)}},{key:"handleTopicDeleted",value:function(e){this.room.id===e.location.roomId&&this.historyWindows.delete(e.location.topicId)}},{key:"createHistoryWindowForTopic",value:function(e){var t=this;if(!this.historyWindows.has(e.id)){var r=new me(this.room.id,e.id,this.tracker);if(r.setTraverseLock(this.traverseLock),this.historyWindows.set([e.id,r]),r.on("reftopicsdeleted",function(e){var r,n,o=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=we(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}(e);try{for(o.s();!(n=o.n()).done;){var i=n.value;t.historyWindows.delete(i)}}catch(e){o.e(e)}finally{o.f()}(r=t.tracker.rooms)._deleteTopicsFromRoom.apply(r,[t.room.id].concat(be(e)))}),e.refMessage){var n=this.historyWindows.get(e.refMessage.location.topicId);null==n||n._updateMessageReference(e)}}}},{key:"updateTraverseLock",value:function(e){this.traverseLock="Ephemeral"===e.history.mode}}],t&&Pe(e.prototype,t),r&&Pe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i}();function Ae(e){return Ae="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ae(e)}function _e(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return Me(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Me(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function Me(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Ce(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Fe(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Fe(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Fe(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Fe(f,"constructor",s),Fe(s,"constructor",u),u.displayName="GeneratorFunction",Fe(s,o,"GeneratorFunction"),Fe(f),Fe(f,o,"Generator"),Fe(f,n,function(){return this}),Fe(f,"toString",function(){return"[object Generator]"}),(Ce=function(){return{w:i,m:h}})()}function Fe(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Fe=function(e,t,r,n){function i(t,r){Fe(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Fe(e,t,r,n)}function Le(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function xe(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Le(i,n,o,a,c,"next",e)}function c(e){Le(i,n,o,a,c,"throw",e)}a(void 0)})}}function Ge(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,De(n.key),n)}}function Ue(e,t,r){return(t=De(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function De(e){var t=function(e,t){if("object"!=Ae(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ae(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ae(t)?t:t+""}var Ne=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Ue(this,"roomHistories",new x),Ue(this,"deferredSession",new Q),this.tracker=t,this.tracker.client.on("Session",function(e){return r.handleSession(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)})},t=[{key:"getRoomHistory",value:(o=xe(Ce().m(function e(t){return Ce().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roomHistories.get(t))}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"_resolveLastMessage",value:(n=xe(Ce().m(function e(t){var r,n,o;return Ce().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getRoomHistory(t.roomId).then(function(e){return null==e?void 0:e.getMessagesWindow(t.topicId,!0)}).then(function(e){return(null==e?void 0:e.hasLatest)&&e.getAt(e.length-1)});case 1:if(r=e.v){e.n=3;break}return e.n=2,this.tracker.client.send("GetMessages",{location:t,limit:1});case 2:o=e.v,r=null===(n=o.data)||void 0===n?void 0:n.messages[0];case 3:return e.a(2,r||null)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"createHistoryForNewRoom",value:function(e){this.roomHistories.set([e.id,new Re(e,this.tracker)])}},{key:"handleRoomDeleted",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleRoomJoin",value:function(e){this.createHistoryForNewRoom(e.room)}},{key:"handleRoomLeft",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleSession",value:function(e){for(var t=new Set(e.state.rooms.map(function(e){return e.id})),r=0,n=Array.from(this.roomHistories.items.keys());r<n.length;r++){var o=n[r];t.has(o)||this.roomHistories.delete(o)}var i,a=_e(e.state.rooms);try{for(a.s();!(i=a.n()).done;){var c=i.value,u=this.roomHistories.get(c.id);u?u.resync(c):this.createHistoryForNewRoom(c)}}catch(e){a.e(e)}finally{a.f()}this.deferredSession.resolve()}}],t&&Ge(e.prototype,t),r&&Ge(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Be(e){return Be="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Be(e)}function We(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Je(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?We(Object(r),!0).forEach(function(t){nt(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):We(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function He(e){return function(e){if(Array.isArray(e))return Ve(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Qe(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function $e(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Qe(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function Qe(e,t){if(e){if("string"==typeof e)return Ve(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Ve(e,t):void 0}}function Ve(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function ze(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return qe(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(qe(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,qe(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,qe(f,"constructor",s),qe(s,"constructor",u),u.displayName="GeneratorFunction",qe(s,o,"GeneratorFunction"),qe(f),qe(f,o,"Generator"),qe(f,n,function(){return this}),qe(f,"toString",function(){return"[object Generator]"}),(ze=function(){return{w:i,m:h}})()}function qe(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}qe=function(e,t,r,n){function i(t,r){qe(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},qe(e,t,r,n)}function Ke(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Ye(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ke(i,n,o,a,c,"next",e)}function c(e){Ke(i,n,o,a,c,"throw",e)}a(void 0)})}}function Xe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,ot(n.key),n)}}function Ze(e,t,r){return t=tt(t),function(e,t){if(t&&("object"==Be(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,et()?Reflect.construct(t,r||[],tt(e).constructor):t.apply(e,r))}function et(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(et=function(){return!!e})()}function tt(e){return tt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},tt(e)}function rt(e,t){return rt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},rt(e,t)}function nt(e,t,r){return(t=ot(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ot(e){var t=function(e,t){if("object"!=Be(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Be(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Be(t)?t:t+""}var it=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),nt(r=Ze(this,t),"followedTopics",new x),nt(r,"followedTopicsPromises",new V),nt(r,"deferredSession",new Q),nt(r,"summariesCache",new Map),nt(r,"staleRooms",new Set),r.tracker=e,r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),r.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),r.tracker.client.on("FollowedTopicUpdated",function(e){return r.handleFollowedTopicUpdated(e)}),r.tracker.client.on("TopicFollowed",function(e){return r.handleTopicFollowed(e)}),r.tracker.client.on("TopicUnfollowed",function(e){return r.handleTopicUnfollowed(e)}),r.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&rt(e,t)}(t,e),r=t,n=[{key:"cacheForSpace",value:(l=Ye(ze().m(function e(t){var r,n,o,i,a=this;return ze().w(function(e){for(;;)switch(e.n){case 0:if(!(i=t)){e.n=2;break}return e.n=1,this.tracker.spaces.get();case 1:i=!e.v.has(t);case 2:if(!i){e.n=3;break}throw new Error("You are not in space ".concat(t));case 3:return e.n=4,this.tracker.rooms.get();case 4:if(r=e.v,(n=t?r.findBy("spaceId",t).items.map(function(e){return e.id}):r.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id})).length){e.n=5;break}return e.a(2);case 5:if(n.some(function(e){return!a.followedTopics.has(e)||a.staleRooms.has(e)})){e.n=6;break}return e.a(2);case 6:return o="space_fetch_".concat(t||"spaceless"),this.followedTopicsPromises.notExist(o)&&this.followedTopicsPromises.registerByFunction(Ye(ze().m(function e(){var r;return ze().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,a.tracker.client.send("GetFollowedTopics",{location:{spaceId:t}});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:a.reconcileRoomsFollowedTopics(n,r.data.followedTopics);case 3:return e.a(2)}},e)})),o),e.n=7,this.followedTopicsPromises.get(o);case 7:return e.a(2)}},e,this)})),function(e){return l.apply(this,arguments)})},{key:"getForRoom",value:(s=Ye(ze().m(function e(t){var r=this;return ze().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:if(e.v.has(t)){e.n=2;break}return e.a(2,void 0);case 2:if(this.followedTopics.has(t)&&!this.staleRooms.has(t)){e.n=3;break}return this.followedTopicsPromises.notExist(t)&&this.followedTopicsPromises.registerByFunction(Ye(ze().m(function e(){var n;return ze().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetFollowedTopics",{location:{roomId:t}});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.applyRoomFollowedTopics(t,n.data.followedTopics),r.invalidateUnreadSummaries(t);case 3:return e.a(2)}},e)})),t),e.n=3,this.followedTopicsPromises.get(t);case 3:return e.a(2,this.followedTopics.get(t))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"ackRoom",value:(u=Ye(ze().m(function e(t){var r,n,o,i,a;return ze().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.getForRoom(t);case 1:if(r=e.v){e.n=2;break}return e.a(2);case 2:n=$e(r.items),e.p=3,n.s();case 4:if((o=n.n()).done){e.n=6;break}if(!(i=o.value).isUnread){e.n=5;break}return e.n=5,this.tracker.client.send("Ack",{location:i.location});case 5:e.n=4;break;case 6:e.n=8;break;case 7:e.p=7,a=e.v,n.e(a);case 8:return e.p=8,n.f(),e.f(8);case 9:return e.a(2)}},e,this,[[3,7,8,9]])})),function(e){return u.apply(this,arguments)})},{key:"summarize",value:(c=Ye(ze().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b;return ze().w(function(e){for(;;)switch(e.p=e.n){case 0:if(r=t.topicId?"topic:".concat(t.roomId,":").concat(t.topicId):t.roomId?"room:".concat(t.roomId):t.spaceId?"space:".concat(t.spaceId):"spaceless",!this.summariesCache.has(r)){e.n=1;break}return e.a(2,this.summariesCache.get(r));case 1:return n=[],e.n=2,this.tracker.rooms.get();case 2:if(i=e.v,!t.topicId){e.n=4;break}if(t.roomId){e.n=3;break}throw new Error("roomId is required when querying by topicId");case 3:n=[t.roomId],o=t.topicId,e.n=9;break;case 4:if(!t.roomId){e.n=5;break}n=[t.roomId],e.n=9;break;case 5:if(!t.spaceId){e.n=7;break}return e.n=6,this.cacheForSpace(t.spaceId);case 6:n=i.findBy("spaceId",t.spaceId).items.map(function(e){return e.id}),e.n=9;break;case 7:return e.n=8,this.cacheForSpace(null);case 8:n=i.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id});case 9:a=0,c=0,u=$e(n),e.p=10,u.s();case 11:if((s=u.n()).done){e.n=22;break}return l=s.value,e.n=12,this.getForRoom(l);case 12:if(f=e.v){e.n=13;break}return e.a(3,21);case 13:h=$e(f.items),e.p=14,h.s();case 15:if((p=h.n()).done){e.n=18;break}if(y=p.value,!o||y.location.topicId===o){e.n=16;break}return e.a(3,17);case 16:y.isUnread&&c++,a+=null!==(d=y.mentionCount)&&void 0!==d?d:0;case 17:e.n=15;break;case 18:e.n=20;break;case 19:e.p=19,v=e.v,h.e(v);case 20:return e.p=20,h.f(),e.f(20);case 21:e.n=11;break;case 22:e.n=24;break;case 23:e.p=23,b=e.v,u.e(b);case 24:return e.p=24,u.f(),e.f(24);case 25:return m={mentionCount:a,unreadTopicCount:c,isUnread:c>0},this.summariesCache.set(r,m),e.a(2,m)}},e,this,[[14,19,20,21],[10,23,24,25]])})),function(e){return c.apply(this,arguments)})},{key:"_deleteByTopicIds",value:function(e){for(var t,r=this,n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];null===(t=this.followedTopics.get(e))||void 0===t||t.delete.apply(t,o),o.forEach(function(t){return r.invalidateUnreadSummaries(e,t)})}},{key:"handleSession",value:function(e){var t,r=$e(this.followedTopics.items.keys());try{for(r.s();!(t=r.n()).done;){var n=t.value;this.staleRooms.add(n)}}catch(e){r.e(e)}finally{r.f()}this.followedTopicsPromises.forgetAll(),this.invalidateUnreadSummaries(),this.deferredSession.resolve()}},{key:"handleNewMessage",value:function(e){this.updateLocallyFollowedTopicOnNewMessage(e)}},{key:"handleFollowedTopicUpdated",value:function(e){var t;null===(t=this.followedTopics.get(e.followedTopic.location.roomId))||void 0===t||t.set(e.followedTopic),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleTopicFollowed",value:function(e){this.setFollowedTopicsArray([e.followedTopic.location.roomId],[e.followedTopic]),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleTopicUnfollowed",value:function(e){var t;null===(t=this.followedTopics.get(e.location.roomId))||void 0===t||t.delete(e.location.topicId),this.invalidateUnreadSummaries(e.location.roomId,e.location.topicId)}},{key:"handleRoomDeleted",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleRoomJoin",value:function(e){this.clearRoomFollowedTopicsStructures(e.room.id)}},{key:"handleRoomLeft",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleNewTopic",value:(a=Ye(ze().m(function e(t){var r,n;return ze().w(function(e){for(;;)switch(e.n){case 0:if(!this.followedTopics.has(t.roomId)){e.n=2;break}return e.n=1,this.tracker.client.send("GetFollowedTopics",{location:{roomId:t.roomId,topicId:t.topic.id}});case 1:r=e.v,(n=r.data.followedTopics[0])&&(this.followedTopics.get(t.roomId).set(n),this.invalidateUnreadSummaries(t.roomId,t.topic.id));case 2:return e.a(2)}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t;null===(t=this.followedTopics.get(e.location.roomId))||void 0===t||t.delete(e.location.topicId),this.invalidateUnreadSummaries(e.location.roomId,e.location.topicId)}},{key:"invalidateUnreadSummaries",value:function(e,t){if(e){if(this.summariesCache.delete("room:".concat(e)),t)this.summariesCache.delete("topic:".concat(e,":").concat(t));else{var r,n=$e(this.summariesCache.keys());try{for(n.s();!(r=n.n()).done;){var o=r.value;o.startsWith("topic:".concat(e,":"))&&this.summariesCache.delete(o)}}catch(e){n.e(e)}finally{n.f()}}var i,a=$e(this.summariesCache.keys());try{for(a.s();!(i=a.n()).done;){var c=i.value;(c.startsWith("space:")||"spaceless"===c)&&this.summariesCache.delete(c)}}catch(e){a.e(e)}finally{a.f()}}else this.summariesCache.clear();this.emit("change")}},{key:"invalidateUnreadSummariesForRooms",value:function(e){var t=this,r=new Set(e);e.forEach(function(e){t.summariesCache.delete("room:".concat(e))});var n,o=$e(this.summariesCache.keys());try{for(o.s();!(n=o.n()).done;){var i=n.value;if(i.startsWith("space:")||"spaceless"===i)this.summariesCache.delete(i);else if(i.startsWith("topic:")){var a=i.split(":");a.length>=2&&r.has(a[1])&&this.summariesCache.delete(i)}}}catch(e){o.e(e)}finally{o.f()}this.emit("change")}},{key:"updateLocallyFollowedTopicOnNewMessage",value:(i=Ye(ze().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h;return ze().w(function(e){for(;;)switch(e.n){case 0:if(r=this.followedTopics.get(t.message.location.roomId),n=null==r?void 0:r.get(t.message.location.topicId),r&&n&&"Ephemeral"!==t.message.type){e.n=1;break}return e.a(2);case 1:return e.n=2,this.tracker.getMe();case 2:if(o=e.v,t.message.author.user.id!==o.id){e.n=3;break}i={missed:0,lastAckMessageId:t.message.id},e.n=6;break;case 3:if("Text"!==t.message.type){e.n=5;break}return e.n=4,this.tracker.rooms.getMe(t.message.location.roomId);case 4:s=e.v,l=[].concat(He(null!==(a=null===(c=s.spaceMember)||void 0===c?void 0:c.roles)&&void 0!==a?a:[]),He(null!==(u=s.roles)&&void 0!==u?u:[])),f=[].concat(He(l.map(function(e){return"<@&".concat(e,">")})),["<@".concat(o.id,">")]),h=f.some(function(e){return t.message.content.includes(e)}),i={missed:null===n.missed?null:n.missed+1,isUnread:!0,mentionCount:n.mentionCount+(h?1:0)},e.n=6;break;case 5:i={missed:null===n.missed?null:n.missed+1,isUnread:!0};case 6:r.set(Je(Je({},n),i)),this.invalidateUnreadSummaries(t.message.location.roomId,t.message.location.topicId);case 7:return e.a(2)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"applyRoomFollowedTopics",value:function(e,t){var r;this.followedTopics.has(e)||this.followedTopics.set([e,new D(function(e){return e.location.topicId})]),(r=this.followedTopics.get(e)).reconcile.apply(r,He(t)),this.staleRooms.delete(e)}},{key:"reconcileRoomsFollowedTopics",value:function(e,t){var r=this,n={};t.forEach(function(e){var t,r;(null!==(r=n[t=e.location.roomId])&&void 0!==r?r:n[t]=[]).push(e)}),e.forEach(function(e){var t;return r.applyRoomFollowedTopics(e,null!==(t=n[e])&&void 0!==t?t:[])}),this.invalidateUnreadSummariesForRooms(e)}},{key:"setFollowedTopicsArray",value:function(e,t){var r=this,n={};t.forEach(function(e){var t,r;null!==(r=n[t=e.location.roomId])&&void 0!==r||(n[t]=[]),n[e.location.roomId].push(e)}),e.forEach(function(e){var t;r.followedTopics.has(e)||r.followedTopics.set([e,new D(function(e){return e.location.topicId})]),n[e]&&(t=r.followedTopics.get(e)).set.apply(t,He(n[e]))}),this.invalidateUnreadSummariesForRooms(e)}},{key:"clearRoomFollowedTopicsStructures",value:function(e){this.followedTopics.delete(e),this.followedTopicsPromises.forget(e),this.staleRooms.delete(e),this.invalidateUnreadSummaries(e)}}],n&&Xe(r.prototype,n),o&&Xe(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l}(a);function at(e){return at="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},at(e)}function ct(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ut(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ct(Object(r),!0).forEach(function(t){bt(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ct(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function st(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=ft(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function lt(e){return function(e){if(Array.isArray(e))return ht(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||ft(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ft(e,t){if(e){if("string"==typeof e)return ht(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ht(e,t):void 0}}function ht(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function pt(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return dt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(dt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,dt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,dt(f,"constructor",s),dt(s,"constructor",u),u.displayName="GeneratorFunction",dt(s,o,"GeneratorFunction"),dt(f),dt(f,o,"Generator"),dt(f,n,function(){return this}),dt(f,"toString",function(){return"[object Generator]"}),(pt=function(){return{w:i,m:h}})()}function dt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}dt=function(e,t,r,n){function i(t,r){dt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},dt(e,t,r,n)}function yt(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function mt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){yt(i,n,o,a,c,"next",e)}function c(e){yt(i,n,o,a,c,"throw",e)}a(void 0)})}}function vt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,gt(n.key),n)}}function bt(e,t,r){return(t=gt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function gt(e){var t=function(e,t){if("object"!=at(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=at(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==at(t)?t:t+""}var wt=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),bt(this,"messages",void 0),bt(this,"followedTopics",void 0),bt(this,"list",new D("id")),bt(this,"topics",new x),bt(this,"members",new x),bt(this,"deferredSession",new Q),bt(this,"membersPromises",new V),bt(this,"topicsPromises",new V),this.tracker=t,this.messages=new Ne(t),this.followedTopics=new it(t),this.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),this.tracker.client.on("MessagesRedacted",function(e){return r.handleMessagesRedacted(e)}),this.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoined(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("TopicUpdated",function(e){return r.handleTopicUpdated(e)}),this.tracker.client.on("RoomMemberJoined",function(e){return r.handleRoomMemberJoined(e)}),this.tracker.client.on("RoomMemberLeft",function(e){return r.handleRoomMemberLeft(e)}),this.tracker.client.on("RoomMembers",function(e){return r.handleRoomMembers(e)}),this.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getMembers",value:(a=mt(pt().m(function e(t){var r=this;return pt().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(mt(pt().m(function e(){var n;return pt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetRoomMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleRoomMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=mt(pt().m(function e(t){var r,n;return pt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){var t,n;return(null!==(t=null===(n=e.user)||void 0===n?void 0:n.id)&&void 0!==t?t:e.spaceMember.user.id)===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"get",value:function(){var e=mt(pt().m(function e(){return pt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getTopics",value:(o=mt(pt().m(function e(t,r){var n,o,i,a,c,u,s,l=this;return pt().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:if(null==r||!r.length){e.n=8;break}n=function(e){var r;return!(null!==(r=l.topics.get(t))&&void 0!==r&&r.has(e)||l.topicsPromises.has(t+e))},(o=r.filter(n)).length&&(i=this.tracker.client.send("GetTopics",{roomId:t,topicIds:o}).then(function(e){var t;return null===(t=l.topics.get(e.data.location.roomId))||void 0===t?void 0:t.set.apply(t,lt(e.data.topics))}),o.forEach(function(e){return l.topicsPromises.register(i,t+e)})),a=st(r),e.p=2,a.s();case 3:if((c=a.n()).done){e.n=5;break}return u=c.value,e.n=4,this.topicsPromises.get(t+u);case 4:e.n=3;break;case 5:e.n=7;break;case 6:e.p=6,s=e.v,a.e(s);case 7:return e.p=7,a.f(),e.f(7);case 8:return e.a(2,this.topics.get(t))}},e,this,[[2,6,7,8]])})),function(e,t){return o.apply(this,arguments)})},{key:"_deleteTopicsFromRoom",value:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];null===(t=this.topics.get(e))||void 0===t||t.delete.apply(t,n)}},{key:"deleteRoom",value:function(){for(var e,t,r,n,o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];(e=this.list).delete.apply(e,i),(t=this.members).delete.apply(t,i),(r=this.membersPromises).forget.apply(r,i);for(var c=0,u=i;c<u.length;c++){var s,l,f,h=u[c],p=null!==(s=null===(l=this.topics.get(h))||void 0===l?void 0:l.items.map(function(e){return e.id}))&&void 0!==s?s:[];(f=this.followedTopics)._deleteByTopicIds.apply(f,[h].concat(lt(p)))}(n=this.topics).delete.apply(n,i)}},{key:"deleteRoomsBySpaceId",value:function(e){this.deleteRoom.apply(this,lt(this.list.findBy("spaceId",e).items.map(function(e){return e.id})))}},{key:"handleSpaceMemberUpdated",value:function(e){var t,r=st(this.list.findBy("spaceId",e.spaceId).items);try{for(r.s();!(t=r.n()).done;){var n=t.value,o=this.members.get(n.id);if(o&&o.has(e.userId)){var i=o.get(e.userId),a=e.member;a.user=i.spaceMember.user,o.set(ut(ut({},i),{},{spaceMember:a}))}}}catch(e){r.e(e)}finally{r.f()}}},{key:"handleSpaceMemberLeft",value:function(e){var t=this;this.list.findBy("spaceId",e.spaceId).items.forEach(function(r){var n;return null===(n=t.members.get(r.id))||void 0===n?void 0:n.delete(e.userId)})}},{key:"handleRoomMemberUpdated",value:function(e){var t,r;if(this.members.has(e.roomId)){var n=this.members.get(e.roomId),o=n.get(e.userId),i=e.member,a=null!==(t=null===(r=o.spaceMember)||void 0===r?void 0:r.user)&&void 0!==t?t:o.user;i.spaceMember?i.spaceMember.user=a:i.user=a,n.set(i)}}},{key:"handleSpaceDeleted",value:function(e){this.deleteRoomsBySpaceId(e.id)}},{key:"handleTopicDeleted",value:function(e){var t;this.topics.get(e.location.roomId).delete(e.location.topicId);var r=this.list.get(e.location.roomId);(null===(t=r.defaultTopic)||void 0===t?void 0:t.id)===e.location.topicId&&this.list.set(ut(ut({},r),{},{defaultTopic:null}))}},{key:"handleNewTopic",value:function(e){this.addJoinedRoomTopics(e.roomId,e.topic)}},{key:"addJoinedRoomTopics",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o;this.topics.has(e)?(o=this.topics.get(e)).set.apply(o,r):this.topics.set([e,new D("id",r)])}},{key:"handleRoomJoined",value:function(e){this.addJoinedRooms(e.room)}},{key:"handleRoomUpdated",value:function(e){this.list.has(e.room.id)&&this.list.set(e.room)}},{key:"handleRoomDeleted",value:function(e){this.deleteRoom(e.id)}},{key:"handleTopicUpdated",value:function(e){var t,r=this.list.get(e.location.roomId);if(null!==(t=this.topics.get(e.location.roomId))&&void 0!==t&&t.has(e.topic.id)&&this.topics.get(e.location.roomId).set(e.topic),r.defaultTopic.id===e.topic.id){var n=ut({},r);n.defaultTopic=e.topic,this.list.set(n)}}},{key:"addJoinedRooms",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];for(var o=0,i=r;o<i.length;o++){var a=i[o];a.defaultTopic&&this.addJoinedRoomTopics(a.id,a.defaultTopic),"Pm"===a.type&&a.recipients&&(this.handleRoomMembers({id:a.id,members:a.recipients.map(function(e){return{user:e,spaceMember:null,roles:null,customColor:null,customNick:null,extras:""}})}),this.membersPromises.register(Promise.resolve(),a.id))}(e=this.list).set.apply(e,r)}},{key:"handleRoomLeft",value:function(e){this.deleteRoom(e.id)}},{key:"handleRoomMemberJoined",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).set(e.member)}},{key:"handleRoomMemberLeft",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).delete(e.userId)}},{key:"handleRoomMembers",value:function(e){var t;this.members.has(e.id)?(t=this.members.get(e.id)).reconcile.apply(t,lt(e.members)):this.members.set([e.id,new D(function(e){var t,r;return null!==(t=null===(r=e.user)||void 0===r?void 0:r.id)&&void 0!==t?t:e.spaceMember.user.id},e.members)])}},{key:"handleSession",value:function(e){var t=new Set(e.state.rooms.map(function(e){return e.id})),r=this.list.items.filter(function(e){return!t.has(e.id)}).map(function(e){return e.id});r.length&&this.deleteRoom.apply(this,lt(r)),this.membersPromises.forgetAll(),this.topicsPromises.forgetAll(),this.addJoinedRooms.apply(this,lt(e.state.rooms)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){var t;this.members.items.forEach(function(t){var r=t.get(e.user.id);if(r){var n=ut({},r);r.user?n.user=e.user:n.spaceMember.user=e.user,t.set(n)}});var r=[];this.list.items.forEach(function(t){var n;null!==(n=t.recipients)&&void 0!==n&&n.some(function(t){return t.id===e.user.id})&&(t.recipients=t.recipients.map(function(t){return t.id===e.user.id?e.user:t}),r.push(ut({},t)))}),(t=this.list).set.apply(t,r)}},{key:"handleNewMessage",value:function(e){var t,r=this.topics.get(e.message.location.roomId),n=null==r?void 0:r.get(e.message.location.topicId);if(n){var o=ut(ut({},n),{},{messageCount:n.messageCount+1,lastMessage:e.message});r.set(o);var i=this.list.get(e.message.location.roomId);(null===(t=i.defaultTopic)||void 0===t?void 0:t.id)===e.message.location.topicId&&this.list.set(ut(ut({},i),{},{defaultTopic:o}))}}},{key:"handleMessagesRedacted",value:(n=mt(pt().m(function e(t){var r,n,o,i,a;return pt().w(function(e){for(;;)switch(e.n){case 0:if(r=this.topics.get(t.location.roomId),!(n=null==r?void 0:r.get(t.location.topicId))){e.n=4;break}if(!((o=Math.max(n.messageCount-t.ids.length,0))>0)){e.n=2;break}return e.n=1,this.messages._resolveLastMessage(t.location);case 1:a=e.v,e.n=3;break;case 2:a=null;case 3:i=a,r.set(ut(ut({},n),{},{messageCount:o,lastMessage:i}));case 4:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})}],t&&vt(e.prototype,t),r&&vt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a}();function kt(e){var t,r;return null!==(t=e.user)&&void 0!==t?t:null===(r=e.spaceMember)||void 0===r?void 0:r.user}function St(e){return St="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},St(e)}function Ot(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Tt(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function jt(e){return function(e){if(Array.isArray(e))return Pt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Tt(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Tt(e,t){if(e){if("string"==typeof e)return Pt(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Pt(e,t):void 0}}function Pt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function It(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Et(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?It(Object(r),!0).forEach(function(t){Ft(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):It(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Rt(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return At(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(At(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,At(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,At(f,"constructor",s),At(s,"constructor",u),u.displayName="GeneratorFunction",At(s,o,"GeneratorFunction"),At(f),At(f,o,"Generator"),At(f,n,function(){return this}),At(f,"toString",function(){return"[object Generator]"}),(Rt=function(){return{w:i,m:h}})()}function At(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}At=function(e,t,r,n){function i(t,r){At(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},At(e,t,r,n)}function _t(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Mt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){_t(i,n,o,a,c,"next",e)}function c(e){_t(i,n,o,a,c,"throw",e)}a(void 0)})}}function Ct(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Lt(n.key),n)}}function Ft(e,t,r){return(t=Lt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Lt(e){var t=function(e,t){if("object"!=St(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=St(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==St(t)?t:t+""}var xt=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Ft(this,"list",new D("id")),Ft(this,"roles",new x),Ft(this,"rooms",new x),Ft(this,"roomIdToSpaceId",new x),Ft(this,"members",new x),Ft(this,"deferredSession",new Q),Ft(this,"roomsPromises",new V),Ft(this,"membersPromises",new V),this.tracker=t,this.tracker.client.on("NewRoom",function(e){return r.handleNewRoom(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceUpdated",function(e){return r.handleSpaceUpdated(e)}),this.tracker.client.on("SpaceJoined",function(e){return r.handleSpaceJoined(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceMemberJoined",function(e){return r.handleSpaceMemberJoined(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMembers",function(e){return r.handleSpaceMembers(e)}),this.tracker.client.on("SpaceRooms",function(e){return r.handleSpaceRooms(e)}),this.tracker.client.on("RoomSummaryUpdated",function(e){return r.handleRoomSummaryUpdated(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("NewRole",function(e){return r.handleNewRole(e)}),this.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),this.tracker.client.on("RoleUpdated",function(e){return r.handleRoleUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"get",value:function(){var e=Mt(Rt().m(function e(){return Rt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getRoles",value:(u=Mt(Rt().m(function e(t){return Rt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roles.get(t))}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"getRooms",value:(c=Mt(Rt().m(function e(t){var r=this;return Rt().w(function(e){for(;;)switch(e.n){case 0:return this.roomsPromises.notExist(t)&&this.roomsPromises.registerByFunction(Mt(Rt().m(function e(){var n;return Rt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceRooms",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceRooms(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.roomsPromises.get(t);case 1:return e.a(2,this.rooms.get(t))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getMembers",value:(a=Mt(Rt().m(function e(t){var r=this;return Rt().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(Mt(Rt().m(function e(){var n;return Rt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=Mt(Rt().m(function e(t){var r,n;return Rt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){return e.user.id===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"handleNewRole",value:function(e){var t=this.roles.get(e.spaceId);t.set(e.role),this.list.get(e.spaceId).roles=t.items}},{key:"handleNewRoom",value:function(e){var t;null===(t=this.rooms.get(e.spaceId))||void 0===t||t.set(e.summary),this.roomIdToSpaceId.set([e.summary.id,e.spaceId])}},{key:"handleRoomUpdated",value:function(e){if(e.room.spaceId&&this.rooms.has(e.room.spaceId)){var t=this.rooms.get(e.room.spaceId);t.set(Et(Et({},t.get(e.room.id)),{},{name:e.room.name,description:e.room.description}))}}},{key:"handleRoomDeleted",value:(o=Mt(Rt().m(function e(t){var r,n,o,i;return Rt().w(function(e){for(;;)switch(e.n){case 0:if(n=this.roomIdToSpaceId.get(t.id),this.roomIdToSpaceId.delete(t.id),n){e.n=1;break}return e.a(2);case 1:o=this.list.get(n),i=!1,null===(r=this.rooms.get(n))||void 0===r||r.delete(t.id),o.systemRoom===t.id&&(o.systemRoom=null,i=!0),o.defaultRooms.includes(t.id)&&(o.defaultRooms=o.defaultRooms.filter(function(e){return e!==t.id}),i=!0),i&&this.list.set(o);case 2:return e.a(2)}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoleDeleted",value:function(e){var t=this.roles.get(e.spaceId);t.delete(e.id),this.list.get(e.spaceId).roles=t.items}},{key:"handleSpaceUpdated",value:function(e){this.list.set(e.space)}},{key:"handleSpaceDeleted",value:function(e){var t,r,n,o=null!==(t=null===(r=this.rooms.get(e.id))||void 0===r?void 0:r.items.map(function(e){return e.id}))&&void 0!==t?t:[];(n=this.roomIdToSpaceId).delete.apply(n,jt(o)),this.roles.delete(e.id),this.members.delete(e.id),this.membersPromises.forget(e.id),this.rooms.delete(e.id),this.roomsPromises.forget(e.id),this.list.delete(e.id)}},{key:"handleSpaceJoined",value:function(e){this.addJoinedSpaces(e.space)}},{key:"addJoinedSpaces",value:function(){for(var e,t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this.roles).set.apply(e,jt(n.map(function(e){return[e.id,new D("id",e.roles)]}))),(t=this.list).set.apply(t,n)}},{key:"handleSpaceMemberJoined",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).set(e.member)}},{key:"handleSpaceMemberLeft",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).delete(e.userId)}},{key:"handleSpaceMembers",value:function(e){var t;this.members.has(e.id)?(t=this.members.get(e.id)).reconcile.apply(t,jt(e.members)):this.members.set([e.id,new D(function(e){return null==e?void 0:e.user.id},e.members)])}},{key:"handleSpaceRooms",value:function(e){var t,r=this;this.rooms.has(e.id)?(t=this.rooms.get(e.id)).reconcile.apply(t,jt(e.summaries)):this.rooms.set([e.id,new D("id",e.summaries)]),e.summaries.forEach(function(t){return r.roomIdToSpaceId.set([t.id,e.id])})}},{key:"handleRoomSummaryUpdated",value:(n=Mt(Rt().m(function e(t){var r,n,o,i,a;return Rt().w(function(e){for(;;)switch(e.n){case 0:if(r=this.roomIdToSpaceId.get(t.summary.id),n=this.roomsPromises.get(r),!r||!n){e.n=2;break}return e.n=1,n;case 1:o=this.rooms.get(r),i=o.get(t.summary.id),a=i?Et(Et({},i),t.summary):t.summary,o.set(a);case 2:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleSpaceMemberUpdated",value:function(e){if(this.members.has(e.spaceId)){var t=this.members.get(e.spaceId),r=t.get(e.userId);t.set(Et(Et({},e.member),{},{user:r.user}))}}},{key:"handleRoleUpdated",value:function(e){var t,r=this.roles.get(e.spaceId),n=r.get(e.role.id),o=e.role,i=[o];n.priority!==o.priority&&i.push.apply(i,jt(function(e,t,r){var n=r.priority-t.priority>0,o=!n,i=[];return e.forEach(function(e){e.id!==r.id&&(n&&t.priority<=e.priority&&(e.priority--,i.push(e)),o&&r.priority<=e.priority&&(e.priority++,i.push(e)))}),i}(r.items,n,o))),(t=this.roles.get(e.spaceId)).set.apply(t,i)}},{key:"handleSession",value:function(e){var t,r,n=new Set(e.state.spaces.map(function(e){return e.id})),o=this.list.items.filter(function(e){return!n.has(e.id)}).map(function(e){return e.id}),i=Ot(o);try{for(i.s();!(r=i.n()).done;){var a=r.value;this.handleSpaceDeleted({id:a})}}catch(e){i.e(e)}finally{i.f()}this.roomsPromises.forgetAll(),this.membersPromises.forgetAll();var c,u=Ot(e.state.spaces);try{for(u.s();!(c=u.n()).done;){var s,l=c.value;this.roles.has(l.id)?(s=this.roles.get(l.id)).reconcile.apply(s,jt(l.roles)):this.roles.set([l.id,new D("id",l.roles)])}}catch(e){u.e(e)}finally{u.f()}(t=this.list).set.apply(t,jt(e.state.spaces)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){this.members.items.forEach(function(t){var r=t.get(e.user.id);r&&t.set(Et(Et({},r),{},{user:e.user}))})}}],t&&Ct(e.prototype,t),r&&Ct(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a,c,u}();function Gt(e){return Gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Gt(e)}function Ut(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Wt(n.key),n)}}function Dt(e,t,r){return t&&Ut(e.prototype,t),r&&Ut(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Nt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Bt(e,t,r){return(t=Wt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Wt(e){var t=function(e,t){if("object"!=Gt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Gt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Gt(t)?t:t+""}var Jt=function(e){return e[e.Global=0]="Global",e[e.Space=1]="Space",e[e.Room=2]="Room",e[e.Topic=3]="Topic",e}({}),Ht=Dt(function e(){Nt(this,e),Bt(this,"value",void 0),Bt(this,"maxLayer",void 0)}),$t=function(){return Dt(function e(){Nt(this,e)},null,[{key:"getNames",value:function(){return Object.keys(this.list)}},{key:"getByName",value:function(e){return this.list[e]}},{key:"canBeDefinedOnLayer",value:function(e,t){if(!this.getByName(e))throw new Error("Invalid permission name: ".concat(e));return t<=this.getByName(e).maxLayer}}])}();function Qt(e){return Qt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Qt(e)}function Vt(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Kt(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function zt(e){return function(e){if(Array.isArray(e))return Yt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Kt(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function qt(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||Kt(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Kt(e,t){if(e){if("string"==typeof e)return Yt(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Yt(e,t):void 0}}function Yt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Xt(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Zt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Zt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Zt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Zt(f,"constructor",s),Zt(s,"constructor",u),u.displayName="GeneratorFunction",Zt(s,o,"GeneratorFunction"),Zt(f),Zt(f,o,"Generator"),Zt(f,n,function(){return this}),Zt(f,"toString",function(){return"[object Generator]"}),(Xt=function(){return{w:i,m:h}})()}function Zt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Zt=function(e,t,r,n){function i(t,r){Zt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Zt(e,t,r,n)}function er(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function tr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){er(i,n,o,a,c,"next",e)}function c(e){er(i,n,o,a,c,"throw",e)}a(void 0)})}}function rr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,ur(n.key),n)}}function nr(e,t,r){return t=ir(t),function(e,t){if(t&&("object"==Qt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,or()?Reflect.construct(t,r||[],ir(e).constructor):t.apply(e,r))}function or(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(or=function(){return!!e})()}function ir(e){return ir=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ir(e)}function ar(e,t){return ar=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ar(e,t)}function cr(e,t,r){return(t=ur(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ur(e){var t=function(e,t){if("object"!=Qt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Qt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Qt(t)?t:t+""}Bt($t,"list",{Root:{value:1,maxLayer:Jt.Room},CreateSpaces:{value:2,maxLayer:Jt.Global},ManageSpace:{value:4,maxLayer:Jt.Space},ManageRoles:{value:8,maxLayer:Jt.Space},CreateTopics:{value:32,maxLayer:Jt.Room},ManageTopic:{value:64,maxLayer:Jt.Topic},ManageMemberProfiles:{value:128,maxLayer:Jt.Space},ManageMemberRoles:{value:256,maxLayer:Jt.Room},CreateMessages:{value:512,maxLayer:Jt.Topic},ManagePermissions:{value:1024,maxLayer:Jt.Topic},CreateRooms:{value:2048,maxLayer:Jt.Space},ManageRoom:{value:4096,maxLayer:Jt.Room},CreateEmoticons:{value:8192,maxLayer:Jt.Space},ManageEmoticons:{value:16384,maxLayer:Jt.Space},ManageBans:{value:32768,maxLayer:Jt.Room},Kick:{value:65536,maxLayer:Jt.Room},ChangeOwnNick:{value:1<<17,maxLayer:Jt.Space},ChangeOwnColor:{value:1<<18,maxLayer:Jt.Room},RedactMessages:{value:1<<19,maxLayer:Jt.Topic}});var sr=function(e,t){return[e.spaceId,e.roomId,e.topicId,null==t?void 0:t.type,null==t?void 0:t.userId,null==t?void 0:t.roleId].filter(Boolean).join("/")},lr=function(e){return sr(e.location,e.target)},fr=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),cr(r=nr(this,t),"overwrites",new x),cr(r,"overwritesPromises",new V),r.tracker=e,r.tracker.client.on("PermissionOverwrites",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("PermissionOverwritesUpdated",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),r.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),r.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&ar(e,t)}(t,e),r=t,n=[{key:"getOverwrites",value:(f=tr(Xt().m(function e(t,r){var n,o=this;return Xt().w(function(e){for(;;)switch(e.n){case 0:return this.validateLocation(t),n=sr(t,r),this.overwritesPromises.notExist(n)&&this.overwritesPromises.registerByFunction(tr(Xt().m(function e(){var n;return Xt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.tracker.client.send("GetPermissionOverwrites",{location:t,target:r});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:o.handlePermissionOverwrites(n.data);case 3:return e.a(2)}},e)})),n),e.n=1,this.overwritesPromises.get(n);case 1:return e.a(2,this.overwrites.get(n))}},e,this)})),function(e,t){return f.apply(this,arguments)})},{key:"check",value:(l=tr(Xt().m(function e(t,r){var n,o;return Xt().w(function(e){for(;;)switch(e.n){case 0:if(t.length){e.n=1;break}throw new Error("Permission names array cannot be empty");case 1:return e.n=2,this.calculatePermissions(r);case 2:return n=e.v,o=[],t.forEach(function(e){~n&$t.getByName(e).value&&o.push(e)}),e.a(2,{ok:0===o.length,hasAll:0===o.length,hasAny:o.length<t.length,missing:o})}},e,this)})),function(e,t){return l.apply(this,arguments)})},{key:"calculatePermissions",value:(s=tr(Xt().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b,g,w,k,S,O,j,T,P;return Xt().w(function(e){for(;;)switch(e.n){case 0:if(!t.roomId){e.n=2;break}return e.n=1,this.tracker.rooms.get();case 1:v=e.v.get(t.roomId),e.n=3;break;case 2:v=null;case 3:return c=v,t={spaceId:null!==(r=t.spaceId)&&void 0!==r?r:null==c?void 0:c.spaceId,roomId:t.roomId,topicId:t.topicId},this.validateLocation(t),e.n=4,this.tracker.getMe();case 4:return u=e.v.id,e.n=5,this.fetchMembersOrFail(t);case 5:if(s=e.v,l=qt(s,2),f=l[0],h=l[1],p=[].concat(zt(null!==(n=null==f?void 0:f.roles)&&void 0!==n?n:[]),zt(null!==(o=null==h?void 0:h.roles)&&void 0!==o?o:[])),d=[this.getOverwrites({},{type:"User",userId:u}).then(function(e){return e.overwrites})],!(b=t.spaceId)){e.n=9;break}return e.n=6,this.tracker.spaces.get();case 6:if(k=i=e.v,!(w=null!==k)){e.n=7;break}w=void 0!==i;case 7:if(!(g=w)){e.n=8;break}g=i.has(t.spaceId);case 8:b=g;case 9:if(!b){e.n=10;break}y={spaceId:t.spaceId},d.push(this.collectRoleOverwrites(y,p)),d.push(this.getOverwrites(y,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 10:if(c&&(m={spaceId:t.spaceId,roomId:t.roomId},p.length&&d.push(this.collectRoleOverwrites(m,p)),d.push(this.getOverwrites(m,{type:"User",userId:u}).then(function(e){return e.overwrites}))),!(S=t.topicId)){e.n=14;break}return e.n=11,this.tracker.rooms.getTopics(t.roomId);case 11:if(T=a=e.v,!(j=null!==T)){e.n=12;break}j=void 0!==a;case 12:if(!(O=j)){e.n=13;break}O=a.has(t.topicId);case 13:S=O;case 14:if(!S){e.n=15;break}p.length&&d.push(this.collectRoleOverwrites(t,p)),d.push(this.getOverwrites(t,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 15:return P=this,e.n=16,Promise.all(d);case 16:return e.a(2,P.resolveOverwritesHierarchy.call(P,e.v))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"handlePermissionOverwrites",value:function(e){this.overwrites.set([lr(e),e]),this.emit("change")}},{key:"handleSpaceDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(sr({spaceId:e.id}));(t=this.overwritesPromises).forget.apply(t,zt(r))}},{key:"handleRoomDeleted",value:(u=tr(Xt().m(function e(t){var r,n,o;return Xt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:(r=e.v.get(t.id))&&(o=this.deleteOverwritesByIdPrefix(sr({spaceId:r.spaceId,roomId:r.id})),(n=this.overwritesPromises).forget.apply(n,zt(o)));case 2:return e.a(2)}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(sr(e.location));(t=this.overwritesPromises).forget.apply(t,zt(r))}},{key:"handleRoleDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(sr({spaceId:e.spaceId},{type:"Role",roleId:e.id}));(t=this.overwritesPromises).forget.apply(t,zt(r))}},{key:"handleSpaceMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"handleRoomMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"deleteOverwritesByIdPrefix",value:function(e){var t=this,r=[];return this.overwrites.items.forEach(function(n){var o=lr(n);o.startsWith(e)&&(r.push(o),t.overwrites.delete(o))}),r}},{key:"collectRoleOverwrites",value:(c=tr(Xt().m(function e(t,r){var n,o=this;return Xt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all(r.map(function(e){return o.getOverwrites(t,{type:"Role",roleId:e})}));case 1:return n=e.v,e.a(2,this.resolveOverwritesFromRolesByOrder(t.spaceId,n))}},e,this)})),function(e,t){return c.apply(this,arguments)})},{key:"resolveOverwritesFromRolesByOrder",value:(a=tr(Xt().m(function e(t,r){var n,o,i,a,c;return Xt().w(function(e){for(;;)switch(e.n){case 0:return n=0,o=0,e.n=1,this.tracker.spaces.getRoles(t);case 1:return i=e.v,a=r.sort(function(e,t){return i.get(e.target.roleId).priority-i.get(t.target.roleId).priority}),c=r.reduce(function(e,t){var r,n,o,i;return Math.max(e,null!==(r=null===(n=t.overwrites.allow)||void 0===n?void 0:n.toString(2).length)&&void 0!==r?r:0,null!==(o=null===(i=t.overwrites.deny)||void 0===i?void 0:i.toString(2).length)&&void 0!==o?o:0)},0),a.forEach(function(e){for(var t,r,i,a,u=e.overwrites,s=null!==(t=null===(r=u.deny)||void 0===r?void 0:r.toString(2).split("").reverse().join(""))&&void 0!==t?t:"",l=null!==(i=null===(a=u.allow)||void 0===a?void 0:a.toString(2).split("").reverse().join(""))&&void 0!==i?i:"",f=0;f<c;f++){var h,p,d=parseInt(null!==(h=s[f])&&void 0!==h?h:"0"),y=parseInt(null!==(p=l[f])&&void 0!==p?p:"0");d&&(o|=1<<f),y&&(n|=1<<f)}}),e.a(2,{allow:n,deny:o})}},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"resolveOverwritesHierarchy",value:function(e){var t,r=0,n=Vt(e);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(o.allow&$t.getByName("Root").value)return this.getRootAccessValue();r=r&~o.deny|o.allow}}catch(e){n.e(e)}finally{n.f()}return r}},{key:"getRootAccessValue",value:function(){var e,t=0,r=Vt($t.getNames());try{for(r.s();!(e=r.n()).done;){var n=e.value;t|=$t.getByName(n).value}}catch(e){r.e(e)}finally{r.f()}return t}},{key:"fetchMembersOrFail",value:(i=tr(Xt().m(function e(t){var r,n,o,i;return Xt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all([t.spaceId?this.tracker.spaces.getMe(t.spaceId):null,t.roomId?this.tracker.rooms.getMe(t.roomId):null]);case 1:if(r=e.v,n=t.spaceId&&!r[0],o=t.roomId&&!r[1],!n&&!o){e.n=2;break}throw i=n?"space (".concat(t.spaceId,")"):"room (".concat(t.roomId,")"),new Error("Attempting to calculate permissions for a ".concat(i," that the user does not belong to"));case 2:return e.a(2,r)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"validateLocation",value:function(e){if(e.topicId&&!e.roomId)throw new Error("Corrupted arguments hierarchy")}},{key:"handleSession",value:function(e){this.overwritesPromises.forgetAll(),this.emit("change")}}],n&&rr(r.prototype,n),o&&rr(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l,f}(a);function hr(e){return hr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},hr(e)}function pr(e){return function(e){if(Array.isArray(e))return dr(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return dr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?dr(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function dr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function yr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return mr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(mr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,mr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,mr(f,"constructor",s),mr(s,"constructor",u),u.displayName="GeneratorFunction",mr(s,o,"GeneratorFunction"),mr(f),mr(f,o,"Generator"),mr(f,n,function(){return this}),mr(f,"toString",function(){return"[object Generator]"}),(yr=function(){return{w:i,m:h}})()}function mr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}mr=function(e,t,r,n){function i(t,r){mr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},mr(e,t,r,n)}function vr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function br(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){vr(i,n,o,a,c,"next",e)}function c(e){vr(i,n,o,a,c,"throw",e)}a(void 0)})}}function gr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,kr(n.key),n)}}function wr(e,t,r){return(t=kr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function kr(e){var t=function(e,t){if("object"!=hr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=hr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==hr(t)?t:t+""}var Sr="global",Or=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),wr(this,"list",new x),wr(this,"emoticonsPromises",new V),this.tracker=t,this.tracker.client.on("Emoticons",function(e){return r.handleEmoticons(e)}),this.tracker.client.on("NewEmoticon",function(e){return r.handleNewEmoticon(e)}),this.tracker.client.on("EmoticonDeleted",function(e){return r.handleEmoticonDeleted(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=br(yr().m(function e(t){var r,n=this;return yr().w(function(e){for(;;)switch(e.n){case 0:return r=null!=t?t:Sr,this.emoticonsPromises.notExist(r)&&this.emoticonsPromises.registerByFunction(br(yr().m(function e(){var r;return yr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,n.tracker.client.send("GetEmoticons",{spaceId:t});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:n.handleEmoticons(r.data);case 3:return e.a(2)}},e)})),r),e.n=1,this.emoticonsPromises.get(r);case 1:return e.a(2,this.list.get(r))}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"handleEmoticons",value:function(e){var t,r,n=null!==(t=e.location.spaceId)&&void 0!==t?t:Sr;this.list.has(n)||this.list.set([n,new D("id")]),(r=this.list.get(n)).reconcile.apply(r,pr(e.emoticons))}},{key:"handleNewEmoticon",value:function(e){var t,r=this.list.get(null!==(t=e.emoticon.spaceId)&&void 0!==t?t:Sr);null==r||r.set(e.emoticon)}},{key:"handleEmoticonDeleted",value:function(e){var t,r=this.list.get(null!==(t=e.spaceId)&&void 0!==t?t:Sr);null==r||r.delete(e.emoticonId)}},{key:"handleSpaceDeleted",value:function(e){this.list.delete(e.id)}},{key:"handleSession",value:function(){this.emoticonsPromises.forgetAll()}}],t&&gr(e.prototype,t),r&&gr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function jr(e){return jr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},jr(e)}function Tr(e){return function(e){if(Array.isArray(e))return Pr(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return Pr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Pr(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Pr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Ir(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Er(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Er(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Er(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Er(f,"constructor",s),Er(s,"constructor",u),u.displayName="GeneratorFunction",Er(s,o,"GeneratorFunction"),Er(f),Er(f,o,"Generator"),Er(f,n,function(){return this}),Er(f,"toString",function(){return"[object Generator]"}),(Ir=function(){return{w:i,m:h}})()}function Er(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Er=function(e,t,r,n){function i(t,r){Er(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Er(e,t,r,n)}function Rr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Ar(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Mr(n.key),n)}}function _r(e,t,r){return(t=Mr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Mr(e){var t=function(e,t){if("object"!=jr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=jr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==jr(t)?t:t+""}var Cr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),_r(this,"onlineStatus",new a),_r(this,"users",new D("id")),this.tracker=t,t.client.on("UserUpdated",function(e){return r.handleUsers([e.user])}),t.client.on("RoomMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMembers",function(e){return r.handleMembers(e.members)}),t.client.on("RoomMembers",function(e){return r.handleMembers(e.members)}),t.client.on("Messages",function(e){return r.handleUsers(e.messages.map(function(e){return e.author.user}))}),t.client.on("NewMessage",function(e){return r.handleUsers([e.message.author.user])}),t.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getAvailable",value:(n=Ir().m(function e(){return Ir().w(function(e){for(;;)if(0===e.n)return e.a(2,this.users)},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Rr(i,r,o,a,c,"next",e)}function c(e){Rr(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleMembers",value:function(e){this.handleUsers(e.map(kt))}},{key:"handleSession",value:function(e){this.handleUsers([e.user])}},{key:"handleUsers",value:function(e){var t,r=this;e.forEach(function(e){var t=r.users.get(e.id);t&&t.online!==e.online&&r.onlineStatus.emit("change",e)}),(t=this.users).set.apply(t,Tr(e))}}],t&&Ar(e.prototype,t),r&&Ar(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Fr(e){return Fr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Fr(e)}function Lr(e){return function(e){if(Array.isArray(e))return xr(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return xr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?xr(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function xr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Gr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Ur(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Ur(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Ur(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Ur(f,"constructor",s),Ur(s,"constructor",u),u.displayName="GeneratorFunction",Ur(s,o,"GeneratorFunction"),Ur(f),Ur(f,o,"Generator"),Ur(f,n,function(){return this}),Ur(f,"toString",function(){return"[object Generator]"}),(Gr=function(){return{w:i,m:h}})()}function Ur(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Ur=function(e,t,r,n){function i(t,r){Ur(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Ur(e,t,r,n)}function Dr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Nr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Dr(i,n,o,a,c,"next",e)}function c(e){Dr(i,n,o,a,c,"throw",e)}a(void 0)})}}function Br(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Jr(n.key),n)}}function Wr(e,t,r){return(t=Jr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Jr(e){var t=function(e,t){if("object"!=Fr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Fr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Fr(t)?t:t+""}var Hr=function(e,t){return"".concat(e,"-").concat(t)},$r=function(e){return Hr(e.refUser.id,e.type)},Qr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Wr(this,"relationships",new D($r)),Wr(this,"promises",new V),this.tracker=t,this.tracker.client.on("Relationships",function(e){return r.handleRelationships(e)}),this.tracker.client.on("NewRelationship",function(e){return r.handleNewRelationship(e)}),this.tracker.client.on("RelationshipDeleted",function(e){return r.handleRelationshipDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=Nr(Gr().m(function e(){var t=this;return Gr().w(function(e){for(;;)switch(e.n){case 0:return this.promises.notExist("all")&&this.promises.registerByFunction(Nr(Gr().m(function e(){var r;return Gr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,t.tracker.client.send("GetRelationships",{});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:return e.a(2)}},e)})),"all"),e.n=1,this.promises.get("all");case 1:return e.a(2,this.relationships)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"exists",value:(n=Nr(Gr().m(function e(t,r){return Gr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.get();case 1:return e.a(2,this.relationships.has(Hr(t,r)))}},e,this)})),function(e,t){return n.apply(this,arguments)})},{key:"handleRelationships",value:function(e){var t;(t=this.relationships).reconcile.apply(t,Lr(e.relationships))}},{key:"handleNewRelationship",value:function(e){this.promises.has("all")&&this.relationships.set(e.relationship)}},{key:"handleRelationshipDeleted",value:function(e){this.promises.has("all")&&this.relationships.delete($r(e.relationship))}},{key:"handleSession",value:function(){this.promises.forgetAll()}}],t&&Br(e.prototype,t),r&&Br(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n}();function Vr(e){return Vr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Vr(e)}function zr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return qr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(qr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,qr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,qr(f,"constructor",s),qr(s,"constructor",u),u.displayName="GeneratorFunction",qr(s,o,"GeneratorFunction"),qr(f),qr(f,o,"Generator"),qr(f,n,function(){return this}),qr(f,"toString",function(){return"[object Generator]"}),(zr=function(){return{w:i,m:h}})()}function qr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}qr=function(e,t,r,n){function i(t,r){qr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},qr(e,t,r,n)}function Kr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Yr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Zr(n.key),n)}}function Xr(e,t,r){return(t=Zr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Zr(e){var t=function(e,t){if("object"!=Vr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Vr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Vr(t)?t:t+""}var en=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Xr(this,"client",void 0),Xr(this,"permissions",void 0),Xr(this,"rooms",void 0),Xr(this,"spaces",void 0),Xr(this,"emoticons",void 0),Xr(this,"users",void 0),Xr(this,"relationships",void 0),Xr(this,"_me",null),Xr(this,"deferredSession",new Q),this.client=t,this.client.on("Session",function(e){return r.handleSession(e)}),this.permissions=new fr(this),this.rooms=new wt(this),this.spaces=new xt(this),this.emoticons=new Or(this),this.users=new Cr(this),this.relationships=new Qr(this)},t=[{key:"me",get:function(){return this._me}},{key:"getMe",value:(n=zr().m(function e(){return zr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this._me)}},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Kr(i,r,o,a,c,"next",e)}function c(e){Kr(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleSession",value:function(e){this._me=e.user,this.deferredSession.resolve()}}],t&&Yr(e.prototype,t),r&&Yr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function tn(e){return tn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},tn(e)}function rn(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return nn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?nn(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function nn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function on(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return an(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(an(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,an(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,an(f,"constructor",s),an(s,"constructor",u),u.displayName="GeneratorFunction",an(s,o,"GeneratorFunction"),an(f),an(f,o,"Generator"),an(f,n,function(){return this}),an(f,"toString",function(){return"[object Generator]"}),(on=function(){return{w:i,m:h}})()}function an(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}an=function(e,t,r,n){function i(t,r){an(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},an(e,t,r,n)}function cn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function un(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){cn(i,n,o,a,c,"next",e)}function c(e){cn(i,n,o,a,c,"throw",e)}a(void 0)})}}function sn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,yn(n.key),n)}}function ln(e,t,r){return t=hn(t),function(e,t){if(t&&("object"==tn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,fn()?Reflect.construct(t,r||[],hn(e).constructor):t.apply(e,r))}function fn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(fn=function(){return!!e})()}function hn(e){return hn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},hn(e)}function pn(e,t){return pn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},pn(e,t)}function dn(e,t,r){return(t=yn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function yn(e){var t=function(e,t){if("object"!=tn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=tn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==tn(t)?t:t+""}var mn=function(e){return e.connect="connect",e.disconnect="disconnect",e.message="message",e.error="error",e}(mn||{}),vn=function(e){function t(e){var r,n,o,i,a,c,u,s,l;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),dn(l=ln(this,t),"Event",mn),dn(l,"state",void 0),dn(l,"ws",null),dn(l,"sendQueue",[]),dn(l,"connectingTimeoutId",void 0),dn(l,"authenticated",void 0),dn(l,"authenticatedResolvers",null),dn(l,"connectPromise",null),dn(l,"pingMonitorInterval",void 0),dn(l,"inFlightPingTimeout",void 0),dn(l,"lastReceivedMessageAt",void 0),l.options=e,(null===(r=l.options.stateTracking)||void 0===r||r)&&(l.state=new en(l)),null!==(n=e.ping)&&void 0!==n||(e.ping={}),null!==(i=(o=e.ping).enabled)&&void 0!==i||(o.enabled=!0),null!==(c=(a=e.ping).noActivityTimeoutMs)&&void 0!==c||(a.noActivityTimeoutMs=15e3),null!==(s=(u=e.ping).pongBackTimeoutMs)&&void 0!==s||(u.pongBackTimeoutMs=5e3),l}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&pn(e,t)}(t,e),r=t,n=[{key:"connect",value:(a=un(on().m(function e(){var t,r,n,o,i,a=this;return on().w(function(e){for(;;)switch(e.n){case 0:if(!this.isOpenWsState()&&!this.isConnectingWsState()){e.n=1;break}return e.a(2,null!==(o=this.connectPromise)&&void 0!==o?o:void 0);case 1:return null!==(t=this.connectPromise)&&void 0!==t||(this.connectPromise=new Promise(function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return a.authenticatedResolvers=t})),(i=new URLSearchParams(null!==(r=this.options.queryParams)&&void 0!==r?r:{})).set("token",this.options.token),this.ws=new WebSocket("".concat(this.options.url,"?").concat(i)),this.ws.onclose=function(e){return a.onClose(e)},this.ws.onmessage=function(e){return a.onMessage(e)},this.connectingTimeoutId=setTimeout(function(){return a.triggerConnectionTimeout()},null!==(n=this.options.connectingTimeoutMs)&&void 0!==n?n:1e4),this.authenticated=!1,e.a(2,this.connectPromise)}},e,this)})),function(){return a.apply(this,arguments)})},{key:"disconnect",value:function(){var e;this.failPendingCommands(new Error("Client disconnected before the command was answered")),null===(e=this.ws)||void 0===e||e.close(1e3),this.ws=null}},{key:"send",value:(i=un(on().m(function e(t,r){var n,o;return on().w(function(e){for(;;)switch(e.n){case 0:if(n=this.createEnvelope(t,r),o=this.createPromiseFromCommandEnvelope(n),!(this.isConnectingWsState()||!this.authenticated&&this.isOpenWsState())){e.n=1;break}return this.sendQueue.push(n),e.a(2,o);case 1:return this.sendEnvelope(n),e.a(2,o)}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"isReady",get:function(){return this.isOpenWsState()&&this.authenticated}},{key:"sendEnvelope",value:function(e){var t,r;this.isReady?this.ws.send(JSON.stringify(e)):this.handleEnvelopeSendError(e,new Error("Cannot send - client is not ready (state=".concat(null!==(t=null===(r=this.ws)||void 0===r?void 0:r.readyState)&&void 0!==t?t:"[no connection]","; authenticated=").concat(this.authenticated,")")))}},{key:"onMessage",value:function(e){this.lastReceivedMessageAt=Date.now();var t=JSON.parse(e.data);if(this.handleIncomingEnvelope(t),this.emit(t.type,t.data),this.emit(this.Event.message,t),!this.authenticated){var r="Bye"!==t.type;this.authenticated=r,r?(this.startConnectionMonitor(),this.settleConnect(),this.emit(this.Event.connect),this.sendFromQueue()):this.settleConnect(t.data)}}},{key:"onClose",value:function(e){this.stopConnectionMonitor(),clearTimeout(this.connectingTimeoutId);var t=1e3!==e.code;this.failPendingCommands(new Error("Connection closed before the command was answered")),t?this.connect():this.settleConnect(new Error("Connection closed before authentication")),this.emit(this.Event.disconnect,t)}},{key:"settleConnect",value:function(e){var t=this.authenticatedResolvers;this.authenticatedResolvers=null,this.connectPromise=null,t&&(e?t[1](e):t[0]())}},{key:"failPendingCommands",value:function(e){var t=this.sendQueue;this.sendQueue=[];var r,n=rn(t);try{for(n.s();!(r=n.n()).done;){var o=r.value;this.handleEnvelopeSendError(o,e)}}catch(e){n.e(e)}finally{n.f()}this.failAwaitingResponses(e)}},{key:"sendFromQueue",value:function(){var e=this,t=0,r=function(){var r,o=e.sendQueue[n];setTimeout(function(){return e.sendEnvelope(o)},t),t+=null!==(r=e.options.awaitQueueSendDelayMs)&&void 0!==r?r:500};for(var n in this.sendQueue)r();this.sendQueue=[],clearTimeout(this.connectingTimeoutId)}},{key:"triggerConnectionTimeout",value:function(){this.disconnect(),this.emit(this.Event.error,new Error("Connection timeout"))}},{key:"isConnectingWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.CONNECTING}},{key:"isOpenWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.OPEN}},{key:"startConnectionMonitor",value:function(){var e=this;this.options.ping.enabled&&(this.lastReceivedMessageAt=Date.now(),this.pingMonitorInterval=setInterval(un(on().m(function t(){return on().w(function(t){for(;;)switch(t.n){case 0:if(e.isReady&&!e.inFlightPingTimeout){t.n=1;break}return t.a(2);case 1:if(!(Date.now()-e.lastReceivedMessageAt<e.options.ping.noActivityTimeoutMs)){t.n=2;break}return t.a(2);case 2:e.inFlightPingTimeout=setTimeout(function(){e.inFlightPingTimeout=void 0,e.ws.close(3e3)},e.options.ping.pongBackTimeoutMs),e.send("Ping",{}).catch(function(){}).then(function(){clearTimeout(e.inFlightPingTimeout),e.inFlightPingTimeout=void 0});case 3:return t.a(2)}},t)})),1e3))}},{key:"stopConnectionMonitor",value:function(){this.inFlightPingTimeout&&(clearTimeout(this.inFlightPingTimeout),this.inFlightPingTimeout=void 0),this.pingMonitorInterval&&(clearInterval(this.pingMonitorInterval),this.pingMonitorInterval=void 0)}}],n&&sn(r.prototype,n),o&&sn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(v);function bn(e){return bn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},bn(e)}function gn(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return wn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(wn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,wn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,wn(f,"constructor",s),wn(s,"constructor",u),u.displayName="GeneratorFunction",wn(s,o,"GeneratorFunction"),wn(f),wn(f,o,"Generator"),wn(f,n,function(){return this}),wn(f,"toString",function(){return"[object Generator]"}),(gn=function(){return{w:i,m:h}})()}function wn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}wn=function(e,t,r,n){function i(t,r){wn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},wn(e,t,r,n)}function kn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Sn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){kn(i,n,o,a,c,"next",e)}function c(e){kn(i,n,o,a,c,"throw",e)}a(void 0)})}}function On(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Rn(n.key),n)}}function jn(e,t,r){return t=Pn(t),function(e,t){if(t&&("object"==bn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Tn()?Reflect.construct(t,r||[],Pn(e).constructor):t.apply(e,r))}function Tn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Tn=function(){return!!e})()}function Pn(e){return Pn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Pn(e)}function In(e,t){return In=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},In(e,t)}function En(e,t,r){return(t=Rn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Rn(e){var t=function(e,t){if("object"!=bn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=bn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==bn(t)?t:t+""}var An=function(e){return e.message="message",e.error="error",e.destroy="destroy",e}(An||{}),_n=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),En(r=jn(this,t),"Event",An),En(r,"sendStack",[]),r.options=e,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&In(e,t)}(t,e),r=t,n=[{key:"send",value:(a=Sn(gn().m(function e(t,r){var n,o;return gn().w(function(e){for(;;)if(0===e.n)return n=this.createEnvelope(t,r),o={data:n,attempts:0,lastTimeoutId:null},this.sendStack.push(o),this.makeApiCall(o),e.a(2,this.createPromiseFromCommandEnvelope(n))},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"destroy",value:function(){var e=this,t=this.sendStack;this.sendStack=[],t.forEach(function(t){t.lastTimeoutId&&clearTimeout(t.lastTimeoutId),e.handleEnvelopeSendError(t.data,new Error("Client destroyed"))}),this.emit(this.Event.destroy,!1)}},{key:"onMessage",value:(i=Sn(gn().m(function e(t,r){var n;return gn().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,r.json();case 1:n=e.v,e.n=3;break;case 2:return e.p=2,e.v,this.onError(t,"envelope ".concat(t.data.ref," (HTTP ").concat(r.status,", unparsable body)")),e.a(2);case 3:if(this.removeFromStack(t)){e.n=4;break}return e.a(2);case 4:this.handleIncomingEnvelope(n),this.emit(n.type,n.data),this.emit(this.Event.message,n);case 5:return e.a(2)}},e,this,[[0,2]])})),function(e,t){return i.apply(this,arguments)})},{key:"onError",value:function(e,t){var r,n,o=this;if(this.sendStack.includes(e))return e.attempts>=(null!==(r=this.options.attemptsToSend)&&void 0!==r?r:10)?(this.removeFromStack(e),void this.handleEnvelopeSendError(e.data,new Error("Cannot send ".concat(t,"; aborting after reaching the maximum connection errors")))):void(e.lastTimeoutId=setTimeout(function(){return o.makeApiCall(e)},null!==(n=this.options.attemptDelayMs)&&void 0!==n?n:3e3))}},{key:"makeApiCall",value:function(e){var t,r=this;if(this.sendStack.includes(e)){e.attempts++,e.lastTimeoutId=null;var n=JSON.stringify(e.data),o={"Content-Type":"application/json",Accept:"application/json"};o.Authorization="Bearer ".concat(this.options.token);var i=new URLSearchParams(null!==(t=this.options.queryParams)&&void 0!==t?t:{}).toString(),a=i?"".concat(this.options.url,"?").concat(i):this.options.url;fetch(a,{headers:o,body:n,method:"POST"}).then(function(t){return r.onMessage(e,t)}).catch(function(){return r.onError(e,n)})}}},{key:"removeFromStack",value:function(e){var t=this.sendStack.indexOf(e);return-1!==t&&(this.sendStack.splice(t,1),!0)}}],n&&On(r.prototype,n),o&&On(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(v);function Mn(e){return Mn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Mn(e)}function Cn(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Fn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Fn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Fn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Fn(f,"constructor",s),Fn(s,"constructor",u),u.displayName="GeneratorFunction",Fn(s,o,"GeneratorFunction"),Fn(f),Fn(f,o,"Generator"),Fn(f,n,function(){return this}),Fn(f,"toString",function(){return"[object Generator]"}),(Cn=function(){return{w:i,m:h}})()}function Fn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Fn=function(e,t,r,n){function i(t,r){Fn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Fn(e,t,r,n)}function Ln(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function xn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Ln(Object(r),!0).forEach(function(t){Gn(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Ln(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Gn(e,t,r){return(t=Bn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Un(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Dn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Un(i,n,o,a,c,"next",e)}function c(e){Un(i,n,o,a,c,"throw",e)}a(void 0)})}}function Nn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Bn(n.key),n)}}function Bn(e){var t=function(e,t){if("object"!=Mn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Mn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Mn(t)?t:t+""}var Wn=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=t},t=[{key:"send",value:(o=Dn(Cn().m(function e(t,r){var n,o,i,a,c,u,s=arguments;return Cn().w(function(e){for(;;)switch(e.n){case 0:return n=s.length>2&&void 0!==s[2]?s[2]:void 0,o=s.length>3&&void 0!==s[3]?s[3]:{},i=this.getUrl(r),a=void 0,n&&(["GET","DELETE"].includes(t)?i+="?"+new URLSearchParams(n).toString():a=JSON.stringify(n)),c=xn(xn({"Content-Type":"application/json",Accept:"application/json"},o),this.getAuthHeaders()),e.n=1,fetch(i,{method:t,body:a,headers:c});case 1:return u=e.v,e.a(2,this.convertFetchResponse(u))}},e,this)})),function(e,t){return o.apply(this,arguments)})},{key:"getAuthHeaders",value:function(){var e={};return this.options.token&&(e.Authorization="Bearer ".concat(this.options.token)),e}},{key:"getUrl",value:function(e){var t;return this.removeEndingSlash(null!==(t=this.options.url)&&void 0!==t?t:this.defaultUrl)+"/"+this.removeStartingSlash(e)}},{key:"convertFetchResponse",value:(n=Dn(Cn().m(function e(t){var r,n,o,i,a;return Cn().w(function(e){for(;;)switch(e.n){case 0:if(n=t.ok,o=t.status,null===(r=t.headers.get("content-type"))||void 0===r||!r.includes("json")){e.n=2;break}return e.n=1,t.json();case 1:i=e.v,e.n=4;break;case 2:return e.n=3,t.text();case 3:i=e.v;case 4:return a=i,e.a(2,{ok:n,status:o,data:a})}},e)})),function(e){return n.apply(this,arguments)})},{key:"removeStartingSlash",value:function(e){return e.replace(/^\/+/,"")}},{key:"removeEndingSlash",value:function(e){return e.replace(/\/+$/,"")}}],t&&Nn(e.prototype,t),r&&Nn(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Jn(e){return Jn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Jn(e)}function Hn(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return $n(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):($n(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,$n(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,$n(f,"constructor",s),$n(s,"constructor",u),u.displayName="GeneratorFunction",$n(s,o,"GeneratorFunction"),$n(f),$n(f,o,"Generator"),$n(f,n,function(){return this}),$n(f,"toString",function(){return"[object Generator]"}),(Hn=function(){return{w:i,m:h}})()}function $n(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}$n=function(e,t,r,n){function i(t,r){$n(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},$n(e,t,r,n)}function Qn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Vn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Qn(Object(r),!0).forEach(function(t){to(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Qn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function zn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function qn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){zn(i,n,o,a,c,"next",e)}function c(e){zn(i,n,o,a,c,"throw",e)}a(void 0)})}}function Kn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,ro(n.key),n)}}function Yn(e,t,r){return t=Zn(t),function(e,t){if(t&&("object"==Jn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Xn()?Reflect.construct(t,r||[],Zn(e).constructor):t.apply(e,r))}function Xn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Xn=function(){return!!e})()}function Zn(e){return Zn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Zn(e)}function eo(e,t){return eo=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},eo(e,t)}function to(e,t,r){return(t=ro(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ro(e){var t=function(e,t){if("object"!=Jn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Jn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Jn(t)?t:t+""}var no=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return to(e=Yn(this,t,[].concat(n)),"defaultUrl","https://files.devana.pl"),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&eo(e,t)}(t,e),r=t,n=[{key:"uploadFile",value:(c=qn(Hn().m(function e(t){var r,n,o,i;return Hn().w(function(e){for(;;)switch(e.n){case 0:return n=encodeURIComponent(null!==(r=t.name)&&void 0!==r?r:""),o=Vn(Vn({},this.getAuthHeaders()),{},{Accept:"application/json","Content-Disposition":'attachment; filename="'.concat(n,'"'),"Content-Length":t.size}),e.n=1,fetch(this.getUrl("files"),{method:"POST",body:t,headers:o});case 1:return i=e.v,e.a(2,this.convertFetchResponse(i))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getFileMeta",value:(a=qn(Hn().m(function e(t){return Hn().w(function(e){for(;;)if(0===e.n)return e.a(2,this.send("GET","files/"+t))},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getFileMetaBulk",value:(i=qn(Hn().m(function e(t){var r;return Hn().w(function(e){for(;;)if(0===e.n)return r=new URLSearchParams,t.forEach(function(e){return r.append("id[]",e)}),e.a(2,this.send("GET","files?"+r))},e,this)})),function(e){return i.apply(this,arguments)})}],n&&Kn(r.prototype,n),o&&Kn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c}(Wn);return t})());
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.PservClient=t():e.PservClient=t()}(this,()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,i(n.key),n)}}function o(e,t,r){return(t=i(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e){var t=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==r(t)?t:t+""}e.r(t),e.d(t,{AbstractRestClient:()=>Mn,FilesClient:()=>Vn,IndexedCollection:()=>L,IndexedObjectCollection:()=>C,Layer:()=>Gt,ObservableIndexedCollection:()=>x,ObservableIndexedObjectCollection:()=>G,PermissionDefinition:()=>Dt,Permissions:()=>Ut,WebApiChatClient:()=>kn,WebSocketChatClient:()=>cn,extractUserFromMember:()=>vt});var a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,"events",new Map),o(this,"onceEvents",new Map)},(t=[{key:"on",value:function(e,t){return this.addHandler(this.events,e,t),this}},{key:"once",value:function(e,t){return this.addHandler(this.onceEvents,e,t),this}},{key:"off",value:function(e,t){var r,n,o=null===(r=this.events.get(e))||void 0===r?void 0:r.indexOf(t);return void 0===o||o<0||null===(n=this.events.get(e))||void 0===n||n.splice(o,1),this}},{key:"emit",value:function(e,t){return this.callHandlers(this.events,e,t),this.callHandlers(this.onceEvents,e,t),this.onceEvents.delete(e),this}},{key:"addHandler",value:function(e,t,r){var n,o=null!==(n=e.get(t))&&void 0!==n?n:[];o.push(r),e.set(t,o)}},{key:"callHandlers",value:function(e,t,r){var n;null===(n=e.get(t))||void 0===n||n.forEach(function(e){return e(r)})}}])&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,d(n.key),n)}}function s(e,t,r){return t=f(t),function(e,t){if(t&&("object"==c(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,l()?Reflect.construct(t,r||[],f(e).constructor):t.apply(e,r))}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function p(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){var t=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==c(t)?t:t+""}var y=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return p(e=s(this,t,[].concat(n)),"awaitingResponse",new Map),p(e,"sentCounter",0),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}(t,e),r=t,n=[{key:"createEnvelope",value:function(e,t){return{type:e,data:t,ref:(++this.sentCounter).toString()}}},{key:"createPromiseFromCommandEnvelope",value:function(e){var t=this;return new Promise(function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return t.awaitingResponse.set(e.ref,n)})}},{key:"handleIncomingEnvelope",value:function(e){if(this.awaitingResponse.has(e.ref)){var t="Error"===e.type;this.awaitingResponse.get(e.ref)[0]({data:t?null:e.data,error:t?e.data:null}),this.awaitingResponse.delete(e.ref)}}},{key:"handleEnvelopeSendError",value:function(e,t){this.awaitingResponse.has(e.ref)&&(this.awaitingResponse.get(e.ref)[1](t),this.awaitingResponse.delete(e.ref))}}],n&&u(r.prototype,n),o&&u(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(a);function m(e){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m(e)}function v(e,t,r){return t=k(t),function(e,t){if(t&&("object"==m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,b()?Reflect.construct(t,r||[],k(e).constructor):t.apply(e,r))}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}function g(e,t,r,n){var o=w(k(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function w(){return w="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=k(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},w.apply(null,arguments)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function S(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&O(e,t)}function O(e,t){return O=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},O(e,t)}function j(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||I(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=I(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function P(e){return function(e){if(Array.isArray(e))return E(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||I(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e,t){if(e){if("string"==typeof e)return E(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,t):void 0}}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function R(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,F(n.key),n)}}function A(e,t,r){return t&&_(e.prototype,t),r&&_(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function M(e,t,r){return(t=F(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(e){var t=function(e,t){if("object"!=m(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=m(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==m(t)?t:t+""}var L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];R(this,e),M(this,"_items",new Map),this.set.apply(this,P(t))}return A(e,[{key:"items",get:function(){return this._items}},{key:"length",get:function(){return this._items.size}},{key:"set",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this._items.set(i[0],i[1])}}},{key:"get",value:function(e){return this.items.get(e)}},{key:"has",value:function(e){return this.items.has(e)}},{key:"delete",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this.items.delete(i)}}},{key:"deleteAll",value:function(){this.items.clear()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0,i=new e,a=T(this.items.entries());try{for(a.s();!(n=a.n()).done;){var c=j(n.value,2),u=c[0],s=c[1];if(i.length>=o)break;s[t]===r&&i.set([u,s])}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e;return t._items=this._items,t}}])}(),C=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];R(this,e),M(this,"_items",void 0),this.id=t,this._items=new L,this.set.apply(this,P(r))}return A(e,[{key:"items",get:function(){return Array.from(this._items.items.values())}},{key:"length",get:function(){return this._items.length}},{key:"set",value:function(){for(var e,t=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this._items).set.apply(e,P(n.map(function(e){return[t.getId(e),e]})))}},{key:"get",value:function(e){return this._items.get(e)}},{key:"getAt",value:function(e){return this.items[e]}},{key:"has",value:function(e){return this._items.has(e)}},{key:"delete",value:function(){var e;(e=this._items).delete.apply(e,arguments)}},{key:"deleteAll",value:function(){this._items.deleteAll()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new e(this.id),a=T(this.items);try{for(a.s();!(n=a.n()).done;){var c=n.value;if(o&&i.length===o)break;c[t]===r&&i.set(c)}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e(this.id);return t._items=this._items,t}},{key:"getId",value:function(e){return"function"==typeof this.id?this.id(e):e[this.id]}}])}(),x=function(e){function t(){var e,r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return R(this,t),M(r=v(this,t),"eventTarget",void 0),r.eventTarget=new a,(e=r).set.apply(e,P(n)),r}return S(t,e),A(t,[{key:"set",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"set",this,3)(r),this.eventTarget.emit("change",{setItems:r.map(function(e){return e[0]})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){if(this.length){var e=Array.from(this._items.keys());g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:Array.from(e)})}}},{key:"createMirror",value:function(){var e=new t;return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(L),G=function(e){function t(e){var r,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return R(this,t),M(n=v(this,t,[e]),"eventTarget",void 0),n.eventTarget=new a,(r=n).set.apply(r,P(o)),n}return S(t,e),A(t,[{key:"set",value:function(){for(var e=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];n.length&&(g(t,"set",this,3)(n),this.eventTarget.emit("change",{setItems:n.map(function(t){return e.getId(t)})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){var e=this;if(this.length){var r=this.items.map(function(t){return e.getId(t)});g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:r})}}},{key:"createMirror",value:function(){var e=new t(this.id);return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(C);function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}function U(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,J(n.key),n)}}function N(e,t,r){return t&&U(e.prototype,t),r&&U(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function B(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function W(e,t,r){return(t=J(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function J(e){var t=function(e,t){if("object"!=D(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==D(t)?t:t+""}var H=N(function e(){var t=this;B(this,e),W(this,"promise",void 0),W(this,"resolve",void 0),this.promise=new Promise(function(e){return t.resolve=e})}),$=function(){return N(function e(){B(this,e),W(this,"promises",new L)},[{key:"register",value:function(e,t){this.promises.set([t,e])}},{key:"registerByFunction",value:function(e,t){this.register(e(),t)}},{key:"get",value:function(e){return this.promises.get(e)}},{key:"has",value:function(e){return this.promises.has(e)}},{key:"notExist",value:function(e){return!this.has(e)}},{key:"forget",value:function(){var e;(e=this.promises).delete.apply(e,arguments)}},{key:"forgetAll",value:function(){this.promises.deleteAll()}}])}();function Q(e){return Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Q(e)}function V(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?V(Object(r),!0).forEach(function(t){fe(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function q(e,t,r,n){var o=K(ue(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function K(){return K="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=ue(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},K.apply(null,arguments)}function Y(e){return function(e){if(Array.isArray(e))return X(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?X(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Z(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ee(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ee(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ee(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ee(f,"constructor",s),ee(s,"constructor",u),u.displayName="GeneratorFunction",ee(s,o,"GeneratorFunction"),ee(f),ee(f,o,"Generator"),ee(f,n,function(){return this}),ee(f,"toString",function(){return"[object Generator]"}),(Z=function(){return{w:i,m:h}})()}function ee(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ee=function(e,t,r,n){function i(t,r){ee(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ee(e,t,r,n)}function te(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function re(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){te(i,n,o,a,c,"next",e)}function c(e){te(i,n,o,a,c,"throw",e)}a(void 0)})}}function ne(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function oe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,he(n.key),n)}}function ie(e,t,r){return t&&oe(e.prototype,t),r&&oe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function ae(e,t,r){return t=ue(t),function(e,t){if(t&&("object"==Q(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ce()?Reflect.construct(t,r||[],ue(e).constructor):t.apply(e,r))}function ce(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ce=function(){return!!e})()}function ue(e){return ue=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ue(e)}function se(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&le(e,t)}function le(e,t){return le=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},le(e,t)}function fe(e,t,r){return(t=he(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e){var t=function(e,t){if("object"!=Q(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Q(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Q(t)?t:t+""}var pe=function(e){return e[e.LIVE=0]="LIVE",e[e.LATEST=1]="LATEST",e[e.PAST=2]="PAST",e[e.OLDEST=3]="OLDEST",e}({}),de=function(e){function t(e,r,n){var o,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return ne(this,t),fe(o=ae(this,t,["id"]),"WindowState",pe),o.roomId=e,o.topicId=r,o.tracker=n,o.internalState.traverseLock=!1,i&&(o.tracker.client.on("NewMessage",function(e){return o.handleNewMessage(e)}),o.tracker.client.on("MessagesRedacted",function(e){return o.handleMessagesRedacted(e)})),o}return se(t,e),ie(t,[{key:"createMirror",value:function(){var e=new t(this.roomId,this.topicId,this.tracker,!1);return e.eventTarget=this.eventTarget,e._items=this._items,e.internalState=this.internalState,e}},{key:"isTraverseLocked",get:function(){return this.internalState.traverseLock}},{key:"setTraverseLock",value:(y=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(this.internalState.traverseLock=r,!r||this.state===pe.LIVE||this.state===pe.LATEST){e.n=1;break}return e.n=1,q(t,"resetToLatest",this,3)([]);case 1:return e.a(2)}},e,this)})),function(e){return y.apply(this,arguments)})},{key:"resetToLatest",value:(d=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"resetToLatest",this,3)([]))}},e,this)})),function(){return d.apply(this,arguments)})},{key:"fetchNext",value:(p=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchNext",this,3)([]))}},e,this)})),function(){return p.apply(this,arguments)})},{key:"fetchPrevious",value:(h=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchPrevious",this,3)([]))}},e,this)})),function(){return h.apply(this,arguments)})},{key:"jumpTo",value:(f=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"jumpTo",this,3)([r]))}},e,this)})),function(e){return f.apply(this,arguments)})},{key:"_updateMessageReference",value:function(e){var t=this.get(e.refMessage.id);t&&this.set(z(z({},t),{},{topicRef:e.id}))}},{key:"fetchItemsAfter",value:(l=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(this.length-1))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},after:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return l.apply(this,arguments)})},{key:"fetchItemsAround",value:(s=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},around:t,limit:this.internalState.fetchLimit});case 1:if(!(r=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(r.error.message));case 2:return e.a(2,r.data.messages)}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"fetchItemsBefore",value:(u=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(0))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},before:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return u.apply(this,arguments)})},{key:"fetchLatestItems",value:(c=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},limit:this.internalState.fetchLimit});case 1:if(!(t=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(t.error.message));case 2:return e.a(2,t.data.messages)}},e,this)})),function(){return c.apply(this,arguments)})},{key:"getTopic",value:(a=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.getTopics(this.roomId,[this.topicId]);case 1:return e.a(2,e.v.get(this.topicId))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"getLatestMessageId",value:(i=re(Z().m(function e(){var t,r,n,o,i;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getTopic();case 1:if(o=t=e.v,n=null===o){e.n=2;break}n=void 0===t;case 2:if(r=n){e.n=3;break}r=null===(t=t.lastMessage)||void 0===t;case 3:if(!r){e.n=4;break}i=void 0,e.n=5;break;case 4:i=t.id;case 5:return e.a(2,i)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"isLatestItemLoaded",value:(o=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getLatestMessageId();case 1:return t=e.v,e.a(2,!t||this.has(t))}},e,this)})),function(){return o.apply(this,arguments)})},{key:"handleNewMessage",value:(n=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:[pe.LATEST,pe.LIVE].includes(this.state)&&t.message.location.roomId===this.roomId&&t.message.location.topicId===this.topicId&&(r=this.state,this.addItems([t.message],"tail"),this.emitChangeWithDiff(!0,r));case 1:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleMessagesRedacted",value:(r=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:if(t.location.topicId===this.topicId&&t.location.roomId===this.roomId){e.n=1;break}return e.a(2);case 1:if(r=this.items.filter(function(e){return e.topicRef&&t.ids.includes(e.id)}).map(function(e){return e.topicRef}),this.delete.apply(this,Y(t.ids)),0!==this.length){e.n=2;break}return e.n=2,this.resetToLatest();case 2:r.length>0&&this.eventTarget.emit("reftopicsdeleted",r);case 3:return e.a(2)}},e,this)})),function(e){return r.apply(this,arguments)})}]);var r,n,o,i,a,c,u,s,l,f,h,p,d,y}(function(e){function t(){var e;ne(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return fe(e=ae(this,t,[].concat(n)),"internalState",{current:pe.LIVE,ongoing:void 0,limit:1e3,retainRatio:1,fetchLimit:50,lastFetchCount:0,oldestId:null}),e}return se(t,e),ie(t,[{key:"state",get:function(){return this.internalState.current}},{key:"fetchLimit",get:function(){return this.internalState.fetchLimit},set:function(e){this.internalState.fetchLimit=e}},{key:"limit",get:function(){return this.internalState.limit},set:function(e){this.internalState.limit=e}},{key:"retainRatio",get:function(){return this.internalState.retainRatio},set:function(e){this.internalState.retainRatio=e}},{key:"hasLatest",get:function(){return[pe.LATEST,pe.LIVE].includes(this.state)}},{key:"hasOldest",get:function(){return this.state===pe.OLDEST||this.state===pe.LATEST&&this.length<this.fetchLimit||null!==this.internalState.oldestId&&this.has(this.internalState.oldestId)}},{key:"resetToLatest",value:(a=re(Z().m(function e(){var t,r;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&this.internalState.current!==pe.LATEST){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.LATEST,e.p=2,e.n=3,this.fetchLatestItems();case 3:t=e.v,this.internalState.lastFetchCount=t.length;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:this._items.deleteAll(),this.addItems(t,"tail"),this.internalState.current=pe.LATEST,this.emitChangeWithDiff(!0,r);case 6:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return a.apply(this,arguments)})},{key:"fetchPrevious",value:(i=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasOldest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsBefore();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=6;break}return e.a(2,this.resetToLatest());case 6:if(t.length){e.n=8;break}return n=this.getAt(0),this.internalState.oldestId=n?this.getId(n):null,e.n=7,this.refreshFetchedState();case 7:return this.internalState.current===pe.PAST&&(this.internalState.current=pe.OLDEST),this.emitChangeWithDiff(!1,r),e.a(2);case 8:return this.addItems(t,"head"),e.n=9,this.refreshFetchedState();case 9:this.emitChangeWithDiff(!0,r);case 10:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return i.apply(this,arguments)})},{key:"fetchNext",value:(o=re(Z().m(function e(){var t,r;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasLatest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsAfter();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=7;break}return e.n=6,this.resetToLatest();case 6:return e.a(2);case 7:if(!t.length){e.n=9;break}return this.addItems(t,"tail"),e.n=8,this.refreshFetchedState();case 8:return this.emitChangeWithDiff(!0,r),e.a(2);case 9:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return o.apply(this,arguments)})},{key:"jumpTo",value:(n=re(Z().m(function e(t){var r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!(this.internalState.ongoing||this.state!==pe.LIVE&&this._items.has(t))){e.n=1;break}return e.a(2);case 1:return n=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsAround(t);case 3:if(r=e.v,this.internalState.lastFetchCount=r?r.length:0,!r){e.n=4;break}return this._items.deleteAll(),this.addItems(r,"tail"),e.n=4,this.refreshFetchedState();case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:this.emitChangeWithDiff(!!r,n);case 6:return e.a(2)}},e,this,[[2,,4,5]])})),function(e){return n.apply(this,arguments)})},{key:"refreshFetchedState",value:(r=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.isLatestItemLoaded();case 1:if(!e.v){e.n=2;break}t=pe.LATEST,e.n=3;break;case 2:t=pe.PAST;case 3:this.internalState.current=t;case 4:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"addItems",value:function(e,t){var r,n,o=this;"head"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(e),Y(this.items)),"tail")),"tail"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(this.items),Y(e)),"head")),this._items.deleteAll(),(r=this._items).set.apply(r,Y(n.map(function(e){return[o.getId(e),e]})))}},{key:"emitChangeWithDiff",value:function(e,t){(e||t!==this.state)&&this.eventTarget.emit("change",{setItems:Array.from(this._items.items.keys())})}},{key:"trimItemsArrayToLimit",value:function(e,t){var r=this.limit;if(null===r||e.length<=r)return e;var n=Math.floor(r*this.internalState.retainRatio);return"head"===t?e.slice(-n):"tail"===t?e.slice(0,n):e}}]);var r,n,o,i,a}(G));function ye(e){return ye="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ye(e)}function me(e){return function(e){if(Array.isArray(e))return ge(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||be(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ve(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||be(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function be(e,t){if(e){if("string"==typeof e)return ge(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ge(e,t):void 0}}function ge(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function we(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ke(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ke(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ke(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ke(f,"constructor",s),ke(s,"constructor",u),u.displayName="GeneratorFunction",ke(s,o,"GeneratorFunction"),ke(f),ke(f,o,"Generator"),ke(f,n,function(){return this}),ke(f,"toString",function(){return"[object Generator]"}),(we=function(){return{w:i,m:h}})()}function ke(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ke=function(e,t,r,n){function i(t,r){ke(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ke(e,t,r,n)}function Se(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Oe(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Se(i,n,o,a,c,"next",e)}function c(e){Se(i,n,o,a,c,"throw",e)}a(void 0)})}}function je(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Pe(n.key),n)}}function Te(e,t,r){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pe(e){var t=function(e,t){if("object"!=ye(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ye(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ye(t)?t:t+""}var Ie=function(){return e=function e(t,r){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Te(this,"historyWindows",new L),Te(this,"traverseLock",!1),this.room=t,this.tracker=r,this.tracker.client.on("RoomUpdated",function(e){return n.handleRoomUpdated(e)}),this.tracker.client.on("NewTopic",function(e){return n.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return n.handleTopicDeleted(e)}),this.updateTraverseLock(this.room),this.room.defaultTopic&&this.createHistoryWindowForTopic(this.room.defaultTopic)},t=[{key:"getMessagesWindow",value:(o=Oe(we().m(function e(t){var r,n,o=arguments;return we().w(function(e){for(;;)switch(e.n){case 0:if(r=o.length>1&&void 0!==o[1]&&o[1],this.historyWindows.has(t)||r){e.n=2;break}return e.n=1,this.tracker.rooms.getTopics(this.room.id,[t]);case 1:(n=e.v.get(t))&&this.createHistoryWindowForTopic(n);case 2:return e.a(2,this.historyWindows.get(t))}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoomUpdated",value:(n=Oe(we().m(function e(t){var r,n,o,i;return we().w(function(e){for(;;)switch(e.n){case 0:if(this.room.id!==t.room.id){e.n=3;break}this.room=t.room,this.updateTraverseLock(t.room),t.room.defaultTopic&&this.createHistoryWindowForTopic(t.room.defaultTopic),r=0,n=Array.from(this.historyWindows.items);case 1:if(!(r<n.length)){e.n=3;break}return o=ve(n[r],2),i=o[1],e.n=2,i.setTraverseLock(this.traverseLock);case 2:r++,e.n=1;break;case 3:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleNewTopic",value:function(e){this.room.id===e.roomId&&this.createHistoryWindowForTopic(e.topic)}},{key:"handleTopicDeleted",value:function(e){this.room.id===e.location.roomId&&this.historyWindows.delete(e.location.topicId)}},{key:"createHistoryWindowForTopic",value:function(e){var t=this;if(!this.historyWindows.has(e.id)){var r=new de(this.room.id,e.id,this.tracker);if(r.setTraverseLock(this.traverseLock),this.historyWindows.set([e.id,r]),r.on("reftopicsdeleted",function(e){var r,n,o=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=be(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}(e);try{for(o.s();!(n=o.n()).done;){var i=n.value;t.historyWindows.delete(i)}}catch(e){o.e(e)}finally{o.f()}(r=t.tracker.rooms)._deleteTopicsFromRoom.apply(r,[t.room.id].concat(me(e)))}),e.refMessage){var n=this.historyWindows.get(e.refMessage.location.topicId);null==n||n._updateMessageReference(e)}}}},{key:"updateTraverseLock",value:function(e){this.traverseLock="Ephemeral"===e.history.mode}}],t&&je(e.prototype,t),r&&je(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Ee(e){return Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ee(e)}function Re(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return _e(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(_e(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,_e(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,_e(f,"constructor",s),_e(s,"constructor",u),u.displayName="GeneratorFunction",_e(s,o,"GeneratorFunction"),_e(f),_e(f,o,"Generator"),_e(f,n,function(){return this}),_e(f,"toString",function(){return"[object Generator]"}),(Re=function(){return{w:i,m:h}})()}function _e(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}_e=function(e,t,r,n){function i(t,r){_e(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},_e(e,t,r,n)}function Ae(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Me(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ae(i,n,o,a,c,"next",e)}function c(e){Ae(i,n,o,a,c,"throw",e)}a(void 0)})}}function Fe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Ce(n.key),n)}}function Le(e,t,r){return(t=Ce(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ce(e){var t=function(e,t){if("object"!=Ee(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ee(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ee(t)?t:t+""}var xe=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Le(this,"roomHistories",new L),Le(this,"deferredSession",new H),this.tracker=t,this.tracker.client.on("Session",function(e){return r.handleSession(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)})},t=[{key:"getRoomHistory",value:(o=Me(Re().m(function e(t){return Re().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roomHistories.get(t))}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"_resolveLastMessage",value:(n=Me(Re().m(function e(t){var r,n,o;return Re().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getRoomHistory(t.roomId).then(function(e){return null==e?void 0:e.getMessagesWindow(t.topicId,!0)}).then(function(e){return(null==e?void 0:e.hasLatest)&&e.getAt(e.length-1)});case 1:if(r=e.v){e.n=3;break}return e.n=2,this.tracker.client.send("GetMessages",{location:t,limit:1});case 2:o=e.v,r=null===(n=o.data)||void 0===n?void 0:n.messages[0];case 3:return e.a(2,r||null)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"createHistoryForNewRoom",value:function(e){this.roomHistories.set([e.id,new Ie(e,this.tracker)])}},{key:"handleRoomDeleted",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleRoomJoin",value:function(e){this.createHistoryForNewRoom(e.room)}},{key:"handleRoomLeft",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleSession",value:function(e){var t=this;this.roomHistories.deleteAll(),e.state.rooms.forEach(function(e){return t.createHistoryForNewRoom(e)}),this.deferredSession.resolve()}}],t&&Fe(e.prototype,t),r&&Fe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Ge(e){return Ge="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ge(e)}function De(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ue(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?De(Object(r),!0).forEach(function(t){Ze(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):De(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Ne(e){return function(e){if(Array.isArray(e))return Je(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||We(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Be(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=We(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function We(e,t){if(e){if("string"==typeof e)return Je(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Je(e,t):void 0}}function Je(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function He(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return $e(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):($e(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,$e(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,$e(f,"constructor",s),$e(s,"constructor",u),u.displayName="GeneratorFunction",$e(s,o,"GeneratorFunction"),$e(f),$e(f,o,"Generator"),$e(f,n,function(){return this}),$e(f,"toString",function(){return"[object Generator]"}),(He=function(){return{w:i,m:h}})()}function $e(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}$e=function(e,t,r,n){function i(t,r){$e(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},$e(e,t,r,n)}function Qe(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Ve(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Qe(i,n,o,a,c,"next",e)}function c(e){Qe(i,n,o,a,c,"throw",e)}a(void 0)})}}function ze(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,et(n.key),n)}}function qe(e,t,r){return t=Ye(t),function(e,t){if(t&&("object"==Ge(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Ke()?Reflect.construct(t,r||[],Ye(e).constructor):t.apply(e,r))}function Ke(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Ke=function(){return!!e})()}function Ye(e){return Ye=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Ye(e)}function Xe(e,t){return Xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Xe(e,t)}function Ze(e,t,r){return(t=et(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function et(e){var t=function(e,t){if("object"!=Ge(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ge(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ge(t)?t:t+""}var tt=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),Ze(r=qe(this,t),"followedTopics",new L),Ze(r,"followedTopicsPromises",new $),Ze(r,"deferredSession",new H),Ze(r,"summariesCache",new Map),r.tracker=e,r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),r.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),r.tracker.client.on("FollowedTopicUpdated",function(e){return r.handleFollowedTopicUpdated(e)}),r.tracker.client.on("TopicFollowed",function(e){return r.handleTopicFollowed(e)}),r.tracker.client.on("TopicUnfollowed",function(e){return r.handleTopicUnfollowed(e)}),r.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Xe(e,t)}(t,e),r=t,n=[{key:"cacheForSpace",value:(l=Ve(He().m(function e(t){var r,n,o,i,a=this;return He().w(function(e){for(;;)switch(e.n){case 0:if(!(i=t)){e.n=2;break}return e.n=1,this.tracker.spaces.get();case 1:i=!e.v.has(t);case 2:if(!i){e.n=3;break}throw new Error("You are not in space ".concat(t));case 3:return e.n=4,this.tracker.rooms.get();case 4:if(r=e.v,(n=t?r.findBy("spaceId",t).items.map(function(e){return e.id}):r.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id})).length){e.n=5;break}return e.a(2);case 5:if(!n.every(function(e){return a.followedTopics.has(e)})){e.n=6;break}return e.a(2);case 6:return o="space_fetch_".concat(t||"spaceless"),this.followedTopicsPromises.notExist(o)&&this.followedTopicsPromises.registerByFunction(Ve(He().m(function e(){var r;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,a.tracker.client.send("GetFollowedTopics",{location:{spaceId:t}});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:a.setFollowedTopicsArray(n,r.data.followedTopics);case 3:return e.a(2)}},e)})),o),e.n=7,this.followedTopicsPromises.get(o);case 7:return e.a(2)}},e,this)})),function(e){return l.apply(this,arguments)})},{key:"getForRoom",value:(s=Ve(He().m(function e(t){var r=this;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:if(e.v.has(t)){e.n=2;break}return e.a(2,void 0);case 2:if(this.followedTopics.has(t)){e.n=3;break}return this.followedTopicsPromises.notExist(t)&&this.followedTopicsPromises.registerByFunction(Ve(He().m(function e(){var n;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetFollowedTopics",{location:{roomId:t}});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.setFollowedTopicsArray([t],n.data.followedTopics);case 3:return e.a(2)}},e)})),t),e.n=3,this.followedTopicsPromises.get(t);case 3:return e.a(2,this.followedTopics.get(t))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"ackRoom",value:(u=Ve(He().m(function e(t){var r,n,o,i,a;return He().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.getForRoom(t);case 1:if(r=e.v){e.n=2;break}return e.a(2);case 2:n=Be(r.items),e.p=3,n.s();case 4:if((o=n.n()).done){e.n=6;break}if(!(i=o.value).isUnread){e.n=5;break}return e.n=5,this.tracker.client.send("Ack",{location:i.location});case 5:e.n=4;break;case 6:e.n=8;break;case 7:e.p=7,a=e.v,n.e(a);case 8:return e.p=8,n.f(),e.f(8);case 9:return e.a(2)}},e,this,[[3,7,8,9]])})),function(e){return u.apply(this,arguments)})},{key:"summarize",value:(c=Ve(He().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b;return He().w(function(e){for(;;)switch(e.p=e.n){case 0:if(r=t.topicId?"topic:".concat(t.roomId,":").concat(t.topicId):t.roomId?"room:".concat(t.roomId):t.spaceId?"space:".concat(t.spaceId):"spaceless",!this.summariesCache.has(r)){e.n=1;break}return e.a(2,this.summariesCache.get(r));case 1:return n=[],e.n=2,this.tracker.rooms.get();case 2:if(i=e.v,!t.topicId){e.n=4;break}if(t.roomId){e.n=3;break}throw new Error("roomId is required when querying by topicId");case 3:n=[t.roomId],o=t.topicId,e.n=9;break;case 4:if(!t.roomId){e.n=5;break}n=[t.roomId],e.n=9;break;case 5:if(!t.spaceId){e.n=7;break}return e.n=6,this.cacheForSpace(t.spaceId);case 6:n=i.findBy("spaceId",t.spaceId).items.map(function(e){return e.id}),e.n=9;break;case 7:return e.n=8,this.cacheForSpace(null);case 8:n=i.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id});case 9:a=0,c=0,u=Be(n),e.p=10,u.s();case 11:if((s=u.n()).done){e.n=22;break}return l=s.value,e.n=12,this.getForRoom(l);case 12:if(f=e.v){e.n=13;break}return e.a(3,21);case 13:h=Be(f.items),e.p=14,h.s();case 15:if((p=h.n()).done){e.n=18;break}if(y=p.value,!o||y.location.topicId===o){e.n=16;break}return e.a(3,17);case 16:y.isUnread&&c++,a+=null!==(d=y.mentionCount)&&void 0!==d?d:0;case 17:e.n=15;break;case 18:e.n=20;break;case 19:e.p=19,v=e.v,h.e(v);case 20:return e.p=20,h.f(),e.f(20);case 21:e.n=11;break;case 22:e.n=24;break;case 23:e.p=23,b=e.v,u.e(b);case 24:return e.p=24,u.f(),e.f(24);case 25:return m={mentionCount:a,unreadTopicCount:c,isUnread:c>0},this.summariesCache.set(r,m),e.a(2,m)}},e,this,[[14,19,20,21],[10,23,24,25]])})),function(e){return c.apply(this,arguments)})},{key:"_deleteByTopicIds",value:function(e){for(var t,r=this,n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];null===(t=this.followedTopics.get(e))||void 0===t||t.delete.apply(t,o),o.forEach(function(t){return r.invalidateUnreadSummaries(e,t)})}},{key:"handleSession",value:function(e){this.followedTopics.deleteAll(),this.followedTopicsPromises.forgetAll(),this.invalidateUnreadSummaries(),this.deferredSession.resolve()}},{key:"handleNewMessage",value:function(e){this.updateLocallyFollowedTopicOnNewMessage(e)}},{key:"handleFollowedTopicUpdated",value:function(e){var t;null===(t=this.followedTopics.get(e.followedTopic.location.roomId))||void 0===t||t.set(e.followedTopic),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleTopicFollowed",value:function(e){this.setFollowedTopicsArray([e.followedTopic.location.roomId],[e.followedTopic]),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleTopicUnfollowed",value:function(e){var t;null===(t=this.followedTopics.get(e.location.roomId))||void 0===t||t.delete(e.location.topicId),this.invalidateUnreadSummaries(e.location.roomId,e.location.topicId)}},{key:"handleRoomDeleted",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleRoomJoin",value:function(e){this.clearRoomFollowedTopicsStructures(e.room.id)}},{key:"handleRoomLeft",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleNewTopic",value:(a=Ve(He().m(function e(t){var r,n;return He().w(function(e){for(;;)switch(e.n){case 0:if(!this.followedTopics.has(t.roomId)){e.n=2;break}return e.n=1,this.tracker.client.send("GetFollowedTopics",{location:{roomId:t.roomId,topicId:t.topic.id}});case 1:r=e.v,(n=r.data.followedTopics[0])&&(this.followedTopics.get(t.roomId).set(n),this.invalidateUnreadSummaries(t.roomId,t.topic.id));case 2:return e.a(2)}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t;null===(t=this.followedTopics.get(e.location.roomId))||void 0===t||t.delete(e.location.topicId),this.invalidateUnreadSummaries(e.location.roomId,e.location.topicId)}},{key:"invalidateUnreadSummaries",value:function(e,t){if(e){if(this.summariesCache.delete("room:".concat(e)),t)this.summariesCache.delete("topic:".concat(e,":").concat(t));else{var r,n=Be(this.summariesCache.keys());try{for(n.s();!(r=n.n()).done;){var o=r.value;o.startsWith("topic:".concat(e,":"))&&this.summariesCache.delete(o)}}catch(e){n.e(e)}finally{n.f()}}var i,a=Be(this.summariesCache.keys());try{for(a.s();!(i=a.n()).done;){var c=i.value;(c.startsWith("space:")||"spaceless"===c)&&this.summariesCache.delete(c)}}catch(e){a.e(e)}finally{a.f()}}else this.summariesCache.clear();this.emit("change")}},{key:"invalidateUnreadSummariesForRooms",value:function(e){var t=this,r=new Set(e);e.forEach(function(e){t.summariesCache.delete("room:".concat(e))});var n,o=Be(this.summariesCache.keys());try{for(o.s();!(n=o.n()).done;){var i=n.value;if(i.startsWith("space:")||"spaceless"===i)this.summariesCache.delete(i);else if(i.startsWith("topic:")){var a=i.split(":");a.length>=2&&r.has(a[1])&&this.summariesCache.delete(i)}}}catch(e){o.e(e)}finally{o.f()}this.emit("change")}},{key:"updateLocallyFollowedTopicOnNewMessage",value:(i=Ve(He().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h;return He().w(function(e){for(;;)switch(e.n){case 0:if(r=this.followedTopics.get(t.message.location.roomId),n=null==r?void 0:r.get(t.message.location.topicId),r&&n&&"Ephemeral"!==t.message.type){e.n=1;break}return e.a(2);case 1:return e.n=2,this.tracker.getMe();case 2:if(o=e.v,t.message.author.user.id!==o.id){e.n=3;break}i={missed:0,lastAckMessageId:t.message.id},e.n=6;break;case 3:if("Text"!==t.message.type){e.n=5;break}return e.n=4,this.tracker.rooms.getMe(t.message.location.roomId);case 4:s=e.v,l=[].concat(Ne(null!==(a=null===(c=s.spaceMember)||void 0===c?void 0:c.roles)&&void 0!==a?a:[]),Ne(null!==(u=s.roles)&&void 0!==u?u:[])),f=[].concat(Ne(l.map(function(e){return"<@&".concat(e,">")})),["<@".concat(o.id,">")]),h=f.some(function(e){return t.message.content.includes(e)}),i={missed:null===n.missed?null:n.missed+1,isUnread:!0,mentionCount:n.mentionCount+(h?1:0)},e.n=6;break;case 5:i={missed:null===n.missed?null:n.missed+1,isUnread:!0};case 6:r.set(Ue(Ue({},n),i)),this.invalidateUnreadSummaries(t.message.location.roomId,t.message.location.topicId);case 7:return e.a(2)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"setFollowedTopicsArray",value:function(e,t){var r=this,n={};t.forEach(function(e){var t,r;null!==(r=n[t=e.location.roomId])&&void 0!==r||(n[t]=[]),n[e.location.roomId].push(e)}),e.forEach(function(e){var t;r.followedTopics.has(e)||r.followedTopics.set([e,new G(function(e){return e.location.topicId})]),n[e]&&(t=r.followedTopics.get(e)).set.apply(t,Ne(n[e]))}),this.invalidateUnreadSummariesForRooms(e)}},{key:"clearRoomFollowedTopicsStructures",value:function(e){this.followedTopics.delete(e),this.followedTopicsPromises.forget(e),this.invalidateUnreadSummaries(e)}}],n&&ze(r.prototype,n),o&&ze(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l}(a);function rt(e){return rt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},rt(e)}function nt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ot(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?nt(Object(r),!0).forEach(function(t){dt(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):nt(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function it(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=ct(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function at(e){return function(e){if(Array.isArray(e))return ut(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||ct(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ct(e,t){if(e){if("string"==typeof e)return ut(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ut(e,t):void 0}}function ut(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function st(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return lt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(lt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,lt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,lt(f,"constructor",s),lt(s,"constructor",u),u.displayName="GeneratorFunction",lt(s,o,"GeneratorFunction"),lt(f),lt(f,o,"Generator"),lt(f,n,function(){return this}),lt(f,"toString",function(){return"[object Generator]"}),(st=function(){return{w:i,m:h}})()}function lt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}lt=function(e,t,r,n){function i(t,r){lt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},lt(e,t,r,n)}function ft(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function ht(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){ft(i,n,o,a,c,"next",e)}function c(e){ft(i,n,o,a,c,"throw",e)}a(void 0)})}}function pt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,yt(n.key),n)}}function dt(e,t,r){return(t=yt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function yt(e){var t=function(e,t){if("object"!=rt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=rt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==rt(t)?t:t+""}var mt=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),dt(this,"messages",void 0),dt(this,"followedTopics",void 0),dt(this,"list",new G("id")),dt(this,"topics",new L),dt(this,"members",new L),dt(this,"deferredSession",new H),dt(this,"membersPromises",new $),dt(this,"topicsPromises",new $),this.tracker=t,this.messages=new xe(t),this.followedTopics=new tt(t),this.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),this.tracker.client.on("MessagesRedacted",function(e){return r.handleMessagesRedacted(e)}),this.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoined(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("TopicUpdated",function(e){return r.handleTopicUpdated(e)}),this.tracker.client.on("RoomMemberJoined",function(e){return r.handleRoomMemberJoined(e)}),this.tracker.client.on("RoomMemberLeft",function(e){return r.handleRoomMemberLeft(e)}),this.tracker.client.on("RoomMembers",function(e){return r.handleRoomMembers(e)}),this.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getMembers",value:(a=ht(st().m(function e(t){var r=this;return st().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(ht(st().m(function e(){var n;return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetRoomMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleRoomMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=ht(st().m(function e(t){var r,n;return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){var t,n;return(null!==(t=null===(n=e.user)||void 0===n?void 0:n.id)&&void 0!==t?t:e.spaceMember.user.id)===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"get",value:function(){var e=ht(st().m(function e(){return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getTopics",value:(o=ht(st().m(function e(t,r){var n,o,i,a,c,u,s,l=this;return st().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:if(null==r||!r.length){e.n=8;break}n=function(e){var r;return!(null!==(r=l.topics.get(t))&&void 0!==r&&r.has(e)||l.topicsPromises.has(t+e))},(o=r.filter(n)).length&&(i=this.tracker.client.send("GetTopics",{roomId:t,topicIds:o}).then(function(e){var t;return null===(t=l.topics.get(e.data.location.roomId))||void 0===t?void 0:t.set.apply(t,at(e.data.topics))}),o.forEach(function(e){return l.topicsPromises.register(i,t+e)})),a=it(r),e.p=2,a.s();case 3:if((c=a.n()).done){e.n=5;break}return u=c.value,e.n=4,this.topicsPromises.get(t+u);case 4:e.n=3;break;case 5:e.n=7;break;case 6:e.p=6,s=e.v,a.e(s);case 7:return e.p=7,a.f(),e.f(7);case 8:return e.a(2,this.topics.get(t))}},e,this,[[2,6,7,8]])})),function(e,t){return o.apply(this,arguments)})},{key:"_deleteTopicsFromRoom",value:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];null===(t=this.topics.get(e))||void 0===t||t.delete.apply(t,n)}},{key:"deleteRoom",value:function(){for(var e,t,r,n,o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];(e=this.list).delete.apply(e,i),(t=this.members).delete.apply(t,i),(r=this.membersPromises).forget.apply(r,i);for(var c=0,u=i;c<u.length;c++){var s,l,f,h=u[c],p=null!==(s=null===(l=this.topics.get(h))||void 0===l?void 0:l.items.map(function(e){return e.id}))&&void 0!==s?s:[];(f=this.followedTopics)._deleteByTopicIds.apply(f,[h].concat(at(p)))}(n=this.topics).delete.apply(n,i)}},{key:"deleteRoomsBySpaceId",value:function(e){this.deleteRoom.apply(this,at(this.list.findBy("spaceId",e).items.map(function(e){return e.id})))}},{key:"handleSpaceMemberUpdated",value:function(e){var t,r=it(this.list.findBy("spaceId",e.spaceId).items);try{for(r.s();!(t=r.n()).done;){var n=t.value,o=this.members.get(n.id);if(o&&o.has(e.userId)){var i=o.get(e.userId),a=e.member;a.user=i.spaceMember.user,o.set(ot(ot({},i),{},{spaceMember:a}))}}}catch(e){r.e(e)}finally{r.f()}}},{key:"handleSpaceMemberLeft",value:function(e){var t=this;this.list.findBy("spaceId",e.spaceId).items.forEach(function(r){var n;return null===(n=t.members.get(r.id))||void 0===n?void 0:n.delete(e.userId)})}},{key:"handleRoomMemberUpdated",value:function(e){var t,r;if(this.members.has(e.roomId)){var n=this.members.get(e.roomId),o=n.get(e.userId),i=e.member,a=null!==(t=null===(r=o.spaceMember)||void 0===r?void 0:r.user)&&void 0!==t?t:o.user;i.spaceMember?i.spaceMember.user=a:i.user=a,n.set(i)}}},{key:"handleSpaceDeleted",value:function(e){this.deleteRoomsBySpaceId(e.id)}},{key:"handleTopicDeleted",value:function(e){var t;this.topics.get(e.location.roomId).delete(e.location.topicId);var r=this.list.get(e.location.roomId);(null===(t=r.defaultTopic)||void 0===t?void 0:t.id)===e.location.topicId&&this.list.set(ot(ot({},r),{},{defaultTopic:null}))}},{key:"handleNewTopic",value:function(e){this.addJoinedRoomTopics(e.roomId,e.topic)}},{key:"addJoinedRoomTopics",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o;this.topics.has(e)?(o=this.topics.get(e)).set.apply(o,r):this.topics.set([e,new G("id",r)])}},{key:"handleRoomJoined",value:function(e){this.addJoinedRooms(e.room)}},{key:"handleRoomUpdated",value:function(e){this.list.has(e.room.id)&&this.list.set(e.room)}},{key:"handleRoomDeleted",value:function(e){this.deleteRoom(e.id)}},{key:"handleTopicUpdated",value:function(e){var t,r=this.list.get(e.location.roomId);if(null!==(t=this.topics.get(e.location.roomId))&&void 0!==t&&t.has(e.topic.id)&&this.topics.get(e.location.roomId).set(e.topic),r.defaultTopic.id===e.topic.id){var n=ot({},r);n.defaultTopic=e.topic,this.list.set(n)}}},{key:"addJoinedRooms",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];for(var o=0,i=r;o<i.length;o++){var a=i[o];a.defaultTopic&&this.addJoinedRoomTopics(a.id,a.defaultTopic),"Pm"===a.type&&a.recipients&&(this.handleRoomMembers({id:a.id,members:a.recipients.map(function(e){return{user:e,spaceMember:null,roles:null,customColor:null,customNick:null,extras:""}})}),this.membersPromises.register(Promise.resolve(),a.id))}(e=this.list).set.apply(e,r)}},{key:"handleRoomLeft",value:function(e){this.deleteRoom(e.id)}},{key:"handleRoomMemberJoined",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).set(e.member)}},{key:"handleRoomMemberLeft",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).delete(e.userId)}},{key:"handleRoomMembers",value:function(e){this.members.has(e.id)||this.members.set([e.id,new G(function(e){var t,r;return null!==(t=null===(r=e.user)||void 0===r?void 0:r.id)&&void 0!==t?t:e.spaceMember.user.id},e.members)])}},{key:"handleSession",value:function(e){this.list.deleteAll(),this.topics.deleteAll(),this.topicsPromises.forgetAll(),this.members.deleteAll(),this.membersPromises.forgetAll(),this.addJoinedRooms.apply(this,at(e.state.rooms)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){var t;this.members.items.forEach(function(t){var r=t.get(e.user.id);if(r){var n=ot({},r);r.user?n.user=e.user:n.spaceMember.user=e.user,t.set(n)}});var r=[];this.list.items.forEach(function(t){var n;null!==(n=t.recipients)&&void 0!==n&&n.some(function(t){return t.id===e.user.id})&&(t.recipients=t.recipients.map(function(t){return t.id===e.user.id?e.user:t}),r.push(ot({},t)))}),(t=this.list).set.apply(t,r)}},{key:"handleNewMessage",value:function(e){var t,r=this.topics.get(e.message.location.roomId),n=null==r?void 0:r.get(e.message.location.topicId);if(n){var o=ot(ot({},n),{},{messageCount:n.messageCount+1,lastMessage:e.message});r.set(o);var i=this.list.get(e.message.location.roomId);(null===(t=i.defaultTopic)||void 0===t?void 0:t.id)===e.message.location.topicId&&this.list.set(ot(ot({},i),{},{defaultTopic:o}))}}},{key:"handleMessagesRedacted",value:(n=ht(st().m(function e(t){var r,n,o,i,a;return st().w(function(e){for(;;)switch(e.n){case 0:if(r=this.topics.get(t.location.roomId),!(n=null==r?void 0:r.get(t.location.topicId))){e.n=4;break}if(!((o=Math.max(n.messageCount-t.ids.length,0))>0)){e.n=2;break}return e.n=1,this.messages._resolveLastMessage(t.location);case 1:a=e.v,e.n=3;break;case 2:a=null;case 3:i=a,r.set(ot(ot({},n),{},{messageCount:o,lastMessage:i}));case 4:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})}],t&&pt(e.prototype,t),r&&pt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a}();function vt(e){var t,r;return null!==(t=e.user)&&void 0!==t?t:null===(r=e.spaceMember)||void 0===r?void 0:r.user}function bt(e){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},bt(e)}function gt(e){return function(e){if(Array.isArray(e))return wt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return wt(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wt(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function kt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function St(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?kt(Object(r),!0).forEach(function(t){Et(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):kt(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Ot(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return jt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(jt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,jt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,jt(f,"constructor",s),jt(s,"constructor",u),u.displayName="GeneratorFunction",jt(s,o,"GeneratorFunction"),jt(f),jt(f,o,"Generator"),jt(f,n,function(){return this}),jt(f,"toString",function(){return"[object Generator]"}),(Ot=function(){return{w:i,m:h}})()}function jt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}jt=function(e,t,r,n){function i(t,r){jt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},jt(e,t,r,n)}function Tt(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Pt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Tt(i,n,o,a,c,"next",e)}function c(e){Tt(i,n,o,a,c,"throw",e)}a(void 0)})}}function It(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Rt(n.key),n)}}function Et(e,t,r){return(t=Rt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Rt(e){var t=function(e,t){if("object"!=bt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==bt(t)?t:t+""}var _t=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Et(this,"list",new G("id")),Et(this,"roles",new L),Et(this,"rooms",new L),Et(this,"roomIdToSpaceId",new L),Et(this,"members",new L),Et(this,"deferredSession",new H),Et(this,"roomsPromises",new $),Et(this,"membersPromises",new $),this.tracker=t,this.tracker.client.on("NewRoom",function(e){return r.handleNewRoom(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceUpdated",function(e){return r.handleSpaceUpdated(e)}),this.tracker.client.on("SpaceJoined",function(e){return r.handleSpaceJoined(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceMemberJoined",function(e){return r.handleSpaceMemberJoined(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMembers",function(e){return r.handleSpaceMembers(e)}),this.tracker.client.on("SpaceRooms",function(e){return r.handleSpaceRooms(e)}),this.tracker.client.on("RoomSummaryUpdated",function(e){return r.handleRoomSummaryUpdated(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("NewRole",function(e){return r.handleNewRole(e)}),this.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),this.tracker.client.on("RoleUpdated",function(e){return r.handleRoleUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"get",value:function(){var e=Pt(Ot().m(function e(){return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getRoles",value:(u=Pt(Ot().m(function e(t){return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roles.get(t))}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"getRooms",value:(c=Pt(Ot().m(function e(t){var r=this;return Ot().w(function(e){for(;;)switch(e.n){case 0:return this.roomsPromises.notExist(t)&&this.roomsPromises.registerByFunction(Pt(Ot().m(function e(){var n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceRooms",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceRooms(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.roomsPromises.get(t);case 1:return e.a(2,this.rooms.get(t))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getMembers",value:(a=Pt(Ot().m(function e(t){var r=this;return Ot().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(Pt(Ot().m(function e(){var n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=Pt(Ot().m(function e(t){var r,n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){return e.user.id===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"handleNewRole",value:function(e){var t=this.roles.get(e.spaceId);t.set(e.role),this.list.get(e.spaceId).roles=t.items}},{key:"handleNewRoom",value:function(e){var t;null===(t=this.rooms.get(e.spaceId))||void 0===t||t.set(e.summary),this.roomIdToSpaceId.set([e.summary.id,e.spaceId])}},{key:"handleRoomUpdated",value:function(e){if(e.room.spaceId&&this.rooms.has(e.room.spaceId)){var t=this.rooms.get(e.room.spaceId);t.set(St(St({},t.get(e.room.id)),{},{name:e.room.name,description:e.room.description}))}}},{key:"handleRoomDeleted",value:(o=Pt(Ot().m(function e(t){var r,n,o,i;return Ot().w(function(e){for(;;)switch(e.n){case 0:if(n=this.roomIdToSpaceId.get(t.id),this.roomIdToSpaceId.delete(t.id),n){e.n=1;break}return e.a(2);case 1:o=this.list.get(n),i=!1,null===(r=this.rooms.get(n))||void 0===r||r.delete(t.id),o.systemRoom===t.id&&(o.systemRoom=null,i=!0),o.defaultRooms.includes(t.id)&&(o.defaultRooms=o.defaultRooms.filter(function(e){return e!==t.id}),i=!0),i&&this.list.set(o);case 2:return e.a(2)}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoleDeleted",value:function(e){var t=this.roles.get(e.spaceId);t.delete(e.id),this.list.get(e.spaceId).roles=t.items}},{key:"handleSpaceUpdated",value:function(e){this.list.set(e.space)}},{key:"handleSpaceDeleted",value:function(e){var t,r,n,o=null!==(t=null===(r=this.rooms.get(e.id))||void 0===r?void 0:r.items.map(function(e){return e.id}))&&void 0!==t?t:[];(n=this.roomIdToSpaceId).delete.apply(n,gt(o)),this.roles.delete(e.id),this.members.delete(e.id),this.membersPromises.forget(e.id),this.rooms.delete(e.id),this.roomsPromises.forget(e.id),this.list.delete(e.id)}},{key:"handleSpaceJoined",value:function(e){this.addJoinedSpaces(e.space)}},{key:"addJoinedSpaces",value:function(){for(var e,t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this.roles).set.apply(e,gt(n.map(function(e){return[e.id,new G("id",e.roles)]}))),(t=this.list).set.apply(t,n)}},{key:"handleSpaceMemberJoined",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).set(e.member)}},{key:"handleSpaceMemberLeft",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).delete(e.userId)}},{key:"handleSpaceMembers",value:function(e){this.members.has(e.id)||this.members.set([e.id,new G(function(e){return null==e?void 0:e.user.id},e.members)])}},{key:"handleSpaceRooms",value:function(e){var t=this;this.rooms.has(e.id)||(this.rooms.set([e.id,new G("id",e.summaries)]),e.summaries.forEach(function(r){return t.roomIdToSpaceId.set([r.id,e.id])}))}},{key:"handleRoomSummaryUpdated",value:(n=Pt(Ot().m(function e(t){var r,n,o,i,a;return Ot().w(function(e){for(;;)switch(e.n){case 0:if(r=this.roomIdToSpaceId.get(t.summary.id),n=this.roomsPromises.get(r),!r||!n){e.n=2;break}return e.n=1,n;case 1:o=this.rooms.get(r),i=o.get(t.summary.id),a=i?St(St({},i),t.summary):t.summary,o.set(a);case 2:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleSpaceMemberUpdated",value:function(e){if(this.members.has(e.spaceId)){var t=this.members.get(e.spaceId),r=t.get(e.userId);t.set(St(St({},e.member),{},{user:r.user}))}}},{key:"handleRoleUpdated",value:function(e){var t,r=this.roles.get(e.spaceId),n=r.get(e.role.id),o=e.role,i=[o];n.priority!==o.priority&&i.push.apply(i,gt(function(e,t,r){var n=r.priority-t.priority>0,o=!n,i=[];return e.forEach(function(e){e.id!==r.id&&(n&&t.priority<=e.priority&&(e.priority--,i.push(e)),o&&r.priority<=e.priority&&(e.priority++,i.push(e)))}),i}(r.items,n,o))),(t=this.roles.get(e.spaceId)).set.apply(t,i)}},{key:"handleSession",value:function(e){this.list.deleteAll(),this.roles.deleteAll(),this.rooms.deleteAll(),this.roomsPromises.forgetAll(),this.members.deleteAll(),this.membersPromises.forgetAll(),this.roomIdToSpaceId.deleteAll(),this.addJoinedSpaces.apply(this,gt(e.state.spaces)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){this.members.items.forEach(function(t){var r=t.get(e.user.id);r&&t.set(St(St({},r),{},{user:e.user}))})}}],t&&It(e.prototype,t),r&&It(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a,c,u}();function At(e){return At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},At(e)}function Mt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,xt(n.key),n)}}function Ft(e,t,r){return t&&Mt(e.prototype,t),r&&Mt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Lt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ct(e,t,r){return(t=xt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function xt(e){var t=function(e,t){if("object"!=At(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=At(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==At(t)?t:t+""}var Gt=function(e){return e[e.Global=0]="Global",e[e.Space=1]="Space",e[e.Room=2]="Room",e[e.Topic=3]="Topic",e}({}),Dt=Ft(function e(){Lt(this,e),Ct(this,"value",void 0),Ct(this,"maxLayer",void 0)}),Ut=function(){return Ft(function e(){Lt(this,e)},null,[{key:"getNames",value:function(){return Object.keys(this.list)}},{key:"getByName",value:function(e){return this.list[e]}},{key:"canBeDefinedOnLayer",value:function(e,t){if(!this.getByName(e))throw new Error("Invalid permission name: ".concat(e));return t<=this.getByName(e).maxLayer}}])}();function Nt(e){return Nt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Nt(e)}function Bt(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Ht(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function Wt(e){return function(e){if(Array.isArray(e))return $t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Ht(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Jt(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||Ht(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ht(e,t){if(e){if("string"==typeof e)return $t(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$t(e,t):void 0}}function $t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Qt(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Vt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Vt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Vt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Vt(f,"constructor",s),Vt(s,"constructor",u),u.displayName="GeneratorFunction",Vt(s,o,"GeneratorFunction"),Vt(f),Vt(f,o,"Generator"),Vt(f,n,function(){return this}),Vt(f,"toString",function(){return"[object Generator]"}),(Qt=function(){return{w:i,m:h}})()}function Vt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Vt=function(e,t,r,n){function i(t,r){Vt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Vt(e,t,r,n)}function zt(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function qt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){zt(i,n,o,a,c,"next",e)}function c(e){zt(i,n,o,a,c,"throw",e)}a(void 0)})}}function Kt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,rr(n.key),n)}}function Yt(e,t,r){return t=Zt(t),function(e,t){if(t&&("object"==Nt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Xt()?Reflect.construct(t,r||[],Zt(e).constructor):t.apply(e,r))}function Xt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Xt=function(){return!!e})()}function Zt(e){return Zt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Zt(e)}function er(e,t){return er=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},er(e,t)}function tr(e,t,r){return(t=rr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function rr(e){var t=function(e,t){if("object"!=Nt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Nt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Nt(t)?t:t+""}Ct(Ut,"list",{Root:{value:1,maxLayer:Gt.Room},CreateSpaces:{value:2,maxLayer:Gt.Global},ManageSpace:{value:4,maxLayer:Gt.Space},ManageRoles:{value:8,maxLayer:Gt.Space},CreateTopics:{value:32,maxLayer:Gt.Room},ManageTopic:{value:64,maxLayer:Gt.Topic},ManageMemberProfiles:{value:128,maxLayer:Gt.Space},ManageMemberRoles:{value:256,maxLayer:Gt.Room},CreateMessages:{value:512,maxLayer:Gt.Topic},ManagePermissions:{value:1024,maxLayer:Gt.Topic},CreateRooms:{value:2048,maxLayer:Gt.Space},ManageRoom:{value:4096,maxLayer:Gt.Room},CreateEmoticons:{value:8192,maxLayer:Gt.Space},ManageEmoticons:{value:16384,maxLayer:Gt.Space},ManageBans:{value:32768,maxLayer:Gt.Room},Kick:{value:65536,maxLayer:Gt.Room},ChangeOwnNick:{value:1<<17,maxLayer:Gt.Space},ChangeOwnColor:{value:1<<18,maxLayer:Gt.Room},RedactMessages:{value:1<<19,maxLayer:Gt.Topic}});var nr=function(e,t){return[e.spaceId,e.roomId,e.topicId,null==t?void 0:t.type,null==t?void 0:t.userId,null==t?void 0:t.roleId].filter(Boolean).join("/")},or=function(e){return nr(e.location,e.target)},ir=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),tr(r=Yt(this,t),"overwrites",new L),tr(r,"overwritesPromises",new $),r.tracker=e,r.tracker.client.on("PermissionOverwrites",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("PermissionOverwritesUpdated",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),r.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),r.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&er(e,t)}(t,e),r=t,n=[{key:"getOverwrites",value:(f=qt(Qt().m(function e(t,r){var n,o=this;return Qt().w(function(e){for(;;)switch(e.n){case 0:return this.validateLocation(t),n=nr(t,r),this.overwritesPromises.notExist(n)&&this.overwritesPromises.registerByFunction(qt(Qt().m(function e(){var n;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.tracker.client.send("GetPermissionOverwrites",{location:t,target:r});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:o.handlePermissionOverwrites(n.data);case 3:return e.a(2)}},e)})),n),e.n=1,this.overwritesPromises.get(n);case 1:return e.a(2,this.overwrites.get(n))}},e,this)})),function(e,t){return f.apply(this,arguments)})},{key:"check",value:(l=qt(Qt().m(function e(t,r){var n,o;return Qt().w(function(e){for(;;)switch(e.n){case 0:if(t.length){e.n=1;break}throw new Error("Permission names array cannot be empty");case 1:return e.n=2,this.calculatePermissions(r);case 2:return n=e.v,o=[],t.forEach(function(e){~n&Ut.getByName(e).value&&o.push(e)}),e.a(2,{ok:0===o.length,hasAll:0===o.length,hasAny:o.length<t.length,missing:o})}},e,this)})),function(e,t){return l.apply(this,arguments)})},{key:"calculatePermissions",value:(s=qt(Qt().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b,g,w,k,S,O,j,T,P;return Qt().w(function(e){for(;;)switch(e.n){case 0:if(!t.roomId){e.n=2;break}return e.n=1,this.tracker.rooms.get();case 1:v=e.v.get(t.roomId),e.n=3;break;case 2:v=null;case 3:return c=v,t={spaceId:null!==(r=t.spaceId)&&void 0!==r?r:null==c?void 0:c.spaceId,roomId:t.roomId,topicId:t.topicId},this.validateLocation(t),e.n=4,this.tracker.getMe();case 4:return u=e.v.id,e.n=5,this.fetchMembersOrFail(t);case 5:if(s=e.v,l=Jt(s,2),f=l[0],h=l[1],p=[].concat(Wt(null!==(n=null==f?void 0:f.roles)&&void 0!==n?n:[]),Wt(null!==(o=null==h?void 0:h.roles)&&void 0!==o?o:[])),d=[this.getOverwrites({},{type:"User",userId:u}).then(function(e){return e.overwrites})],!(b=t.spaceId)){e.n=9;break}return e.n=6,this.tracker.spaces.get();case 6:if(k=i=e.v,!(w=null!==k)){e.n=7;break}w=void 0!==i;case 7:if(!(g=w)){e.n=8;break}g=i.has(t.spaceId);case 8:b=g;case 9:if(!b){e.n=10;break}y={spaceId:t.spaceId},d.push(this.collectRoleOverwrites(y,p)),d.push(this.getOverwrites(y,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 10:if(c&&(m={spaceId:t.spaceId,roomId:t.roomId},p.length&&d.push(this.collectRoleOverwrites(m,p)),d.push(this.getOverwrites(m,{type:"User",userId:u}).then(function(e){return e.overwrites}))),!(S=t.topicId)){e.n=14;break}return e.n=11,this.tracker.rooms.getTopics(t.roomId);case 11:if(T=a=e.v,!(j=null!==T)){e.n=12;break}j=void 0!==a;case 12:if(!(O=j)){e.n=13;break}O=a.has(t.topicId);case 13:S=O;case 14:if(!S){e.n=15;break}p.length&&d.push(this.collectRoleOverwrites(t,p)),d.push(this.getOverwrites(t,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 15:return P=this,e.n=16,Promise.all(d);case 16:return e.a(2,P.resolveOverwritesHierarchy.call(P,e.v))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"handlePermissionOverwrites",value:function(e){this.overwrites.set([or(e),e]),this.emit("change")}},{key:"handleSpaceDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr({spaceId:e.id}));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleRoomDeleted",value:(u=qt(Qt().m(function e(t){var r,n,o;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:(r=e.v.get(t.id))&&(o=this.deleteOverwritesByIdPrefix(nr({spaceId:r.spaceId,roomId:r.id})),(n=this.overwritesPromises).forget.apply(n,Wt(o)));case 2:return e.a(2)}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr(e.location));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleRoleDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr({spaceId:e.spaceId},{type:"Role",roleId:e.id}));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleSpaceMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"handleRoomMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"deleteOverwritesByIdPrefix",value:function(e){var t=this,r=[];return this.overwrites.items.forEach(function(n){var o=or(n);o.startsWith(e)&&(r.push(o),t.overwrites.delete(o))}),r}},{key:"collectRoleOverwrites",value:(c=qt(Qt().m(function e(t,r){var n,o=this;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all(r.map(function(e){return o.getOverwrites(t,{type:"Role",roleId:e})}));case 1:return n=e.v,e.a(2,this.resolveOverwritesFromRolesByOrder(t.spaceId,n))}},e,this)})),function(e,t){return c.apply(this,arguments)})},{key:"resolveOverwritesFromRolesByOrder",value:(a=qt(Qt().m(function e(t,r){var n,o,i,a,c;return Qt().w(function(e){for(;;)switch(e.n){case 0:return n=0,o=0,e.n=1,this.tracker.spaces.getRoles(t);case 1:return i=e.v,a=r.sort(function(e,t){return i.get(e.target.roleId).priority-i.get(t.target.roleId).priority}),c=r.reduce(function(e,t){var r,n,o,i;return Math.max(e,null!==(r=null===(n=t.overwrites.allow)||void 0===n?void 0:n.toString(2).length)&&void 0!==r?r:0,null!==(o=null===(i=t.overwrites.deny)||void 0===i?void 0:i.toString(2).length)&&void 0!==o?o:0)},0),a.forEach(function(e){for(var t,r,i,a,u=e.overwrites,s=null!==(t=null===(r=u.deny)||void 0===r?void 0:r.toString(2).split("").reverse().join(""))&&void 0!==t?t:"",l=null!==(i=null===(a=u.allow)||void 0===a?void 0:a.toString(2).split("").reverse().join(""))&&void 0!==i?i:"",f=0;f<c;f++){var h,p,d=parseInt(null!==(h=s[f])&&void 0!==h?h:"0"),y=parseInt(null!==(p=l[f])&&void 0!==p?p:"0");d&&(o|=1<<f),y&&(n|=1<<f)}}),e.a(2,{allow:n,deny:o})}},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"resolveOverwritesHierarchy",value:function(e){var t,r=0,n=Bt(e);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(o.allow&Ut.getByName("Root").value)return this.getRootAccessValue();r=r&~o.deny|o.allow}}catch(e){n.e(e)}finally{n.f()}return r}},{key:"getRootAccessValue",value:function(){var e,t=0,r=Bt(Ut.getNames());try{for(r.s();!(e=r.n()).done;){var n=e.value;t|=Ut.getByName(n).value}}catch(e){r.e(e)}finally{r.f()}return t}},{key:"fetchMembersOrFail",value:(i=qt(Qt().m(function e(t){var r,n,o,i;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all([t.spaceId?this.tracker.spaces.getMe(t.spaceId):null,t.roomId?this.tracker.rooms.getMe(t.roomId):null]);case 1:if(r=e.v,n=t.spaceId&&!r[0],o=t.roomId&&!r[1],!n&&!o){e.n=2;break}throw i=n?"space (".concat(t.spaceId,")"):"room (".concat(t.roomId,")"),new Error("Attempting to calculate permissions for a ".concat(i," that the user does not belong to"));case 2:return e.a(2,r)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"validateLocation",value:function(e){if(e.topicId&&!e.roomId)throw new Error("Corrupted arguments hierarchy")}},{key:"handleSession",value:function(e){this.overwrites.deleteAll(),this.overwritesPromises.forgetAll()}}],n&&Kt(r.prototype,n),o&&Kt(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l,f}(a);function ar(e){return ar="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ar(e)}function cr(e){return function(e){if(Array.isArray(e))return ur(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return ur(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ur(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ur(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function sr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return lr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(lr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,lr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,lr(f,"constructor",s),lr(s,"constructor",u),u.displayName="GeneratorFunction",lr(s,o,"GeneratorFunction"),lr(f),lr(f,o,"Generator"),lr(f,n,function(){return this}),lr(f,"toString",function(){return"[object Generator]"}),(sr=function(){return{w:i,m:h}})()}function lr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}lr=function(e,t,r,n){function i(t,r){lr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},lr(e,t,r,n)}function fr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function hr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){fr(i,n,o,a,c,"next",e)}function c(e){fr(i,n,o,a,c,"throw",e)}a(void 0)})}}function pr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,yr(n.key),n)}}function dr(e,t,r){return(t=yr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function yr(e){var t=function(e,t){if("object"!=ar(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ar(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ar(t)?t:t+""}var mr="global",vr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),dr(this,"list",new L),dr(this,"emoticonsPromises",new $),this.tracker=t,this.tracker.client.on("Emoticons",function(e){return r.handleEmoticons(e)}),this.tracker.client.on("NewEmoticon",function(e){return r.handleNewEmoticon(e)}),this.tracker.client.on("EmoticonDeleted",function(e){return r.handleEmoticonDeleted(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=hr(sr().m(function e(t){var r,n=this;return sr().w(function(e){for(;;)switch(e.n){case 0:return r=null!=t?t:mr,this.emoticonsPromises.notExist(r)&&this.emoticonsPromises.registerByFunction(hr(sr().m(function e(){var r;return sr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,n.tracker.client.send("GetEmoticons",{spaceId:t});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:n.handleEmoticons(r.data);case 3:return e.a(2)}},e)})),r),e.n=1,this.emoticonsPromises.get(r);case 1:return e.a(2,this.list.get(r))}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"handleEmoticons",value:function(e){var t,r=null!==(t=e.location.spaceId)&&void 0!==t?t:mr;this.list.has(r)||this.list.set([r,new G("id")]);var n=this.list.get(r);n.set.apply(n,cr(e.emoticons))}},{key:"handleNewEmoticon",value:function(e){var t,r=this.list.get(null!==(t=e.emoticon.spaceId)&&void 0!==t?t:mr);null==r||r.set(e.emoticon)}},{key:"handleEmoticonDeleted",value:function(e){var t,r=this.list.get(null!==(t=e.spaceId)&&void 0!==t?t:mr);null==r||r.delete(e.emoticonId)}},{key:"handleSpaceDeleted",value:function(e){this.list.delete(e.id)}},{key:"handleSession",value:function(){this.list.deleteAll(),this.emoticonsPromises.forgetAll()}}],t&&pr(e.prototype,t),r&&pr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function br(e){return br="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},br(e)}function gr(e){return function(e){if(Array.isArray(e))return wr(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return wr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wr(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function kr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Sr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Sr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Sr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Sr(f,"constructor",s),Sr(s,"constructor",u),u.displayName="GeneratorFunction",Sr(s,o,"GeneratorFunction"),Sr(f),Sr(f,o,"Generator"),Sr(f,n,function(){return this}),Sr(f,"toString",function(){return"[object Generator]"}),(kr=function(){return{w:i,m:h}})()}function Sr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Sr=function(e,t,r,n){function i(t,r){Sr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Sr(e,t,r,n)}function Or(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Pr(n.key),n)}}function Tr(e,t,r){return(t=Pr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pr(e){var t=function(e,t){if("object"!=br(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=br(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==br(t)?t:t+""}var Ir=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Tr(this,"onlineStatus",new a),Tr(this,"users",new G("id")),this.tracker=t,t.client.on("UserUpdated",function(e){return r.handleUsers([e.user])}),t.client.on("RoomMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMembers",function(e){return r.handleMembers(e.members)}),t.client.on("RoomMembers",function(e){return r.handleMembers(e.members)}),t.client.on("Messages",function(e){return r.handleUsers(e.messages.map(function(e){return e.author.user}))}),t.client.on("NewMessage",function(e){return r.handleUsers([e.message.author.user])}),t.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getAvailable",value:(n=kr().m(function e(){return kr().w(function(e){for(;;)if(0===e.n)return e.a(2,this.users)},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Or(i,r,o,a,c,"next",e)}function c(e){Or(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleMembers",value:function(e){this.handleUsers(e.map(vt))}},{key:"handleSession",value:function(e){this.users.deleteAll(),this.handleUsers([e.user])}},{key:"handleUsers",value:function(e){var t,r=this;e.forEach(function(e){var t=r.users.get(e.id);t&&t.online!==e.online&&r.onlineStatus.emit("change",e)}),(t=this.users).set.apply(t,gr(e))}}],t&&jr(e.prototype,t),r&&jr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Er(e){return Er="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Er(e)}function Rr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return _r(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(_r(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,_r(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,_r(f,"constructor",s),_r(s,"constructor",u),u.displayName="GeneratorFunction",_r(s,o,"GeneratorFunction"),_r(f),_r(f,o,"Generator"),_r(f,n,function(){return this}),_r(f,"toString",function(){return"[object Generator]"}),(Rr=function(){return{w:i,m:h}})()}function _r(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}_r=function(e,t,r,n){function i(t,r){_r(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},_r(e,t,r,n)}function Ar(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Mr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ar(i,n,o,a,c,"next",e)}function c(e){Ar(i,n,o,a,c,"throw",e)}a(void 0)})}}function Fr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Cr(n.key),n)}}function Lr(e,t,r){return(t=Cr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Cr(e){var t=function(e,t){if("object"!=Er(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Er(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Er(t)?t:t+""}var xr=function(e,t){return"".concat(e,"-").concat(t)},Gr=function(e){return xr(e.refUser.id,e.type)},Dr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Lr(this,"relationships",new G(Gr)),Lr(this,"promises",new $),this.tracker=t,this.tracker.client.on("Relationships",function(e){return r.handleRelationships(e)}),this.tracker.client.on("NewRelationship",function(e){return r.handleNewRelationship(e)}),this.tracker.client.on("RelationshipDeleted",function(e){return r.handleRelationshipDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=Mr(Rr().m(function e(){var t=this;return Rr().w(function(e){for(;;)switch(e.n){case 0:return this.promises.notExist("all")&&this.promises.registerByFunction(Mr(Rr().m(function e(){var r;return Rr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,t.tracker.client.send("GetRelationships",{});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:return e.a(2)}},e)})),"all"),e.n=1,this.promises.get("all");case 1:return e.a(2,this.relationships)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"exists",value:(n=Mr(Rr().m(function e(t,r){return Rr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.get();case 1:return e.a(2,this.relationships.has(xr(t,r)))}},e,this)})),function(e,t){return n.apply(this,arguments)})},{key:"handleRelationships",value:function(e){var t=this;this.relationships.deleteAll(),e.relationships.forEach(function(e){t.relationships.set(e)})}},{key:"handleNewRelationship",value:function(e){this.promises.has("all")&&this.relationships.set(e.relationship)}},{key:"handleRelationshipDeleted",value:function(e){this.promises.has("all")&&this.relationships.delete(Gr(e.relationship))}},{key:"handleSession",value:function(){this.promises.forgetAll(),this.relationships.deleteAll()}}],t&&Fr(e.prototype,t),r&&Fr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n}();function Ur(e){return Ur="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ur(e)}function Nr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Br(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Br(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Br(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Br(f,"constructor",s),Br(s,"constructor",u),u.displayName="GeneratorFunction",Br(s,o,"GeneratorFunction"),Br(f),Br(f,o,"Generator"),Br(f,n,function(){return this}),Br(f,"toString",function(){return"[object Generator]"}),(Nr=function(){return{w:i,m:h}})()}function Br(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Br=function(e,t,r,n){function i(t,r){Br(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Br(e,t,r,n)}function Wr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,$r(n.key),n)}}function Hr(e,t,r){return(t=$r(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function $r(e){var t=function(e,t){if("object"!=Ur(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ur(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ur(t)?t:t+""}var Qr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Hr(this,"client",void 0),Hr(this,"permissions",void 0),Hr(this,"rooms",void 0),Hr(this,"spaces",void 0),Hr(this,"emoticons",void 0),Hr(this,"users",void 0),Hr(this,"relationships",void 0),Hr(this,"_me",null),Hr(this,"deferredSession",new H),this.client=t,this.client.on("Session",function(e){return r.handleSession(e)}),this.permissions=new ir(this),this.rooms=new mt(this),this.spaces=new _t(this),this.emoticons=new vr(this),this.users=new Ir(this),this.relationships=new Dr(this)},t=[{key:"me",get:function(){return this._me}},{key:"getMe",value:(n=Nr().m(function e(){return Nr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this._me)}},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Wr(i,r,o,a,c,"next",e)}function c(e){Wr(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleSession",value:function(e){this._me=e.user,this.deferredSession.resolve()}}],t&&Jr(e.prototype,t),r&&Jr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Vr(e){return Vr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Vr(e)}function zr(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return qr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(qr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,qr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,qr(f,"constructor",s),qr(s,"constructor",u),u.displayName="GeneratorFunction",qr(s,o,"GeneratorFunction"),qr(f),qr(f,o,"Generator"),qr(f,n,function(){return this}),qr(f,"toString",function(){return"[object Generator]"}),(zr=function(){return{w:i,m:h}})()}function qr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}qr=function(e,t,r,n){function i(t,r){qr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},qr(e,t,r,n)}function Kr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Yr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Kr(i,n,o,a,c,"next",e)}function c(e){Kr(i,n,o,a,c,"throw",e)}a(void 0)})}}function Xr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,on(n.key),n)}}function Zr(e,t,r){return t=tn(t),function(e,t){if(t&&("object"==Vr(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,en()?Reflect.construct(t,r||[],tn(e).constructor):t.apply(e,r))}function en(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(en=function(){return!!e})()}function tn(e){return tn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},tn(e)}function rn(e,t){return rn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},rn(e,t)}function nn(e,t,r){return(t=on(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function on(e){var t=function(e,t){if("object"!=Vr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Vr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Vr(t)?t:t+""}var an=function(e){return e.connect="connect",e.disconnect="disconnect",e.message="message",e.error="error",e}(an||{}),cn=function(e){function t(e){var r,n,o,i,a,c,u,s,l;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),nn(l=Zr(this,t),"Event",an),nn(l,"state",void 0),nn(l,"ws",null),nn(l,"sendQueue",[]),nn(l,"connectingTimeoutId",void 0),nn(l,"authenticated",void 0),nn(l,"authenticatedResolvers",void 0),nn(l,"pingMonitorInterval",void 0),nn(l,"inFlightPingTimeout",void 0),nn(l,"lastReceivedMessageAt",void 0),l.options=e,(null===(r=l.options.stateTracking)||void 0===r||r)&&(l.state=new Qr(l)),null!==(n=e.ping)&&void 0!==n||(e.ping={}),null!==(i=(o=e.ping).enabled)&&void 0!==i||(o.enabled=!0),null!==(c=(a=e.ping).noActivityTimeoutMs)&&void 0!==c||(a.noActivityTimeoutMs=15e3),null!==(s=(u=e.ping).pongBackTimeoutMs)&&void 0!==s||(u.pongBackTimeoutMs=5e3),l}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&rn(e,t)}(t,e),r=t,n=[{key:"connect",value:(a=Yr(zr().m(function e(){var t,r,n,o=this;return zr().w(function(e){for(;;)switch(e.n){case 0:if(!this.isOpenWsState()&&!this.isConnectingWsState()){e.n=1;break}return e.a(2);case 1:return(n=new URLSearchParams(null!==(t=this.options.queryParams)&&void 0!==t?t:{})).set("token",this.options.token),this.ws=new WebSocket("".concat(this.options.url,"?").concat(n)),this.ws.onclose=function(e){return o.onClose(e)},this.ws.onmessage=function(e){return o.onMessage(e)},this.connectingTimeoutId=setTimeout(function(){return o.triggerConnectionTimeout()},null!==(r=this.options.connectingTimeoutMs)&&void 0!==r?r:1e4),this.authenticated=!1,e.a(2,new Promise(function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return o.authenticatedResolvers=t}))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"disconnect",value:function(){var e;this.sendQueue=[],null===(e=this.ws)||void 0===e||e.close(1e3),this.ws=null}},{key:"send",value:(i=Yr(zr().m(function e(t,r){var n,o;return zr().w(function(e){for(;;)switch(e.n){case 0:if(n=this.createEnvelope(t,r),o=this.createPromiseFromCommandEnvelope(n),!(this.isConnectingWsState()||!this.authenticated&&this.isOpenWsState())){e.n=1;break}return this.sendQueue.push(n),e.a(2,o);case 1:return this.sendEnvelope(n),e.a(2,o)}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"isReady",get:function(){return this.isOpenWsState()&&this.authenticated}},{key:"sendEnvelope",value:function(e){var t,r;this.isReady?this.ws.send(JSON.stringify(e)):this.handleEnvelopeSendError(e,new Error("Cannot send - client is not ready (state=".concat(null!==(t=null===(r=this.ws)||void 0===r?void 0:r.readyState)&&void 0!==t?t:"[no connection]","; authenticated=").concat(this.authenticated,")")))}},{key:"onMessage",value:function(e){this.lastReceivedMessageAt=Date.now();var t=JSON.parse(e.data);if(this.handleIncomingEnvelope(t),this.emit(t.type,t.data),this.emit(this.Event.message,t),!this.authenticated){var r="Bye"!==t.type;this.authenticated=r,r?(this.startConnectionMonitor(),this.authenticatedResolvers[0](),this.emit(this.Event.connect),this.sendFromQueue()):this.authenticatedResolvers[1](t.data)}}},{key:"onClose",value:function(e){this.stopConnectionMonitor(),clearTimeout(this.connectingTimeoutId);var t=1e3!==e.code;t&&this.connect(),this.emit(this.Event.disconnect,t)}},{key:"sendFromQueue",value:function(){var e=this,t=0,r=function(){var r,o=e.sendQueue[n];setTimeout(function(){return e.sendEnvelope(o)},t),t+=null!==(r=e.options.awaitQueueSendDelayMs)&&void 0!==r?r:500};for(var n in this.sendQueue)r();this.sendQueue=[],clearTimeout(this.connectingTimeoutId)}},{key:"triggerConnectionTimeout",value:function(){this.disconnect(),this.emit(this.Event.error,new Error("Connection timeout"))}},{key:"isConnectingWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.CONNECTING}},{key:"isOpenWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.OPEN}},{key:"startConnectionMonitor",value:function(){var e=this;this.options.ping.enabled&&(this.lastReceivedMessageAt=Date.now(),this.pingMonitorInterval=setInterval(Yr(zr().m(function t(){return zr().w(function(t){for(;;)switch(t.n){case 0:if(e.isReady&&!e.inFlightPingTimeout){t.n=1;break}return t.a(2);case 1:if(!(Date.now()-e.lastReceivedMessageAt<e.options.ping.noActivityTimeoutMs)){t.n=2;break}return t.a(2);case 2:e.inFlightPingTimeout=setTimeout(function(){e.inFlightPingTimeout=void 0,e.ws.close(3e3)},e.options.ping.pongBackTimeoutMs),e.send("Ping",{}).then(function(){clearTimeout(e.inFlightPingTimeout),e.inFlightPingTimeout=void 0});case 3:return t.a(2)}},t)})),1e3))}},{key:"stopConnectionMonitor",value:function(){this.inFlightPingTimeout&&(clearTimeout(this.inFlightPingTimeout),this.inFlightPingTimeout=void 0),this.pingMonitorInterval&&(clearInterval(this.pingMonitorInterval),this.pingMonitorInterval=void 0)}}],n&&Xr(r.prototype,n),o&&Xr(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function un(e){return un="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},un(e)}function sn(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ln(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ln(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ln(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ln(f,"constructor",s),ln(s,"constructor",u),u.displayName="GeneratorFunction",ln(s,o,"GeneratorFunction"),ln(f),ln(f,o,"Generator"),ln(f,n,function(){return this}),ln(f,"toString",function(){return"[object Generator]"}),(sn=function(){return{w:i,m:h}})()}function ln(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ln=function(e,t,r,n){function i(t,r){ln(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ln(e,t,r,n)}function fn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function hn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){fn(i,n,o,a,c,"next",e)}function c(e){fn(i,n,o,a,c,"throw",e)}a(void 0)})}}function pn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,gn(n.key),n)}}function dn(e,t,r){return t=mn(t),function(e,t){if(t&&("object"==un(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,yn()?Reflect.construct(t,r||[],mn(e).constructor):t.apply(e,r))}function yn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(yn=function(){return!!e})()}function mn(e){return mn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},mn(e)}function vn(e,t){return vn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},vn(e,t)}function bn(e,t,r){return(t=gn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function gn(e){var t=function(e,t){if("object"!=un(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=un(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==un(t)?t:t+""}var wn=function(e){return e.message="message",e.error="error",e.destroy="destroy",e}(wn||{}),kn=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),bn(r=dn(this,t),"Event",wn),bn(r,"sendStack",[]),r.options=e,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&vn(e,t)}(t,e),r=t,n=[{key:"send",value:(a=hn(sn().m(function e(t,r){var n,o;return sn().w(function(e){for(;;)if(0===e.n)return n=this.createEnvelope(t,r),o={data:n,attempts:0,lastTimeoutId:null},this.sendStack.push(o),this.makeApiCall(o),e.a(2,this.createPromiseFromCommandEnvelope(n))},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"destroy",value:function(){var e=this,t=this.sendStack;this.sendStack=[],t.forEach(function(t){t.lastTimeoutId&&clearTimeout(t.lastTimeoutId),e.handleEnvelopeSendError(t.data,new Error("Client destroyed"))}),this.emit(this.Event.destroy,!1)}},{key:"onMessage",value:(i=hn(sn().m(function e(t,r){var n;return sn().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,r.json();case 1:n=e.v,e.n=3;break;case 2:return e.p=2,e.v,this.onError(t,"envelope ".concat(t.data.ref," (HTTP ").concat(r.status,", unparsable body)")),e.a(2);case 3:if(this.removeFromStack(t)){e.n=4;break}return e.a(2);case 4:this.handleIncomingEnvelope(n),this.emit(n.type,n.data),this.emit(this.Event.message,n);case 5:return e.a(2)}},e,this,[[0,2]])})),function(e,t){return i.apply(this,arguments)})},{key:"onError",value:function(e,t){var r,n,o=this;if(this.sendStack.includes(e))return e.attempts>=(null!==(r=this.options.attemptsToSend)&&void 0!==r?r:10)?(this.removeFromStack(e),void this.handleEnvelopeSendError(e.data,new Error("Cannot send ".concat(t,"; aborting after reaching the maximum connection errors")))):void(e.lastTimeoutId=setTimeout(function(){return o.makeApiCall(e)},null!==(n=this.options.attemptDelayMs)&&void 0!==n?n:3e3))}},{key:"makeApiCall",value:function(e){var t,r=this;if(this.sendStack.includes(e)){e.attempts++,e.lastTimeoutId=null;var n=JSON.stringify(e.data),o={"Content-Type":"application/json",Accept:"application/json"};o.Authorization="Bearer ".concat(this.options.token);var i=new URLSearchParams(null!==(t=this.options.queryParams)&&void 0!==t?t:{}).toString(),a=i?"".concat(this.options.url,"?").concat(i):this.options.url;fetch(a,{headers:o,body:n,method:"POST"}).then(function(t){return r.onMessage(e,t)}).catch(function(){return r.onError(e,n)})}}},{key:"removeFromStack",value:function(e){var t=this.sendStack.indexOf(e);return-1!==t&&(this.sendStack.splice(t,1),!0)}}],n&&pn(r.prototype,n),o&&pn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function Sn(e){return Sn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Sn(e)}function On(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return jn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(jn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,jn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,jn(f,"constructor",s),jn(s,"constructor",u),u.displayName="GeneratorFunction",jn(s,o,"GeneratorFunction"),jn(f),jn(f,o,"Generator"),jn(f,n,function(){return this}),jn(f,"toString",function(){return"[object Generator]"}),(On=function(){return{w:i,m:h}})()}function jn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}jn=function(e,t,r,n){function i(t,r){jn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},jn(e,t,r,n)}function Tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Pn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Tn(Object(r),!0).forEach(function(t){In(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Tn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function In(e,t,r){return(t=An(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function En(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Rn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){En(i,n,o,a,c,"next",e)}function c(e){En(i,n,o,a,c,"throw",e)}a(void 0)})}}function _n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,An(n.key),n)}}function An(e){var t=function(e,t){if("object"!=Sn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Sn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Sn(t)?t:t+""}var Mn=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=t},t=[{key:"send",value:(o=Rn(On().m(function e(t,r){var n,o,i,a,c,u,s=arguments;return On().w(function(e){for(;;)switch(e.n){case 0:return n=s.length>2&&void 0!==s[2]?s[2]:void 0,o=s.length>3&&void 0!==s[3]?s[3]:{},i=this.getUrl(r),a=void 0,n&&(["GET","DELETE"].includes(t)?i+="?"+new URLSearchParams(n).toString():a=JSON.stringify(n)),c=Pn(Pn({"Content-Type":"application/json",Accept:"application/json"},o),this.getAuthHeaders()),e.n=1,fetch(i,{method:t,body:a,headers:c});case 1:return u=e.v,e.a(2,this.convertFetchResponse(u))}},e,this)})),function(e,t){return o.apply(this,arguments)})},{key:"getAuthHeaders",value:function(){var e={};return this.options.token&&(e.Authorization="Bearer ".concat(this.options.token)),e}},{key:"getUrl",value:function(e){var t;return this.removeEndingSlash(null!==(t=this.options.url)&&void 0!==t?t:this.defaultUrl)+"/"+this.removeStartingSlash(e)}},{key:"convertFetchResponse",value:(n=Rn(On().m(function e(t){var r,n,o,i,a;return On().w(function(e){for(;;)switch(e.n){case 0:if(n=t.ok,o=t.status,null===(r=t.headers.get("content-type"))||void 0===r||!r.includes("json")){e.n=2;break}return e.n=1,t.json();case 1:i=e.v,e.n=4;break;case 2:return e.n=3,t.text();case 3:i=e.v;case 4:return a=i,e.a(2,{ok:n,status:o,data:a})}},e)})),function(e){return n.apply(this,arguments)})},{key:"removeStartingSlash",value:function(e){return e.replace(/^\/+/,"")}},{key:"removeEndingSlash",value:function(e){return e.replace(/\/+$/,"")}}],t&&_n(e.prototype,t),r&&_n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Fn(e){return Fn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Fn(e)}function Ln(){/*! 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 u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Cn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=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=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Cn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Cn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Cn(f,"constructor",s),Cn(s,"constructor",u),u.displayName="GeneratorFunction",Cn(s,o,"GeneratorFunction"),Cn(f),Cn(f,o,"Generator"),Cn(f,n,function(){return this}),Cn(f,"toString",function(){return"[object Generator]"}),(Ln=function(){return{w:i,m:h}})()}function Cn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Cn=function(e,t,r,n){function i(t,r){Cn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Cn(e,t,r,n)}function xn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Gn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?xn(Object(r),!0).forEach(function(t){$n(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):xn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Dn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Un(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Dn(i,n,o,a,c,"next",e)}function c(e){Dn(i,n,o,a,c,"throw",e)}a(void 0)})}}function Nn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Qn(n.key),n)}}function Bn(e,t,r){return t=Jn(t),function(e,t){if(t&&("object"==Fn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Wn()?Reflect.construct(t,r||[],Jn(e).constructor):t.apply(e,r))}function Wn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Wn=function(){return!!e})()}function Jn(e){return Jn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Jn(e)}function Hn(e,t){return Hn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Hn(e,t)}function $n(e,t,r){return(t=Qn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Qn(e){var t=function(e,t){if("object"!=Fn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Fn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Fn(t)?t:t+""}var Vn=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return $n(e=Bn(this,t,[].concat(n)),"defaultUrl","https://files.devana.pl"),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Hn(e,t)}(t,e),r=t,n=[{key:"uploadFile",value:(c=Un(Ln().m(function e(t){var r,n,o,i;return Ln().w(function(e){for(;;)switch(e.n){case 0:return n=encodeURIComponent(null!==(r=t.name)&&void 0!==r?r:""),o=Gn(Gn({},this.getAuthHeaders()),{},{Accept:"application/json","Content-Disposition":'attachment; filename="'.concat(n,'"'),"Content-Length":t.size}),e.n=1,fetch(this.getUrl("files"),{method:"POST",body:t,headers:o});case 1:return i=e.v,e.a(2,this.convertFetchResponse(i))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getFileMeta",value:(a=Un(Ln().m(function e(t){return Ln().w(function(e){for(;;)if(0===e.n)return e.a(2,this.send("GET","files/"+t))},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getFileMetaBulk",value:(i=Un(Ln().m(function e(t){var r;return Ln().w(function(e){for(;;)if(0===e.n)return r=new URLSearchParams,t.forEach(function(e){return r.append("id[]",e)}),e.a(2,this.send("GET","files?"+r))},e,this)})),function(e){return i.apply(this,arguments)})}],n&&Nn(r.prototype,n),o&&Nn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c}(Mn);return t})());
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|