polfan-server-js-client 0.2.106 → 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.
@@ -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:()=>Dn,FilesClient:()=>Zn,IndexedCollection:()=>L,IndexedObjectCollection:()=>C,Layer:()=>Bt,ObservableIndexedCollection:()=>x,ObservableIndexedObjectCollection:()=>G,PermissionDefinition:()=>Wt,Permissions:()=>Jt,WebApiChatClient:()=>In,WebSocketChatClient:()=>pn,extractUserFromMember:()=>gt});var a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,"events",new Map),o(this,"onceEvents",new Map)},(t=[{key:"on",value:function(e,t){return this.addHandler(this.events,e,t),this}},{key:"once",value:function(e,t){return this.addHandler(this.onceEvents,e,t),this}},{key:"off",value:function(e,t){var r,n,o=null===(r=this.events.get(e))||void 0===r?void 0:r.indexOf(t);return void 0===o||o<0||null===(n=this.events.get(e))||void 0===n||n.splice(o,1),this}},{key:"emit",value:function(e,t){return this.callHandlers(this.events,e,t),this.callHandlers(this.onceEvents,e,t),this.onceEvents.delete(e),this}},{key:"addHandler",value:function(e,t,r){var n,o=null!==(n=e.get(t))&&void 0!==n?n:[];o.push(r),e.set(t,o)}},{key:"callHandlers",value:function(e,t,r){var n;null===(n=e.get(t))||void 0===n||n.forEach(function(e){return e(r)})}}])&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,d(n.key),n)}}function s(e,t,r){return t=f(t),function(e,t){if(t&&("object"==c(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,l()?Reflect.construct(t,r||[],f(e).constructor):t.apply(e,r))}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function p(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){var t=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==c(t)?t:t+""}var y=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return p(e=s(this,t,[].concat(n)),"awaitingResponse",new Map),p(e,"sentCounter",0),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}(t,e),r=t,n=[{key:"createEnvelope",value:function(e,t){return{type:e,data:t,ref:(++this.sentCounter).toString()}}},{key:"createPromiseFromCommandEnvelope",value:function(e){var t=this;return new Promise(function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return t.awaitingResponse.set(e.ref,n)})}},{key:"handleIncomingEnvelope",value:function(e){if(this.awaitingResponse.has(e.ref)){var t="Error"===e.type;this.awaitingResponse.get(e.ref)[0]({data:t?null:e.data,error:t?e.data:null}),this.awaitingResponse.delete(e.ref)}}},{key:"handleEnvelopeSendError",value:function(e,t){this.awaitingResponse.has(e.ref)&&(this.awaitingResponse.get(e.ref)[1](t),this.awaitingResponse.delete(e.ref))}}],n&&u(r.prototype,n),o&&u(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(a);function m(e){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m(e)}function v(e,t,r){return t=k(t),function(e,t){if(t&&("object"==m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,b()?Reflect.construct(t,r||[],k(e).constructor):t.apply(e,r))}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}function g(e,t,r,n){var o=w(k(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function w(){return w="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=k(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},w.apply(null,arguments)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function S(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&O(e,t)}function O(e,t){return O=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},O(e,t)}function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||I(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function j(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=I(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function P(e){return function(e){if(Array.isArray(e))return E(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||I(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e,t){if(e){if("string"==typeof e)return E(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,t):void 0}}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function R(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,F(n.key),n)}}function A(e,t,r){return t&&_(e.prototype,t),r&&_(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function M(e,t,r){return(t=F(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(e){var t=function(e,t){if("object"!=m(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=m(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==m(t)?t:t+""}var L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];R(this,e),M(this,"_items",new Map),this.set.apply(this,P(t))}return A(e,[{key:"items",get:function(){return this._items}},{key:"length",get:function(){return this._items.size}},{key:"set",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this._items.set(i[0],i[1])}}},{key:"get",value:function(e){return this.items.get(e)}},{key:"has",value:function(e){return this.items.has(e)}},{key:"delete",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this.items.delete(i)}}},{key:"deleteAll",value:function(){this.items.clear()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0,i=new e,a=j(this.items.entries());try{for(a.s();!(n=a.n()).done;){var c=T(n.value,2),u=c[0],s=c[1];if(i.length>=o)break;s[t]===r&&i.set([u,s])}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e;return t._items=this._items,t}}])}(),C=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];R(this,e),M(this,"_items",void 0),this.id=t,this._items=new L,this.set.apply(this,P(r))}return A(e,[{key:"items",get:function(){return Array.from(this._items.items.values())}},{key:"length",get:function(){return this._items.length}},{key:"set",value:function(){for(var e,t=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this._items).set.apply(e,P(n.map(function(e){return[t.getId(e),e]})))}},{key:"get",value:function(e){return this._items.get(e)}},{key:"getAt",value:function(e){return this.items[e]}},{key:"has",value:function(e){return this._items.has(e)}},{key:"delete",value:function(){var e;(e=this._items).delete.apply(e,arguments)}},{key:"deleteAll",value:function(){this._items.deleteAll()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new e(this.id),a=j(this.items);try{for(a.s();!(n=a.n()).done;){var c=n.value;if(o&&i.length===o)break;c[t]===r&&i.set(c)}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e(this.id);return t._items=this._items,t}},{key:"getId",value:function(e){return"function"==typeof this.id?this.id(e):e[this.id]}}])}(),x=function(e){function t(){var e,r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return R(this,t),M(r=v(this,t),"eventTarget",void 0),r.eventTarget=new a,(e=r).set.apply(e,P(n)),r}return S(t,e),A(t,[{key:"set",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"set",this,3)(r),this.eventTarget.emit("change",{setItems:r.map(function(e){return e[0]})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){if(this.length){var e=Array.from(this._items.keys());g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:Array.from(e)})}}},{key:"createMirror",value:function(){var e=new t;return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(L),G=function(e){function t(e){var r,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return R(this,t),M(n=v(this,t,[e]),"eventTarget",void 0),n.eventTarget=new a,(r=n).set.apply(r,P(o)),n}return S(t,e),A(t,[{key:"set",value:function(){for(var e=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];n.length&&(g(t,"set",this,3)(n),this.eventTarget.emit("change",{setItems:n.map(function(t){return e.getId(t)})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){var e=this;if(this.length){var r=this.items.map(function(t){return e.getId(t)});g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:r})}}},{key:"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=j(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),g(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}}])}(C);function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}function U(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,J(n.key),n)}}function N(e,t,r){return t&&U(e.prototype,t),r&&U(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function B(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function W(e,t,r){return(t=J(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function J(e){var t=function(e,t){if("object"!=D(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==D(t)?t:t+""}var H=N(function e(){var t=this;B(this,e),W(this,"promise",void 0),W(this,"resolve",void 0),this.promise=new Promise(function(e){return t.resolve=e})}),$=function(){return N(function e(){B(this,e),W(this,"promises",new L)},[{key:"register",value:function(e,t){this.promises.set([t,e])}},{key:"registerByFunction",value:function(e,t){this.register(e(),t)}},{key:"get",value:function(e){return this.promises.get(e)}},{key:"has",value:function(e){return this.promises.has(e)}},{key:"notExist",value:function(e){return!this.has(e)}},{key:"forget",value:function(){var e;(e=this.promises).delete.apply(e,arguments)}},{key:"forgetAll",value:function(){this.promises.deleteAll()}}])}();function Q(e){return Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Q(e)}function V(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?V(Object(r),!0).forEach(function(t){fe(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function q(e,t,r,n){var o=K(ue(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function K(){return K="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=ue(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},K.apply(null,arguments)}function Y(e){return function(e){if(Array.isArray(e))return X(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?X(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Z(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ee(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ee(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ee(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ee(f,"constructor",s),ee(s,"constructor",u),u.displayName="GeneratorFunction",ee(s,o,"GeneratorFunction"),ee(f),ee(f,o,"Generator"),ee(f,n,function(){return this}),ee(f,"toString",function(){return"[object Generator]"}),(Z=function(){return{w:i,m:h}})()}function ee(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ee=function(e,t,r,n){function i(t,r){ee(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ee(e,t,r,n)}function te(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function re(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){te(i,n,o,a,c,"next",e)}function c(e){te(i,n,o,a,c,"throw",e)}a(void 0)})}}function ne(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function oe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,he(n.key),n)}}function ie(e,t,r){return t&&oe(e.prototype,t),r&&oe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function ae(e,t,r){return t=ue(t),function(e,t){if(t&&("object"==Q(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ce()?Reflect.construct(t,r||[],ue(e).constructor):t.apply(e,r))}function ce(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ce=function(){return!!e})()}function ue(e){return ue=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ue(e)}function se(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&le(e,t)}function le(e,t){return le=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},le(e,t)}function fe(e,t,r){return(t=he(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e){var t=function(e,t){if("object"!=Q(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Q(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Q(t)?t:t+""}var pe=function(e){return e[e.LIVE=0]="LIVE",e[e.LATEST=1]="LATEST",e[e.PAST=2]="PAST",e[e.OLDEST=3]="OLDEST",e}({}),de=function(e){function t(e,r,n){var o,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return ne(this,t),fe(o=ae(this,t,["id"]),"WindowState",pe),o.roomId=e,o.topicId=r,o.tracker=n,o.internalState.traverseLock=!1,i&&(o.tracker.client.on("NewMessage",function(e){return o.handleNewMessage(e)}),o.tracker.client.on("MessagesRedacted",function(e){return o.handleMessagesRedacted(e)})),o}return se(t,e),ie(t,[{key:"createMirror",value:function(){var e=new t(this.roomId,this.topicId,this.tracker,!1);return e.eventTarget=this.eventTarget,e._items=this._items,e.internalState=this.internalState,e}},{key:"isTraverseLocked",get:function(){return this.internalState.traverseLock}},{key:"setTraverseLock",value:(y=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(this.internalState.traverseLock=r,!r||this.state===pe.LIVE||this.state===pe.LATEST){e.n=1;break}return e.n=1,q(t,"resetToLatest",this,3)([]);case 1:return e.a(2)}},e,this)})),function(e){return y.apply(this,arguments)})},{key:"resetToLatest",value:(d=re(Z().m(function e(){var r,n=arguments;return Z().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,q(t,"resetToLatest",this,3)([r]))}},e,this)})),function(){return d.apply(this,arguments)})},{key:"fetchNext",value:(p=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchNext",this,3)([]))}},e,this)})),function(){return p.apply(this,arguments)})},{key:"fetchPrevious",value:(h=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchPrevious",this,3)([]))}},e,this)})),function(){return h.apply(this,arguments)})},{key:"jumpTo",value:(f=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"jumpTo",this,3)([r]))}},e,this)})),function(e){return f.apply(this,arguments)})},{key:"_updateMessageReference",value:function(e){var t=this.get(e.refMessage.id);t&&this.set(z(z({},t),{},{topicRef:e.id}))}},{key:"fetchItemsAfter",value:(l=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(this.length-1))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},after:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return l.apply(this,arguments)})},{key:"fetchItemsAround",value:(s=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},around:t,limit:this.internalState.fetchLimit});case 1:if(!(r=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(r.error.message));case 2:return e.a(2,r.data.messages)}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"fetchItemsBefore",value:(u=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(0))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},before:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return u.apply(this,arguments)})},{key:"fetchLatestItems",value:(c=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},limit:this.internalState.fetchLimit});case 1:if(!(t=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(t.error.message));case 2:return e.a(2,t.data.messages)}},e,this)})),function(){return c.apply(this,arguments)})},{key:"getTopic",value:(a=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.getTopics(this.roomId,[this.topicId]);case 1:return e.a(2,e.v.get(this.topicId))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"getLatestMessageId",value:(i=re(Z().m(function e(){var t,r,n,o,i;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getTopic();case 1:if(o=t=e.v,n=null===o){e.n=2;break}n=void 0===t;case 2:if(r=n){e.n=3;break}r=null===(t=t.lastMessage)||void 0===t;case 3:if(!r){e.n=4;break}i=void 0,e.n=5;break;case 4:i=t.id;case 5:return e.a(2,i)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"isLatestItemLoaded",value:(o=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getLatestMessageId();case 1:return t=e.v,e.a(2,!t||this.has(t))}},e,this)})),function(){return o.apply(this,arguments)})},{key:"handleNewMessage",value:(n=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:[pe.LATEST,pe.LIVE].includes(this.state)&&t.message.location.roomId===this.roomId&&t.message.location.topicId===this.topicId&&(r=this.state,this.addItems([t.message],"tail"),this.emitChangeWithDiff(!0,r));case 1:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleMessagesRedacted",value:(r=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:if(t.location.topicId===this.topicId&&t.location.roomId===this.roomId){e.n=1;break}return e.a(2);case 1:if(r=this.items.filter(function(e){return e.topicRef&&t.ids.includes(e.id)}).map(function(e){return e.topicRef}),this.delete.apply(this,Y(t.ids)),0!==this.length){e.n=2;break}return e.n=2,this.resetToLatest();case 2:r.length>0&&this.eventTarget.emit("reftopicsdeleted",r);case 3:return e.a(2)}},e,this)})),function(e){return r.apply(this,arguments)})}]);var r,n,o,i,a,c,u,s,l,f,h,p,d,y}(function(e){function t(){var e;ne(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return fe(e=ae(this,t,[].concat(n)),"internalState",{current:pe.LIVE,ongoing:void 0,limit:1e3,retainRatio:1,fetchLimit:50,lastFetchCount:0,oldestId:null}),e}return se(t,e),ie(t,[{key:"state",get:function(){return this.internalState.current}},{key:"fetchLimit",get:function(){return this.internalState.fetchLimit},set:function(e){this.internalState.fetchLimit=e}},{key:"limit",get:function(){return this.internalState.limit},set:function(e){this.internalState.limit=e}},{key:"retainRatio",get:function(){return this.internalState.retainRatio},set:function(e){this.internalState.retainRatio=e}},{key:"hasLatest",get:function(){return[pe.LATEST,pe.LIVE].includes(this.state)}},{key:"hasOldest",get:function(){return this.state===pe.OLDEST||this.state===pe.LATEST&&this.length<this.fetchLimit||null!==this.internalState.oldestId&&this.has(this.internalState.oldestId)}},{key:"resetToLatest",value:(a=re(Z().m(function e(){var t,r,n,o=arguments;return Z().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!==pe.LATEST)){e.n=1;break}return e.a(2);case 1:return n=this.state,this.internalState.ongoing=pe.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=pe.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=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasOldest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsBefore();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=6;break}return e.a(2,this.resetToLatest());case 6:if(t.length){e.n=8;break}return n=this.getAt(0),this.internalState.oldestId=n?this.getId(n):null,e.n=7,this.refreshFetchedState();case 7:return this.internalState.current===pe.PAST&&(this.internalState.current=pe.OLDEST),this.emitChangeWithDiff(!1,r),e.a(2);case 8:return this.addItems(t,"head"),e.n=9,this.refreshFetchedState();case 9:this.emitChangeWithDiff(!0,r);case 10:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return i.apply(this,arguments)})},{key:"fetchNext",value:(o=re(Z().m(function e(){var t,r;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasLatest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsAfter();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=7;break}return e.n=6,this.resetToLatest();case 6:return e.a(2);case 7:if(!t.length){e.n=9;break}return this.addItems(t,"tail"),e.n=8,this.refreshFetchedState();case 8:return this.emitChangeWithDiff(!0,r),e.a(2);case 9:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return o.apply(this,arguments)})},{key:"jumpTo",value:(n=re(Z().m(function e(t){var r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!(this.internalState.ongoing||this.state!==pe.LIVE&&this._items.has(t))){e.n=1;break}return e.a(2);case 1:return n=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsAround(t);case 3:if(r=e.v,this.internalState.lastFetchCount=r?r.length:0,!r){e.n=4;break}return this._items.deleteAll(),this.addItems(r,"tail"),e.n=4,this.refreshFetchedState();case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:this.emitChangeWithDiff(!!r,n);case 6:return e.a(2)}},e,this,[[2,,4,5]])})),function(e){return n.apply(this,arguments)})},{key:"refreshFetchedState",value:(r=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.isLatestItemLoaded();case 1:if(!e.v){e.n=2;break}t=pe.LATEST,e.n=3;break;case 2:t=pe.PAST;case 3:this.internalState.current=t;case 4:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"addItems",value:function(e,t){var r,n,o=this;"head"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(e),Y(this.items)),"tail")),"tail"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(this.items),Y(e)),"head")),this._items.deleteAll(),(r=this._items).set.apply(r,Y(n.map(function(e){return[o.getId(e),e]})))}},{key:"emitChangeWithDiff",value:function(e,t){(e||t!==this.state)&&this.eventTarget.emit("change",{setItems:Array.from(this._items.items.keys())})}},{key:"trimItemsArrayToLimit",value:function(e,t){var r=this.limit;if(null===r||e.length<=r)return e;var n=Math.floor(r*this.internalState.retainRatio);return"head"===t?e.slice(-n):"tail"===t?e.slice(0,n):e}}]);var r,n,o,i,a}(G));function ye(e){return ye="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ye(e)}function me(e){return function(e){if(Array.isArray(e))return ge(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||be(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ve(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||be(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function be(e,t){if(e){if("string"==typeof e)return ge(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ge(e,t):void 0}}function ge(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function we(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ke(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ke(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ke(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ke(f,"constructor",s),ke(s,"constructor",u),u.displayName="GeneratorFunction",ke(s,o,"GeneratorFunction"),ke(f),ke(f,o,"Generator"),ke(f,n,function(){return this}),ke(f,"toString",function(){return"[object Generator]"}),(we=function(){return{w:i,m:h}})()}function ke(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ke=function(e,t,r,n){function i(t,r){ke(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ke(e,t,r,n)}function Se(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Oe(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Se(i,n,o,a,c,"next",e)}function c(e){Se(i,n,o,a,c,"throw",e)}a(void 0)})}}function Te(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Pe(n.key),n)}}function je(e,t,r){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pe(e){var t=function(e,t){if("object"!=ye(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ye(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ye(t)?t:t+""}var Ie=function(){return e=function e(t,r){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),je(this,"historyWindows",new L),je(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=Oe(we().m(function e(t){var r,n,o=arguments;return we().w(function(e){for(;;)switch(e.n){case 0:if(r=o.length>1&&void 0!==o[1]&&o[1],this.historyWindows.has(t)||r){e.n=2;break}return e.n=1,this.tracker.rooms.getTopics(this.room.id,[t]);case 1:(n=e.v.get(t))&&this.createHistoryWindowForTopic(n);case 2:return e.a(2,this.historyWindows.get(t))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"resync",value:(o=Oe(we().m(function e(t){var r,n,o,i;return we().w(function(e){for(;;)switch(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=5;break}return o=ve(n[r],2),i=o[1],e.n=2,i.setTraverseLock(this.traverseLock);case 2:if(!this.traverseLock){e.n=3;break}return e.a(3,4);case 3:if(i.state!==pe.LATEST){e.n=4;break}return e.n=4,i.resetToLatest(!0);case 4:r++,e.n=1;break;case 5:return e.a(2)}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoomUpdated",value:(n=Oe(we().m(function e(t){var r,n,o,i;return we().w(function(e){for(;;)switch(e.n){case 0:if(this.room.id!==t.room.id){e.n=3;break}this.room=t.room,this.updateTraverseLock(t.room),t.room.defaultTopic&&this.createHistoryWindowForTopic(t.room.defaultTopic),r=0,n=Array.from(this.historyWindows.items);case 1:if(!(r<n.length)){e.n=3;break}return o=ve(n[r],2),i=o[1],e.n=2,i.setTraverseLock(this.traverseLock);case 2:r++,e.n=1;break;case 3:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleNewTopic",value:function(e){this.room.id===e.roomId&&this.createHistoryWindowForTopic(e.topic)}},{key:"handleTopicDeleted",value:function(e){this.room.id===e.location.roomId&&this.historyWindows.delete(e.location.topicId)}},{key:"createHistoryWindowForTopic",value:function(e){var t=this;if(!this.historyWindows.has(e.id)){var r=new de(this.room.id,e.id,this.tracker);if(r.setTraverseLock(this.traverseLock),this.historyWindows.set([e.id,r]),r.on("reftopicsdeleted",function(e){var r,n,o=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=be(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}(e);try{for(o.s();!(n=o.n()).done;){var i=n.value;t.historyWindows.delete(i)}}catch(e){o.e(e)}finally{o.f()}(r=t.tracker.rooms)._deleteTopicsFromRoom.apply(r,[t.room.id].concat(me(e)))}),e.refMessage){var n=this.historyWindows.get(e.refMessage.location.topicId);null==n||n._updateMessageReference(e)}}}},{key:"updateTraverseLock",value:function(e){this.traverseLock="Ephemeral"===e.history.mode}}],t&&Te(e.prototype,t),r&&Te(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i}();function Ee(e){return Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ee(e)}function Re(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 _e(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_e(e,t):void 0}}(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,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 Ae(){/*! 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 Me(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]())):(Me(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,Me(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Me(f,"constructor",s),Me(s,"constructor",u),u.displayName="GeneratorFunction",Me(s,o,"GeneratorFunction"),Me(f),Me(f,o,"Generator"),Me(f,n,function(){return this}),Me(f,"toString",function(){return"[object Generator]"}),(Ae=function(){return{w:i,m:h}})()}function Me(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Me=function(e,t,r,n){function i(t,r){Me(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))},Me(e,t,r,n)}function Fe(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 Le(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Fe(i,n,o,a,c,"next",e)}function c(e){Fe(i,n,o,a,c,"throw",e)}a(void 0)})}}function Ce(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,Ge(n.key),n)}}function xe(e,t,r){return(t=Ge(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ge(e){var t=function(e,t){if("object"!=Ee(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ee(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ee(t)?t:t+""}var De=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),xe(this,"roomHistories",new L),xe(this,"deferredSession",new H),this.tracker=t,this.tracker.client.on("Session",function(e){return r.handleSession(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)})},t=[{key:"getRoomHistory",value:(o=Le(Ae().m(function e(t){return Ae().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=Le(Ae().m(function e(t){var r,n,o;return Ae().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getRoomHistory(t.roomId).then(function(e){return null==e?void 0:e.getMessagesWindow(t.topicId,!0)}).then(function(e){return(null==e?void 0:e.hasLatest)&&e.getAt(e.length-1)});case 1:if(r=e.v){e.n=3;break}return e.n=2,this.tracker.client.send("GetMessages",{location:t,limit:1});case 2:o=e.v,r=null===(n=o.data)||void 0===n?void 0:n.messages[0];case 3:return e.a(2,r||null)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"createHistoryForNewRoom",value:function(e){this.roomHistories.set([e.id,new Ie(e,this.tracker)])}},{key:"handleRoomDeleted",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleRoomJoin",value:function(e){this.createHistoryForNewRoom(e.room)}},{key:"handleRoomLeft",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleSession",value:function(e){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=Re(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&&Ce(e.prototype,t),r&&Ce(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Ue(e){return Ue="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},Ue(e)}function Ne(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 Be(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Ne(Object(r),!0).forEach(function(t){tt(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Ne(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function We(e){return function(e){if(Array.isArray(e))return $e(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||He(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 Je(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=He(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 He(e,t){if(e){if("string"==typeof e)return $e(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$e(e,t):void 0}}function $e(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Qe(){/*! 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 Ve(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]())):(Ve(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,Ve(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Ve(f,"constructor",s),Ve(s,"constructor",u),u.displayName="GeneratorFunction",Ve(s,o,"GeneratorFunction"),Ve(f),Ve(f,o,"Generator"),Ve(f,n,function(){return this}),Ve(f,"toString",function(){return"[object Generator]"}),(Qe=function(){return{w:i,m:h}})()}function Ve(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Ve=function(e,t,r,n){function i(t,r){Ve(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))},Ve(e,t,r,n)}function ze(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 qe(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){ze(i,n,o,a,c,"next",e)}function c(e){ze(i,n,o,a,c,"throw",e)}a(void 0)})}}function Ke(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,rt(n.key),n)}}function Ye(e,t,r){return t=Ze(t),function(e,t){if(t&&("object"==Ue(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,Xe()?Reflect.construct(t,r||[],Ze(e).constructor):t.apply(e,r))}function Xe(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Xe=function(){return!!e})()}function Ze(e){return Ze=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Ze(e)}function et(e,t){return et=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},et(e,t)}function tt(e,t,r){return(t=rt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function rt(e){var t=function(e,t){if("object"!=Ue(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ue(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ue(t)?t:t+""}var nt=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),tt(r=Ye(this,t),"followedTopics",new L),tt(r,"followedTopicsPromises",new $),tt(r,"deferredSession",new H),tt(r,"summariesCache",new Map),tt(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&&et(e,t)}(t,e),r=t,n=[{key:"cacheForSpace",value:(l=qe(Qe().m(function e(t){var r,n,o,i,a=this;return Qe().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(qe(Qe().m(function e(){var r;return Qe().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=qe(Qe().m(function e(t){var r=this;return Qe().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(qe(Qe().m(function e(){var n;return Qe().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=qe(Qe().m(function e(t){var r,n,o,i,a;return Qe().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=Je(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=qe(Qe().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b;return Qe().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=Je(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=Je(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=Je(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=qe(Qe().m(function e(t){var r,n;return Qe().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=Je(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=Je(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=Je(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=qe(Qe().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h;return Qe().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(We(null!==(a=null===(c=s.spaceMember)||void 0===c?void 0:c.roles)&&void 0!==a?a:[]),We(null!==(u=s.roles)&&void 0!==u?u:[])),f=[].concat(We(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(Be(Be({},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 G(function(e){return e.location.topicId})]),(r=this.followedTopics.get(e)).reconcile.apply(r,We(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 G(function(e){return e.location.topicId})]),n[e]&&(t=r.followedTopics.get(e)).set.apply(t,We(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&&Ke(r.prototype,n),o&&Ke(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l}(a);function ot(e){return ot="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},ot(e)}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 at(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){mt(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 ct(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=st(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 ut(e){return function(e){if(Array.isArray(e))return lt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||st(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 st(e,t){if(e){if("string"==typeof e)return lt(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)?lt(e,t):void 0}}function lt(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 ft(){/*! 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 ht(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]())):(ht(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,ht(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ht(f,"constructor",s),ht(s,"constructor",u),u.displayName="GeneratorFunction",ht(s,o,"GeneratorFunction"),ht(f),ht(f,o,"Generator"),ht(f,n,function(){return this}),ht(f,"toString",function(){return"[object Generator]"}),(ft=function(){return{w:i,m:h}})()}function ht(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ht=function(e,t,r,n){function i(t,r){ht(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))},ht(e,t,r,n)}function pt(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 dt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){pt(i,n,o,a,c,"next",e)}function c(e){pt(i,n,o,a,c,"throw",e)}a(void 0)})}}function yt(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,vt(n.key),n)}}function mt(e,t,r){return(t=vt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function vt(e){var t=function(e,t){if("object"!=ot(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ot(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ot(t)?t:t+""}var bt=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),mt(this,"messages",void 0),mt(this,"followedTopics",void 0),mt(this,"list",new G("id")),mt(this,"topics",new L),mt(this,"members",new L),mt(this,"deferredSession",new H),mt(this,"membersPromises",new $),mt(this,"topicsPromises",new $),this.tracker=t,this.messages=new De(t),this.followedTopics=new nt(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=dt(ft().m(function e(t){var r=this;return ft().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(dt(ft().m(function e(){var n;return ft().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=dt(ft().m(function e(t){var r,n;return ft().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=dt(ft().m(function e(){return ft().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=dt(ft().m(function e(t,r){var n,o,i,a,c,u,s,l=this;return ft().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,ut(e.data.topics))}),o.forEach(function(e){return l.topicsPromises.register(i,t+e)})),a=ct(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(ut(p)))}(n=this.topics).delete.apply(n,i)}},{key:"deleteRoomsBySpaceId",value:function(e){this.deleteRoom.apply(this,ut(this.list.findBy("spaceId",e).items.map(function(e){return e.id})))}},{key:"handleSpaceMemberUpdated",value:function(e){var t,r=ct(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(at(at({},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(at(at({},r),{},{defaultTopic:null}))}},{key:"handleNewTopic",value:function(e){this.addJoinedRoomTopics(e.roomId,e.topic)}},{key:"addJoinedRoomTopics",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o;this.topics.has(e)?(o=this.topics.get(e)).set.apply(o,r):this.topics.set([e,new G("id",r)])}},{key:"handleRoomJoined",value:function(e){this.addJoinedRooms(e.room)}},{key:"handleRoomUpdated",value:function(e){this.list.has(e.room.id)&&this.list.set(e.room)}},{key:"handleRoomDeleted",value:function(e){this.deleteRoom(e.id)}},{key:"handleTopicUpdated",value:function(e){var t,r=this.list.get(e.location.roomId);if(null!==(t=this.topics.get(e.location.roomId))&&void 0!==t&&t.has(e.topic.id)&&this.topics.get(e.location.roomId).set(e.topic),r.defaultTopic.id===e.topic.id){var n=at({},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,ut(e.members)):this.members.set([e.id,new G(function(e){var t,r;return null!==(t=null===(r=e.user)||void 0===r?void 0:r.id)&&void 0!==t?t:e.spaceMember.user.id},e.members)])}},{key:"handleSession",value:function(e){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,ut(r)),this.membersPromises.forgetAll(),this.topicsPromises.forgetAll(),this.addJoinedRooms.apply(this,ut(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=at({},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(at({},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=at(at({},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(at(at({},i),{},{defaultTopic:o}))}}},{key:"handleMessagesRedacted",value:(n=dt(ft().m(function e(t){var r,n,o,i,a;return ft().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(at(at({},n),{},{messageCount:o,lastMessage:i}));case 4:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})}],t&&yt(e.prototype,t),r&&yt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a}();function gt(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 wt(e){return wt="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},wt(e)}function kt(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Ot(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 St(e){return function(e){if(Array.isArray(e))return Tt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Ot(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 Ot(e,t){if(e){if("string"==typeof e)return Tt(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)?Tt(e,t):void 0}}function Tt(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 jt(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 Pt(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?jt(Object(r),!0).forEach(function(t){Mt(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):jt(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function It(){/*! 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 Et(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]())):(Et(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,Et(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Et(f,"constructor",s),Et(s,"constructor",u),u.displayName="GeneratorFunction",Et(s,o,"GeneratorFunction"),Et(f),Et(f,o,"Generator"),Et(f,n,function(){return this}),Et(f,"toString",function(){return"[object Generator]"}),(It=function(){return{w:i,m:h}})()}function Et(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Et=function(e,t,r,n){function i(t,r){Et(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))},Et(e,t,r,n)}function Rt(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 _t(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Rt(i,n,o,a,c,"next",e)}function c(e){Rt(i,n,o,a,c,"throw",e)}a(void 0)})}}function At(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,Ft(n.key),n)}}function Mt(e,t,r){return(t=Ft(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ft(e){var t=function(e,t){if("object"!=wt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=wt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==wt(t)?t:t+""}var Lt=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),Mt(this,"list",new G("id")),Mt(this,"roles",new L),Mt(this,"rooms",new L),Mt(this,"roomIdToSpaceId",new L),Mt(this,"members",new L),Mt(this,"deferredSession",new H),Mt(this,"roomsPromises",new $),Mt(this,"membersPromises",new $),this.tracker=t,this.tracker.client.on("NewRoom",function(e){return r.handleNewRoom(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceUpdated",function(e){return r.handleSpaceUpdated(e)}),this.tracker.client.on("SpaceJoined",function(e){return r.handleSpaceJoined(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceMemberJoined",function(e){return r.handleSpaceMemberJoined(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMembers",function(e){return r.handleSpaceMembers(e)}),this.tracker.client.on("SpaceRooms",function(e){return r.handleSpaceRooms(e)}),this.tracker.client.on("RoomSummaryUpdated",function(e){return r.handleRoomSummaryUpdated(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("NewRole",function(e){return r.handleNewRole(e)}),this.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),this.tracker.client.on("RoleUpdated",function(e){return r.handleRoleUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"get",value:function(){var e=_t(It().m(function e(){return It().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=_t(It().m(function e(t){return It().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=_t(It().m(function e(t){var r=this;return It().w(function(e){for(;;)switch(e.n){case 0:return this.roomsPromises.notExist(t)&&this.roomsPromises.registerByFunction(_t(It().m(function e(){var n;return It().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=_t(It().m(function e(t){var r=this;return It().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(_t(It().m(function e(){var n;return It().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=_t(It().m(function e(t){var r,n;return It().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(Pt(Pt({},t.get(e.room.id)),{},{name:e.room.name,description:e.room.description}))}}},{key:"handleRoomDeleted",value:(o=_t(It().m(function e(t){var r,n,o,i;return It().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,St(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,St(n.map(function(e){return[e.id,new G("id",e.roles)]}))),(t=this.list).set.apply(t,n)}},{key:"handleSpaceMemberJoined",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).set(e.member)}},{key:"handleSpaceMemberLeft",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).delete(e.userId)}},{key:"handleSpaceMembers",value:function(e){var t;this.members.has(e.id)?(t=this.members.get(e.id)).reconcile.apply(t,St(e.members)):this.members.set([e.id,new G(function(e){return null==e?void 0:e.user.id},e.members)])}},{key:"handleSpaceRooms",value:function(e){var t,r=this;this.rooms.has(e.id)?(t=this.rooms.get(e.id)).reconcile.apply(t,St(e.summaries)):this.rooms.set([e.id,new G("id",e.summaries)]),e.summaries.forEach(function(t){return r.roomIdToSpaceId.set([t.id,e.id])})}},{key:"handleRoomSummaryUpdated",value:(n=_t(It().m(function e(t){var r,n,o,i,a;return It().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?Pt(Pt({},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(Pt(Pt({},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,St(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=kt(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=kt(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,St(l.roles)):this.roles.set([l.id,new G("id",l.roles)])}}catch(e){u.e(e)}finally{u.f()}(t=this.list).set.apply(t,St(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(Pt(Pt({},r),{},{user:e.user}))})}}],t&&At(e.prototype,t),r&&At(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a,c,u}();function Ct(e){return Ct="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},Ct(e)}function xt(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,Nt(n.key),n)}}function Gt(e,t,r){return t&&xt(e.prototype,t),r&&xt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Dt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ut(e,t,r){return(t=Nt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Nt(e){var t=function(e,t){if("object"!=Ct(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ct(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ct(t)?t:t+""}var Bt=function(e){return e[e.Global=0]="Global",e[e.Space=1]="Space",e[e.Room=2]="Room",e[e.Topic=3]="Topic",e}({}),Wt=Gt(function e(){Dt(this,e),Ut(this,"value",void 0),Ut(this,"maxLayer",void 0)}),Jt=function(){return Gt(function e(){Dt(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 Ht(e){return Ht="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},Ht(e)}function $t(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=zt(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 Qt(e){return function(e){if(Array.isArray(e))return qt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||zt(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 Vt(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)||zt(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 zt(e,t){if(e){if("string"==typeof e)return qt(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)?qt(e,t):void 0}}function qt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Kt(){/*! 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 Yt(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]())):(Yt(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,Yt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Yt(f,"constructor",s),Yt(s,"constructor",u),u.displayName="GeneratorFunction",Yt(s,o,"GeneratorFunction"),Yt(f),Yt(f,o,"Generator"),Yt(f,n,function(){return this}),Yt(f,"toString",function(){return"[object Generator]"}),(Kt=function(){return{w:i,m:h}})()}function Yt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Yt=function(e,t,r,n){function i(t,r){Yt(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))},Yt(e,t,r,n)}function Xt(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 Zt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Xt(i,n,o,a,c,"next",e)}function c(e){Xt(i,n,o,a,c,"throw",e)}a(void 0)})}}function er(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,ar(n.key),n)}}function tr(e,t,r){return t=nr(t),function(e,t){if(t&&("object"==Ht(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,rr()?Reflect.construct(t,r||[],nr(e).constructor):t.apply(e,r))}function rr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(rr=function(){return!!e})()}function nr(e){return nr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},nr(e)}function or(e,t){return or=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},or(e,t)}function ir(e,t,r){return(t=ar(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ar(e){var t=function(e,t){if("object"!=Ht(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ht(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ht(t)?t:t+""}Ut(Jt,"list",{Root:{value:1,maxLayer:Bt.Room},CreateSpaces:{value:2,maxLayer:Bt.Global},ManageSpace:{value:4,maxLayer:Bt.Space},ManageRoles:{value:8,maxLayer:Bt.Space},CreateTopics:{value:32,maxLayer:Bt.Room},ManageTopic:{value:64,maxLayer:Bt.Topic},ManageMemberProfiles:{value:128,maxLayer:Bt.Space},ManageMemberRoles:{value:256,maxLayer:Bt.Room},CreateMessages:{value:512,maxLayer:Bt.Topic},ManagePermissions:{value:1024,maxLayer:Bt.Topic},CreateRooms:{value:2048,maxLayer:Bt.Space},ManageRoom:{value:4096,maxLayer:Bt.Room},CreateEmoticons:{value:8192,maxLayer:Bt.Space},ManageEmoticons:{value:16384,maxLayer:Bt.Space},ManageBans:{value:32768,maxLayer:Bt.Room},Kick:{value:65536,maxLayer:Bt.Room},ChangeOwnNick:{value:1<<17,maxLayer:Bt.Space},ChangeOwnColor:{value:1<<18,maxLayer:Bt.Room},RedactMessages:{value:1<<19,maxLayer:Bt.Topic}});var cr=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("/")},ur=function(e){return cr(e.location,e.target)},sr=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),ir(r=tr(this,t),"overwrites",new L),ir(r,"overwritesPromises",new $),r.tracker=e,r.tracker.client.on("PermissionOverwrites",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("PermissionOverwritesUpdated",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),r.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),r.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&or(e,t)}(t,e),r=t,n=[{key:"getOverwrites",value:(f=Zt(Kt().m(function e(t,r){var n,o=this;return Kt().w(function(e){for(;;)switch(e.n){case 0:return this.validateLocation(t),n=cr(t,r),this.overwritesPromises.notExist(n)&&this.overwritesPromises.registerByFunction(Zt(Kt().m(function e(){var n;return Kt().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=Zt(Kt().m(function e(t,r){var n,o;return Kt().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&Jt.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=Zt(Kt().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,T,j,P;return Kt().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=Vt(s,2),f=l[0],h=l[1],p=[].concat(Qt(null!==(n=null==f?void 0:f.roles)&&void 0!==n?n:[]),Qt(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(j=a=e.v,!(T=null!==j)){e.n=12;break}T=void 0!==a;case 12:if(!(O=T)){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([ur(e),e]),this.emit("change")}},{key:"handleSpaceDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(cr({spaceId:e.id}));(t=this.overwritesPromises).forget.apply(t,Qt(r))}},{key:"handleRoomDeleted",value:(u=Zt(Kt().m(function e(t){var r,n,o;return Kt().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(cr({spaceId:r.spaceId,roomId:r.id})),(n=this.overwritesPromises).forget.apply(n,Qt(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(cr(e.location));(t=this.overwritesPromises).forget.apply(t,Qt(r))}},{key:"handleRoleDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(cr({spaceId:e.spaceId},{type:"Role",roleId:e.id}));(t=this.overwritesPromises).forget.apply(t,Qt(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=ur(n);o.startsWith(e)&&(r.push(o),t.overwrites.delete(o))}),r}},{key:"collectRoleOverwrites",value:(c=Zt(Kt().m(function e(t,r){var n,o=this;return Kt().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=Zt(Kt().m(function e(t,r){var n,o,i,a,c;return Kt().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=$t(e);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(o.allow&Jt.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=$t(Jt.getNames());try{for(r.s();!(e=r.n()).done;){var n=e.value;t|=Jt.getByName(n).value}}catch(e){r.e(e)}finally{r.f()}return t}},{key:"fetchMembersOrFail",value:(i=Zt(Kt().m(function e(t){var r,n,o,i;return Kt().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&&er(r.prototype,n),o&&er(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l,f}(a);function lr(e){return lr="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},lr(e)}function fr(e){return function(e){if(Array.isArray(e))return hr(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 hr(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)?hr(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 hr(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 pr(){/*! 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 dr(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]())):(dr(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,dr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,dr(f,"constructor",s),dr(s,"constructor",u),u.displayName="GeneratorFunction",dr(s,o,"GeneratorFunction"),dr(f),dr(f,o,"Generator"),dr(f,n,function(){return this}),dr(f,"toString",function(){return"[object Generator]"}),(pr=function(){return{w:i,m:h}})()}function dr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}dr=function(e,t,r,n){function i(t,r){dr(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))},dr(e,t,r,n)}function yr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function mr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){yr(i,n,o,a,c,"next",e)}function c(e){yr(i,n,o,a,c,"throw",e)}a(void 0)})}}function vr(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,gr(n.key),n)}}function br(e,t,r){return(t=gr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function gr(e){var t=function(e,t){if("object"!=lr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=lr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==lr(t)?t:t+""}var wr="global",kr=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),br(this,"list",new L),br(this,"emoticonsPromises",new $),this.tracker=t,this.tracker.client.on("Emoticons",function(e){return r.handleEmoticons(e)}),this.tracker.client.on("NewEmoticon",function(e){return r.handleNewEmoticon(e)}),this.tracker.client.on("EmoticonDeleted",function(e){return r.handleEmoticonDeleted(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=mr(pr().m(function e(t){var r,n=this;return pr().w(function(e){for(;;)switch(e.n){case 0:return r=null!=t?t:wr,this.emoticonsPromises.notExist(r)&&this.emoticonsPromises.registerByFunction(mr(pr().m(function e(){var r;return pr().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:wr;this.list.has(n)||this.list.set([n,new G("id")]),(r=this.list.get(n)).reconcile.apply(r,fr(e.emoticons))}},{key:"handleNewEmoticon",value:function(e){var t,r=this.list.get(null!==(t=e.emoticon.spaceId)&&void 0!==t?t:wr);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:wr);null==r||r.delete(e.emoticonId)}},{key:"handleSpaceDeleted",value:function(e){this.list.delete(e.id)}},{key:"handleSession",value:function(){this.emoticonsPromises.forgetAll()}}],t&&vr(e.prototype,t),r&&vr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function Sr(e){return Sr="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},Sr(e)}function Or(e){return function(e){if(Array.isArray(e))return Tr(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 Tr(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)?Tr(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 Tr(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 jr(){/*! 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 Pr(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]())):(Pr(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,Pr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Pr(f,"constructor",s),Pr(s,"constructor",u),u.displayName="GeneratorFunction",Pr(s,o,"GeneratorFunction"),Pr(f),Pr(f,o,"Generator"),Pr(f,n,function(){return this}),Pr(f,"toString",function(){return"[object Generator]"}),(jr=function(){return{w:i,m:h}})()}function Pr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Pr=function(e,t,r,n){function i(t,r){Pr(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))},Pr(e,t,r,n)}function Ir(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 Er(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_r(n.key),n)}}function Rr(e,t,r){return(t=_r(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _r(e){var t=function(e,t){if("object"!=Sr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Sr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Sr(t)?t:t+""}var Ar=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),Rr(this,"onlineStatus",new a),Rr(this,"users",new G("id")),this.tracker=t,t.client.on("UserUpdated",function(e){return r.handleUsers([e.user])}),t.client.on("RoomMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMembers",function(e){return r.handleMembers(e.members)}),t.client.on("RoomMembers",function(e){return r.handleMembers(e.members)}),t.client.on("Messages",function(e){return r.handleUsers(e.messages.map(function(e){return e.author.user}))}),t.client.on("NewMessage",function(e){return r.handleUsers([e.message.author.user])}),t.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getAvailable",value:(n=jr().m(function e(){return jr().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){Ir(i,r,o,a,c,"next",e)}function c(e){Ir(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(gt))}},{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,Or(e))}}],t&&Er(e.prototype,t),r&&Er(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Mr(e){return Mr="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},Mr(e)}function Fr(e){return function(e){if(Array.isArray(e))return Lr(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 Lr(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)?Lr(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 Lr(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 Cr(){/*! 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 xr(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]())):(xr(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,xr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,xr(f,"constructor",s),xr(s,"constructor",u),u.displayName="GeneratorFunction",xr(s,o,"GeneratorFunction"),xr(f),xr(f,o,"Generator"),xr(f,n,function(){return this}),xr(f,"toString",function(){return"[object Generator]"}),(Cr=function(){return{w:i,m:h}})()}function xr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}xr=function(e,t,r,n){function i(t,r){xr(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))},xr(e,t,r,n)}function Gr(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 Dr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Gr(i,n,o,a,c,"next",e)}function c(e){Gr(i,n,o,a,c,"throw",e)}a(void 0)})}}function Ur(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,Br(n.key),n)}}function Nr(e,t,r){return(t=Br(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Br(e){var t=function(e,t){if("object"!=Mr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Mr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Mr(t)?t:t+""}var Wr=function(e,t){return"".concat(e,"-").concat(t)},Jr=function(e){return Wr(e.refUser.id,e.type)},Hr=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),Nr(this,"relationships",new G(Jr)),Nr(this,"promises",new $),this.tracker=t,this.tracker.client.on("Relationships",function(e){return r.handleRelationships(e)}),this.tracker.client.on("NewRelationship",function(e){return r.handleNewRelationship(e)}),this.tracker.client.on("RelationshipDeleted",function(e){return r.handleRelationshipDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=Dr(Cr().m(function e(){var t=this;return Cr().w(function(e){for(;;)switch(e.n){case 0:return this.promises.notExist("all")&&this.promises.registerByFunction(Dr(Cr().m(function e(){var r;return Cr().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=Dr(Cr().m(function e(t,r){return Cr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.get();case 1:return e.a(2,this.relationships.has(Wr(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,Fr(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(Jr(e.relationship))}},{key:"handleSession",value:function(){this.promises.forgetAll()}}],t&&Ur(e.prototype,t),r&&Ur(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n}();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 Qr(){/*! 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 Vr(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]())):(Vr(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,Vr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Vr(f,"constructor",s),Vr(s,"constructor",u),u.displayName="GeneratorFunction",Vr(s,o,"GeneratorFunction"),Vr(f),Vr(f,o,"Generator"),Vr(f,n,function(){return this}),Vr(f,"toString",function(){return"[object Generator]"}),(Qr=function(){return{w:i,m:h}})()}function Vr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Vr=function(e,t,r,n){function i(t,r){Vr(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))},Vr(e,t,r,n)}function zr(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 qr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Yr(n.key),n)}}function Kr(e,t,r){return(t=Yr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Yr(e){var t=function(e,t){if("object"!=$r(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=$r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==$r(t)?t:t+""}var Xr=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),Kr(this,"client",void 0),Kr(this,"permissions",void 0),Kr(this,"rooms",void 0),Kr(this,"spaces",void 0),Kr(this,"emoticons",void 0),Kr(this,"users",void 0),Kr(this,"relationships",void 0),Kr(this,"_me",null),Kr(this,"deferredSession",new H),this.client=t,this.client.on("Session",function(e){return r.handleSession(e)}),this.permissions=new sr(this),this.rooms=new bt(this),this.spaces=new Lt(this),this.emoticons=new kr(this),this.users=new Ar(this),this.relationships=new Hr(this)},t=[{key:"me",get:function(){return this._me}},{key:"getMe",value:(n=Qr().m(function e(){return Qr().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){zr(i,r,o,a,c,"next",e)}function c(e){zr(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&&qr(e.prototype,t),r&&qr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Zr(e){return Zr="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},Zr(e)}function en(){/*! 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 tn(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]())):(tn(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,tn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,tn(f,"constructor",s),tn(s,"constructor",u),u.displayName="GeneratorFunction",tn(s,o,"GeneratorFunction"),tn(f),tn(f,o,"Generator"),tn(f,n,function(){return this}),tn(f,"toString",function(){return"[object Generator]"}),(en=function(){return{w:i,m:h}})()}function tn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}tn=function(e,t,r,n){function i(t,r){tn(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))},tn(e,t,r,n)}function rn(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 nn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){rn(i,n,o,a,c,"next",e)}function c(e){rn(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,fn(n.key),n)}}function an(e,t,r){return t=un(t),function(e,t){if(t&&("object"==Zr(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,cn()?Reflect.construct(t,r||[],un(e).constructor):t.apply(e,r))}function cn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(cn=function(){return!!e})()}function un(e){return un=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},un(e)}function sn(e,t){return sn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},sn(e,t)}function ln(e,t,r){return(t=fn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function fn(e){var t=function(e,t){if("object"!=Zr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Zr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Zr(t)?t:t+""}var hn=function(e){return e.connect="connect",e.disconnect="disconnect",e.message="message",e.error="error",e}(hn||{}),pn=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),ln(l=an(this,t),"Event",hn),ln(l,"state",void 0),ln(l,"ws",null),ln(l,"sendQueue",[]),ln(l,"connectingTimeoutId",void 0),ln(l,"authenticated",void 0),ln(l,"authenticatedResolvers",void 0),ln(l,"pingMonitorInterval",void 0),ln(l,"inFlightPingTimeout",void 0),ln(l,"lastReceivedMessageAt",void 0),l.options=e,(null===(r=l.options.stateTracking)||void 0===r||r)&&(l.state=new Xr(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&&sn(e,t)}(t,e),r=t,n=[{key:"connect",value:(a=nn(en().m(function e(){var t,r,n,o=this;return en().w(function(e){for(;;)switch(e.n){case 0:if(!this.isOpenWsState()&&!this.isConnectingWsState()){e.n=1;break}return e.a(2);case 1:return(n=new URLSearchParams(null!==(t=this.options.queryParams)&&void 0!==t?t:{})).set("token",this.options.token),this.ws=new WebSocket("".concat(this.options.url,"?").concat(n)),this.ws.onclose=function(e){return o.onClose(e)},this.ws.onmessage=function(e){return o.onMessage(e)},this.connectingTimeoutId=setTimeout(function(){return o.triggerConnectionTimeout()},null!==(r=this.options.connectingTimeoutMs)&&void 0!==r?r:1e4),this.authenticated=!1,e.a(2,new Promise(function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return o.authenticatedResolvers=t}))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"disconnect",value:function(){var e;this.sendQueue=[],null===(e=this.ws)||void 0===e||e.close(1e3),this.ws=null}},{key:"send",value:(i=nn(en().m(function e(t,r){var n,o;return en().w(function(e){for(;;)switch(e.n){case 0:if(n=this.createEnvelope(t,r),o=this.createPromiseFromCommandEnvelope(n),!(this.isConnectingWsState()||!this.authenticated&&this.isOpenWsState())){e.n=1;break}return this.sendQueue.push(n),e.a(2,o);case 1:return this.sendEnvelope(n),e.a(2,o)}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"isReady",get:function(){return this.isOpenWsState()&&this.authenticated}},{key:"sendEnvelope",value:function(e){var t,r;this.isReady?this.ws.send(JSON.stringify(e)):this.handleEnvelopeSendError(e,new Error("Cannot send - client is not ready (state=".concat(null!==(t=null===(r=this.ws)||void 0===r?void 0:r.readyState)&&void 0!==t?t:"[no connection]","; authenticated=").concat(this.authenticated,")")))}},{key:"onMessage",value:function(e){this.lastReceivedMessageAt=Date.now();var t=JSON.parse(e.data);if(this.handleIncomingEnvelope(t),this.emit(t.type,t.data),this.emit(this.Event.message,t),!this.authenticated){var r="Bye"!==t.type;this.authenticated=r,r?(this.startConnectionMonitor(),this.authenticatedResolvers[0](),this.emit(this.Event.connect),this.sendFromQueue()):this.authenticatedResolvers[1](t.data)}}},{key:"onClose",value:function(e){this.stopConnectionMonitor(),clearTimeout(this.connectingTimeoutId);var t=1e3!==e.code;t&&this.connect(),this.emit(this.Event.disconnect,t)}},{key:"sendFromQueue",value:function(){var e=this,t=0,r=function(){var r,o=e.sendQueue[n];setTimeout(function(){return e.sendEnvelope(o)},t),t+=null!==(r=e.options.awaitQueueSendDelayMs)&&void 0!==r?r:500};for(var n in this.sendQueue)r();this.sendQueue=[],clearTimeout(this.connectingTimeoutId)}},{key:"triggerConnectionTimeout",value:function(){this.disconnect(),this.emit(this.Event.error,new Error("Connection timeout"))}},{key:"isConnectingWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.CONNECTING}},{key:"isOpenWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.OPEN}},{key:"startConnectionMonitor",value:function(){var e=this;this.options.ping.enabled&&(this.lastReceivedMessageAt=Date.now(),this.pingMonitorInterval=setInterval(nn(en().m(function t(){return en().w(function(t){for(;;)switch(t.n){case 0:if(e.isReady&&!e.inFlightPingTimeout){t.n=1;break}return t.a(2);case 1:if(!(Date.now()-e.lastReceivedMessageAt<e.options.ping.noActivityTimeoutMs)){t.n=2;break}return t.a(2);case 2:e.inFlightPingTimeout=setTimeout(function(){e.inFlightPingTimeout=void 0,e.ws.close(3e3)},e.options.ping.pongBackTimeoutMs),e.send("Ping",{}).then(function(){clearTimeout(e.inFlightPingTimeout),e.inFlightPingTimeout=void 0});case 3:return t.a(2)}},t)})),1e3))}},{key:"stopConnectionMonitor",value:function(){this.inFlightPingTimeout&&(clearTimeout(this.inFlightPingTimeout),this.inFlightPingTimeout=void 0),this.pingMonitorInterval&&(clearInterval(this.pingMonitorInterval),this.pingMonitorInterval=void 0)}}],n&&on(r.prototype,n),o&&on(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function dn(e){return dn="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},dn(e)}function yn(){/*! 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 mn(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]())):(mn(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,mn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,mn(f,"constructor",s),mn(s,"constructor",u),u.displayName="GeneratorFunction",mn(s,o,"GeneratorFunction"),mn(f),mn(f,o,"Generator"),mn(f,n,function(){return this}),mn(f,"toString",function(){return"[object Generator]"}),(yn=function(){return{w:i,m:h}})()}function mn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}mn=function(e,t,r,n){function i(t,r){mn(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))},mn(e,t,r,n)}function vn(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 bn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){vn(i,n,o,a,c,"next",e)}function c(e){vn(i,n,o,a,c,"throw",e)}a(void 0)})}}function gn(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,jn(n.key),n)}}function wn(e,t,r){return t=Sn(t),function(e,t){if(t&&("object"==dn(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,kn()?Reflect.construct(t,r||[],Sn(e).constructor):t.apply(e,r))}function kn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(kn=function(){return!!e})()}function Sn(e){return Sn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Sn(e)}function On(e,t){return On=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},On(e,t)}function Tn(e,t,r){return(t=jn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function jn(e){var t=function(e,t){if("object"!=dn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=dn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==dn(t)?t:t+""}var Pn=function(e){return e.message="message",e.error="error",e.destroy="destroy",e}(Pn||{}),In=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),Tn(r=wn(this,t),"Event",Pn),Tn(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&&On(e,t)}(t,e),r=t,n=[{key:"send",value:(a=bn(yn().m(function e(t,r){var n,o;return yn().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=bn(yn().m(function e(t,r){var n;return yn().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&&gn(r.prototype,n),o&&gn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function En(e){return En="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},En(e)}function Rn(){/*! 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]"}),(Rn=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 An(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 Mn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?An(Object(r),!0).forEach(function(t){Fn(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):An(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Fn(e,t,r){return(t=Gn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ln(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 Cn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ln(i,n,o,a,c,"next",e)}function c(e){Ln(i,n,o,a,c,"throw",e)}a(void 0)})}}function xn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Gn(n.key),n)}}function Gn(e){var t=function(e,t){if("object"!=En(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=En(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==En(t)?t:t+""}var Dn=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=Cn(Rn().m(function e(t,r){var n,o,i,a,c,u,s=arguments;return Rn().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=Mn(Mn({"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=Cn(Rn().m(function e(t){var r,n,o,i,a;return Rn().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&&xn(e.prototype,t),r&&xn(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Un(e){return Un="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Un(e)}function Nn(){/*! 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 Bn(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]())):(Bn(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,Bn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Bn(f,"constructor",s),Bn(s,"constructor",u),u.displayName="GeneratorFunction",Bn(s,o,"GeneratorFunction"),Bn(f),Bn(f,o,"Generator"),Bn(f,n,function(){return this}),Bn(f,"toString",function(){return"[object Generator]"}),(Nn=function(){return{w:i,m:h}})()}function Bn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Bn=function(e,t,r,n){function i(t,r){Bn(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))},Bn(e,t,r,n)}function Wn(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 Jn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Wn(Object(r),!0).forEach(function(t){Yn(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Wn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Hn(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 $n(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Hn(i,n,o,a,c,"next",e)}function c(e){Hn(i,n,o,a,c,"throw",e)}a(void 0)})}}function Qn(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,Xn(n.key),n)}}function Vn(e,t,r){return t=qn(t),function(e,t){if(t&&("object"==Un(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,zn()?Reflect.construct(t,r||[],qn(e).constructor):t.apply(e,r))}function zn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(zn=function(){return!!e})()}function qn(e){return qn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},qn(e)}function Kn(e,t){return Kn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Kn(e,t)}function Yn(e,t,r){return(t=Xn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Xn(e){var t=function(e,t){if("object"!=Un(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Un(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Un(t)?t:t+""}var Zn=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 Yn(e=Vn(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&&Kn(e,t)}(t,e),r=t,n=[{key:"uploadFile",value:(c=$n(Nn().m(function e(t){var r,n,o,i;return Nn().w(function(e){for(;;)switch(e.n){case 0:return n=encodeURIComponent(null!==(r=t.name)&&void 0!==r?r:""),o=Jn(Jn({},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=$n(Nn().m(function e(t){return Nn().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=$n(Nn().m(function e(t){var r;return Nn().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&&Qn(r.prototype,n),o&&Qn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c}(Dn);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