polfan-server-js-client 0.2.107 → 0.2.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/workspace.xml +14 -11
- package/build/index.cjs.js +5 -4
- 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/index.d.ts +2 -1
- package/build/types/state-tracker/FollowedTopicsManager.d.ts +6 -4
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/state-tracker/FollowedTopicsManager.ts +11 -5
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 F(e,t,r){return t&&M(e.prototype,t),r&&M(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function C(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),C(this,"_items",new Map),this.set.apply(this,E(t))}return F(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),C(this,"_items",void 0),this.id=t,this._items=new x,this.set.apply(this,E(r))}return F(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),C(r=g(this,t),"eventTarget",void 0),r.eventTarget=new a,(e=r).set.apply(e,E(n)),r}return j(t,e),F(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),C(n=g(this,t,[e]),"eventTarget",void 0),n.eventTarget=new a,(r=n).set.apply(r,E(o)),n}return j(t,e),F(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 Fe(){/*! 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 Ce(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]())):(Ce(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,Ce(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Ce(f,"constructor",s),Ce(s,"constructor",u),u.displayName="GeneratorFunction",Ce(s,o,"GeneratorFunction"),Ce(f),Ce(f,o,"Generator"),Ce(f,n,function(){return this}),Ce(f,"toString",function(){return"[object Generator]"}),(Fe=function(){return{w:i,m:h}})()}function Ce(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Ce=function(e,t,r,n){function i(t,r){Ce(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))},Ce(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(Fe().m(function e(t){return Fe().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(Fe().m(function e(t){var r,n,o;return Fe().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=!1,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=!0),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,isUnread:c},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){Ct(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 Ft(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 Ct(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),Ct(this,"list",new D("id")),Ct(this,"roles",new x),Ct(this,"rooms",new x),Ct(this,"roomIdToSpaceId",new x),Ct(this,"members",new x),Ct(this,"deferredSession",new Q),Ct(this,"roomsPromises",new V),Ct(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&&Ft(e.prototype,t),r&&Ft(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 Fr=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 Cr(e){return Cr="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},Cr(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"!=Cr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Cr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Cr(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 Fr(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 Fn(){/*! 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]"}),(Fn=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 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(Fn().m(function e(t,r){var n,o,i,a,c,u,s=arguments;return Fn().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(Fn().m(function e(t){var r,n,o,i,a;return Fn().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:()=>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})());
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|