polfan-server-js-client 0.2.101 → 0.2.102

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:()=>Mn,FilesClient:()=>Vn,IndexedCollection:()=>L,IndexedObjectCollection:()=>C,Layer:()=>Gt,ObservableIndexedCollection:()=>x,ObservableIndexedObjectCollection:()=>G,PermissionDefinition:()=>Dt,Permissions:()=>Ut,WebApiChatClient:()=>kn,WebSocketChatClient:()=>cn,extractUserFromMember:()=>vt});var a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,"events",new Map),o(this,"onceEvents",new Map)},(t=[{key:"on",value:function(e,t){return this.addHandler(this.events,e,t),this}},{key:"once",value:function(e,t){return this.addHandler(this.onceEvents,e,t),this}},{key:"off",value:function(e,t){var r,n,o=null===(r=this.events.get(e))||void 0===r?void 0:r.indexOf(t);return void 0===o||o<0||null===(n=this.events.get(e))||void 0===n||n.splice(o,1),this}},{key:"emit",value:function(e,t){return this.callHandlers(this.events,e,t),this.callHandlers(this.onceEvents,e,t),this.onceEvents.delete(e),this}},{key:"addHandler",value:function(e,t,r){var n,o=null!==(n=e.get(t))&&void 0!==n?n:[];o.push(r),e.set(t,o)}},{key:"callHandlers",value:function(e,t,r){var n;null===(n=e.get(t))||void 0===n||n.forEach(function(e){return e(r)})}}])&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,d(n.key),n)}}function s(e,t,r){return t=f(t),function(e,t){if(t&&("object"==c(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,l()?Reflect.construct(t,r||[],f(e).constructor):t.apply(e,r))}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function p(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){var t=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==c(t)?t:t+""}var y=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return p(e=s(this,t,[].concat(n)),"awaitingResponse",new Map),p(e,"sentCounter",0),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}(t,e),r=t,n=[{key:"createEnvelope",value:function(e,t){return{type:e,data:t,ref:(++this.sentCounter).toString()}}},{key:"createPromiseFromCommandEnvelope",value:function(e){var t=this;return new Promise(function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return t.awaitingResponse.set(e.ref,n)})}},{key:"handleIncomingEnvelope",value:function(e){if(this.awaitingResponse.has(e.ref)){var t="Error"===e.type;this.awaitingResponse.get(e.ref)[0]({data:t?null:e.data,error:t?e.data:null}),this.awaitingResponse.delete(e.ref)}}},{key:"handleEnvelopeSendError",value:function(e,t){this.awaitingResponse.has(e.ref)&&(this.awaitingResponse.get(e.ref)[1](t),this.awaitingResponse.delete(e.ref))}}],n&&u(r.prototype,n),o&&u(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(a);function m(e){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m(e)}function v(e,t,r){return t=k(t),function(e,t){if(t&&("object"==m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,b()?Reflect.construct(t,r||[],k(e).constructor):t.apply(e,r))}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}function g(e,t,r,n){var o=w(k(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function w(){return w="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=k(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},w.apply(null,arguments)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function S(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&O(e,t)}function O(e,t){return O=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},O(e,t)}function j(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||I(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=I(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function P(e){return function(e){if(Array.isArray(e))return E(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||I(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e,t){if(e){if("string"==typeof e)return E(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,t):void 0}}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function R(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,F(n.key),n)}}function A(e,t,r){return t&&_(e.prototype,t),r&&_(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function M(e,t,r){return(t=F(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(e){var t=function(e,t){if("object"!=m(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=m(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==m(t)?t:t+""}var L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];R(this,e),M(this,"_items",new Map),this.set.apply(this,P(t))}return A(e,[{key:"items",get:function(){return this._items}},{key:"length",get:function(){return this._items.size}},{key:"set",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this._items.set(i[0],i[1])}}},{key:"get",value:function(e){return this.items.get(e)}},{key:"has",value:function(e){return this.items.has(e)}},{key:"delete",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this.items.delete(i)}}},{key:"deleteAll",value:function(){this.items.clear()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0,i=new e,a=T(this.items.entries());try{for(a.s();!(n=a.n()).done;){var c=j(n.value,2),u=c[0],s=c[1];if(i.length>=o)break;s[t]===r&&i.set([u,s])}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e;return t._items=this._items,t}}])}(),C=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];R(this,e),M(this,"_items",void 0),this.id=t,this._items=new L,this.set.apply(this,P(r))}return A(e,[{key:"items",get:function(){return Array.from(this._items.items.values())}},{key:"length",get:function(){return this._items.length}},{key:"set",value:function(){for(var e,t=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this._items).set.apply(e,P(n.map(function(e){return[t.getId(e),e]})))}},{key:"get",value:function(e){return this._items.get(e)}},{key:"getAt",value:function(e){return this.items[e]}},{key:"has",value:function(e){return this._items.has(e)}},{key:"delete",value:function(){var e;(e=this._items).delete.apply(e,arguments)}},{key:"deleteAll",value:function(){this._items.deleteAll()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new e(this.id),a=T(this.items);try{for(a.s();!(n=a.n()).done;){var c=n.value;if(o&&i.length===o)break;c[t]===r&&i.set(c)}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e(this.id);return t._items=this._items,t}},{key:"getId",value:function(e){return"function"==typeof this.id?this.id(e):e[this.id]}}])}(),x=function(e){function t(){var e,r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return R(this,t),M(r=v(this,t),"eventTarget",void 0),r.eventTarget=new a,(e=r).set.apply(e,P(n)),r}return S(t,e),A(t,[{key:"set",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"set",this,3)(r),this.eventTarget.emit("change",{setItems:r.map(function(e){return e[0]})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){if(this.length){var e=Array.from(this._items.keys());g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:Array.from(e)})}}},{key:"createMirror",value:function(){var e=new t;return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(L),G=function(e){function t(e){var r,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return R(this,t),M(n=v(this,t,[e]),"eventTarget",void 0),n.eventTarget=new a,(r=n).set.apply(r,P(o)),n}return S(t,e),A(t,[{key:"set",value:function(){for(var e=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];n.length&&(g(t,"set",this,3)(n),this.eventTarget.emit("change",{setItems:n.map(function(t){return e.getId(t)})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){var e=this;if(this.length){var r=this.items.map(function(t){return e.getId(t)});g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:r})}}},{key:"createMirror",value:function(){var e=new t(this.id);return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(C);function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}function U(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,J(n.key),n)}}function N(e,t,r){return t&&U(e.prototype,t),r&&U(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function B(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function W(e,t,r){return(t=J(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function J(e){var t=function(e,t){if("object"!=D(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==D(t)?t:t+""}var H=N(function e(){var t=this;B(this,e),W(this,"promise",void 0),W(this,"resolve",void 0),this.promise=new Promise(function(e){return t.resolve=e})}),$=function(){return N(function e(){B(this,e),W(this,"promises",new L)},[{key:"register",value:function(e,t){this.promises.set([t,e])}},{key:"registerByFunction",value:function(e,t){this.register(e(),t)}},{key:"get",value:function(e){return this.promises.get(e)}},{key:"has",value:function(e){return this.promises.has(e)}},{key:"notExist",value:function(e){return!this.has(e)}},{key:"forget",value:function(){var e;(e=this.promises).delete.apply(e,arguments)}},{key:"forgetAll",value:function(){this.promises.deleteAll()}}])}();function Q(e){return Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Q(e)}function V(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?V(Object(r),!0).forEach(function(t){fe(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function q(e,t,r,n){var o=K(ue(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function K(){return K="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=ue(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},K.apply(null,arguments)}function Y(e){return function(e){if(Array.isArray(e))return X(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?X(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Z(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ee(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ee(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ee(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ee(f,"constructor",s),ee(s,"constructor",u),u.displayName="GeneratorFunction",ee(s,o,"GeneratorFunction"),ee(f),ee(f,o,"Generator"),ee(f,n,function(){return this}),ee(f,"toString",function(){return"[object Generator]"}),(Z=function(){return{w:i,m:h}})()}function ee(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ee=function(e,t,r,n){function i(t,r){ee(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ee(e,t,r,n)}function te(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function re(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){te(i,n,o,a,c,"next",e)}function c(e){te(i,n,o,a,c,"throw",e)}a(void 0)})}}function ne(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function oe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,he(n.key),n)}}function ie(e,t,r){return t&&oe(e.prototype,t),r&&oe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function ae(e,t,r){return t=ue(t),function(e,t){if(t&&("object"==Q(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ce()?Reflect.construct(t,r||[],ue(e).constructor):t.apply(e,r))}function ce(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ce=function(){return!!e})()}function ue(e){return ue=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ue(e)}function se(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&le(e,t)}function le(e,t){return le=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},le(e,t)}function fe(e,t,r){return(t=he(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e){var t=function(e,t){if("object"!=Q(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Q(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Q(t)?t:t+""}var pe=function(e){return e[e.LIVE=0]="LIVE",e[e.LATEST=1]="LATEST",e[e.PAST=2]="PAST",e[e.OLDEST=3]="OLDEST",e}({}),de=function(e){function t(e,r,n){var o,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return ne(this,t),fe(o=ae(this,t,["id"]),"WindowState",pe),o.roomId=e,o.topicId=r,o.tracker=n,o.internalState.traverseLock=!1,i&&(o.tracker.client.on("NewMessage",function(e){return o.handleNewMessage(e)}),o.tracker.client.on("MessagesRedacted",function(e){return o.handleMessagesRedacted(e)})),o}return se(t,e),ie(t,[{key:"createMirror",value:function(){var e=new t(this.roomId,this.topicId,this.tracker,!1);return e.eventTarget=this.eventTarget,e._items=this._items,e.internalState=this.internalState,e}},{key:"isTraverseLocked",get:function(){return this.internalState.traverseLock}},{key:"setTraverseLock",value:(y=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(this.internalState.traverseLock=r,!r||this.state===pe.LIVE||this.state===pe.LATEST){e.n=1;break}return e.n=1,q(t,"resetToLatest",this,3)([]);case 1:return e.a(2)}},e,this)})),function(e){return y.apply(this,arguments)})},{key:"resetToLatest",value:(d=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"resetToLatest",this,3)([]))}},e,this)})),function(){return d.apply(this,arguments)})},{key:"fetchNext",value:(p=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchNext",this,3)([]))}},e,this)})),function(){return p.apply(this,arguments)})},{key:"fetchPrevious",value:(h=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchPrevious",this,3)([]))}},e,this)})),function(){return h.apply(this,arguments)})},{key:"jumpTo",value:(f=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"jumpTo",this,3)([r]))}},e,this)})),function(e){return f.apply(this,arguments)})},{key:"_updateMessageReference",value:function(e){var t=this.get(e.refMessage.id);t&&this.set(z(z({},t),{},{topicRef:e.id}))}},{key:"fetchItemsAfter",value:(l=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(this.length-1))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},after:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return l.apply(this,arguments)})},{key:"fetchItemsAround",value:(s=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},around:t,limit:this.internalState.fetchLimit});case 1:if(!(r=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(r.error.message));case 2:return e.a(2,r.data.messages)}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"fetchItemsBefore",value:(u=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(0))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},before:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return u.apply(this,arguments)})},{key:"fetchLatestItems",value:(c=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},limit:this.internalState.fetchLimit});case 1:if(!(t=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(t.error.message));case 2:return e.a(2,t.data.messages)}},e,this)})),function(){return c.apply(this,arguments)})},{key:"getTopic",value:(a=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.getTopics(this.roomId,[this.topicId]);case 1:return e.a(2,e.v.get(this.topicId))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"getLatestMessageId",value:(i=re(Z().m(function e(){var t,r,n,o,i;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getTopic();case 1:if(o=t=e.v,n=null===o){e.n=2;break}n=void 0===t;case 2:if(r=n){e.n=3;break}r=null===(t=t.lastMessage)||void 0===t;case 3:if(!r){e.n=4;break}i=void 0,e.n=5;break;case 4:i=t.id;case 5:return e.a(2,i)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"isLatestItemLoaded",value:(o=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getLatestMessageId();case 1:return t=e.v,e.a(2,!t||this.has(t))}},e,this)})),function(){return o.apply(this,arguments)})},{key:"handleNewMessage",value:(n=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:[pe.LATEST,pe.LIVE].includes(this.state)&&t.message.location.roomId===this.roomId&&t.message.location.topicId===this.topicId&&(r=this.state,this.addItems([t.message],"tail"),this.emitChangeWithDiff(!0,r));case 1:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleMessagesRedacted",value:(r=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:if(t.location.topicId===this.topicId&&t.location.roomId===this.roomId){e.n=1;break}return e.a(2);case 1:if(r=this.items.filter(function(e){return e.topicRef&&t.ids.includes(e.id)}).map(function(e){return e.topicRef}),this.delete.apply(this,Y(t.ids)),0!==this.length){e.n=2;break}return e.n=2,this.resetToLatest();case 2:r.length>0&&this.eventTarget.emit("reftopicsdeleted",r);case 3:return e.a(2)}},e,this)})),function(e){return r.apply(this,arguments)})}]);var r,n,o,i,a,c,u,s,l,f,h,p,d,y}(function(e){function t(){var e;ne(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return fe(e=ae(this,t,[].concat(n)),"internalState",{current:pe.LIVE,ongoing:void 0,limit:1e3,retainRatio:1,fetchLimit:50,lastFetchCount:0,oldestId:null}),e}return se(t,e),ie(t,[{key:"state",get:function(){return this.internalState.current}},{key:"fetchLimit",get:function(){return this.internalState.fetchLimit},set:function(e){this.internalState.fetchLimit=e}},{key:"limit",get:function(){return this.internalState.limit},set:function(e){this.internalState.limit=e}},{key:"retainRatio",get:function(){return this.internalState.retainRatio},set:function(e){this.internalState.retainRatio=e}},{key:"hasLatest",get:function(){return[pe.LATEST,pe.LIVE].includes(this.state)}},{key:"hasOldest",get:function(){return this.state===pe.OLDEST||this.state===pe.LATEST&&this.length<this.fetchLimit||null!==this.internalState.oldestId&&this.has(this.internalState.oldestId)}},{key:"resetToLatest",value:(a=re(Z().m(function e(){var t,r;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&this.internalState.current!==pe.LATEST){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.LATEST,e.p=2,e.n=3,this.fetchLatestItems();case 3:t=e.v,this.internalState.lastFetchCount=t.length;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:this._items.deleteAll(),this.addItems(t,"tail"),this.internalState.current=pe.LATEST,this.emitChangeWithDiff(!0,r);case 6:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return a.apply(this,arguments)})},{key:"fetchPrevious",value:(i=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasOldest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsBefore();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=6;break}return e.a(2,this.resetToLatest());case 6:if(t.length){e.n=8;break}return n=this.getAt(0),this.internalState.oldestId=n?this.getId(n):null,e.n=7,this.refreshFetchedState();case 7:return this.internalState.current===pe.PAST&&(this.internalState.current=pe.OLDEST),this.emitChangeWithDiff(!1,r),e.a(2);case 8:return this.addItems(t,"head"),e.n=9,this.refreshFetchedState();case 9:this.emitChangeWithDiff(!0,r);case 10:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return i.apply(this,arguments)})},{key:"fetchNext",value:(o=re(Z().m(function e(){var t,r;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasLatest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsAfter();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=7;break}return e.n=6,this.resetToLatest();case 6:return e.a(2);case 7:if(!t.length){e.n=9;break}return this.addItems(t,"tail"),e.n=8,this.refreshFetchedState();case 8:return this.emitChangeWithDiff(!0,r),e.a(2);case 9:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return o.apply(this,arguments)})},{key:"jumpTo",value:(n=re(Z().m(function e(t){var r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this._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:r=e.v,this.internalState.lastFetchCount=r?r.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(r){e.n=6;break}return e.a(2);case 6:this._items.deleteAll(),this.addItems(r,"tail"),this.internalState.current=pe.PAST,this.emitChangeWithDiff(!0,n);case 7:return e.a(2)}},e,this,[[2,,4,5]])})),function(e){return n.apply(this,arguments)})},{key:"refreshFetchedState",value:(r=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.isLatestItemLoaded();case 1:if(!e.v){e.n=2;break}t=pe.LATEST,e.n=3;break;case 2:t=pe.PAST;case 3:this.internalState.current=t;case 4:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"addItems",value:function(e,t){var r,n,o=this;"head"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(e),Y(this.items)),"tail")),"tail"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(this.items),Y(e)),"head")),this._items.deleteAll(),(r=this._items).set.apply(r,Y(n.map(function(e){return[o.getId(e),e]})))}},{key:"emitChangeWithDiff",value:function(e,t){(e||t!==this.state)&&this.eventTarget.emit("change",{setItems:Array.from(this._items.items.keys())})}},{key:"trimItemsArrayToLimit",value:function(e,t){var r=this.limit;if(null===r||e.length<=r)return e;var n=Math.floor(r*this.internalState.retainRatio);return"head"===t?e.slice(-n):"tail"===t?e.slice(0,n):e}}]);var r,n,o,i,a}(G));function ye(e){return ye="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ye(e)}function me(e){return function(e){if(Array.isArray(e))return ge(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||be(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ve(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||be(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function be(e,t){if(e){if("string"==typeof e)return ge(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ge(e,t):void 0}}function ge(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function we(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ke(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ke(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ke(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ke(f,"constructor",s),ke(s,"constructor",u),u.displayName="GeneratorFunction",ke(s,o,"GeneratorFunction"),ke(f),ke(f,o,"Generator"),ke(f,n,function(){return this}),ke(f,"toString",function(){return"[object Generator]"}),(we=function(){return{w:i,m:h}})()}function ke(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ke=function(e,t,r,n){function i(t,r){ke(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ke(e,t,r,n)}function Se(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Oe(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Se(i,n,o,a,c,"next",e)}function c(e){Se(i,n,o,a,c,"throw",e)}a(void 0)})}}function je(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Pe(n.key),n)}}function Te(e,t,r){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pe(e){var t=function(e,t){if("object"!=ye(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ye(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ye(t)?t:t+""}var Ie=function(){return e=function e(t,r){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Te(this,"historyWindows",new L),Te(this,"traverseLock",!1),this.room=t,this.tracker=r,this.tracker.client.on("RoomUpdated",function(e){return n.handleRoomUpdated(e)}),this.tracker.client.on("NewTopic",function(e){return n.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return n.handleTopicDeleted(e)}),this.updateTraverseLock(this.room),this.room.defaultTopic&&this.createHistoryWindowForTopic(this.room.defaultTopic)},t=[{key:"getMessagesWindow",value:(o=Oe(we().m(function e(t){var r,n,o=arguments;return we().w(function(e){for(;;)switch(e.n){case 0:if(r=o.length>1&&void 0!==o[1]&&o[1],this.historyWindows.has(t)||r){e.n=2;break}return e.n=1,this.tracker.rooms.getTopics(this.room.id,[t]);case 1:(n=e.v.get(t))&&this.createHistoryWindowForTopic(n);case 2:return e.a(2,this.historyWindows.get(t))}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoomUpdated",value:(n=Oe(we().m(function e(t){var r,n,o,i;return we().w(function(e){for(;;)switch(e.n){case 0:if(this.room.id!==t.room.id){e.n=3;break}this.room=t.room,this.updateTraverseLock(t.room),t.room.defaultTopic&&this.createHistoryWindowForTopic(t.room.defaultTopic),r=0,n=Array.from(this.historyWindows.items);case 1:if(!(r<n.length)){e.n=3;break}return o=ve(n[r],2),i=o[1],e.n=2,i.setTraverseLock(this.traverseLock);case 2:r++,e.n=1;break;case 3:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleNewTopic",value:function(e){this.room.id===e.roomId&&this.createHistoryWindowForTopic(e.topic)}},{key:"handleTopicDeleted",value:function(e){this.room.id===e.location.roomId&&this.historyWindows.delete(e.location.topicId)}},{key:"createHistoryWindowForTopic",value:function(e){var t=this;if(!this.historyWindows.has(e.id)){var r=new de(this.room.id,e.id,this.tracker);if(r.setTraverseLock(this.traverseLock),this.historyWindows.set([e.id,r]),r.on("reftopicsdeleted",function(e){var r,n,o=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=be(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}(e);try{for(o.s();!(n=o.n()).done;){var i=n.value;t.historyWindows.delete(i)}}catch(e){o.e(e)}finally{o.f()}(r=t.tracker.rooms)._deleteTopicsFromRoom.apply(r,[t.room.id].concat(me(e)))}),e.refMessage){var n=this.historyWindows.get(e.refMessage.location.topicId);null==n||n._updateMessageReference(e)}}}},{key:"updateTraverseLock",value:function(e){this.traverseLock="Ephemeral"===e.history.mode}}],t&&je(e.prototype,t),r&&je(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Ee(e){return Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ee(e)}function Re(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return _e(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(_e(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,_e(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,_e(f,"constructor",s),_e(s,"constructor",u),u.displayName="GeneratorFunction",_e(s,o,"GeneratorFunction"),_e(f),_e(f,o,"Generator"),_e(f,n,function(){return this}),_e(f,"toString",function(){return"[object Generator]"}),(Re=function(){return{w:i,m:h}})()}function _e(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}_e=function(e,t,r,n){function i(t,r){_e(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},_e(e,t,r,n)}function Ae(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Me(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ae(i,n,o,a,c,"next",e)}function c(e){Ae(i,n,o,a,c,"throw",e)}a(void 0)})}}function Fe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Ce(n.key),n)}}function Le(e,t,r){return(t=Ce(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ce(e){var t=function(e,t){if("object"!=Ee(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ee(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ee(t)?t:t+""}var xe=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Le(this,"roomHistories",new L),Le(this,"deferredSession",new H),this.tracker=t,this.tracker.client.on("Session",function(e){return r.handleSession(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)})},t=[{key:"getRoomHistory",value:(o=Me(Re().m(function e(t){return Re().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roomHistories.get(t))}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"_resolveLastMessage",value:(n=Me(Re().m(function e(t){var r,n,o;return Re().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getRoomHistory(t.roomId).then(function(e){return null==e?void 0:e.getMessagesWindow(t.topicId,!0)}).then(function(e){return(null==e?void 0:e.hasLatest)&&e.getAt(e.length-1)});case 1:if(r=e.v){e.n=3;break}return e.n=2,this.tracker.client.send("GetMessages",{location:t,limit:1});case 2:o=e.v,r=null===(n=o.data)||void 0===n?void 0:n.messages[0];case 3:return e.a(2,r||null)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"createHistoryForNewRoom",value:function(e){this.roomHistories.set([e.id,new Ie(e,this.tracker)])}},{key:"handleRoomDeleted",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleRoomJoin",value:function(e){this.createHistoryForNewRoom(e.room)}},{key:"handleRoomLeft",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleSession",value:function(e){var t=this;this.roomHistories.deleteAll(),e.state.rooms.forEach(function(e){return t.createHistoryForNewRoom(e)}),this.deferredSession.resolve()}}],t&&Fe(e.prototype,t),r&&Fe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Ge(e){return Ge="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ge(e)}function De(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ue(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?De(Object(r),!0).forEach(function(t){Ze(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):De(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Ne(e){return function(e){if(Array.isArray(e))return Je(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||We(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Be(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=We(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function We(e,t){if(e){if("string"==typeof e)return Je(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Je(e,t):void 0}}function Je(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function He(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return $e(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):($e(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,$e(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,$e(f,"constructor",s),$e(s,"constructor",u),u.displayName="GeneratorFunction",$e(s,o,"GeneratorFunction"),$e(f),$e(f,o,"Generator"),$e(f,n,function(){return this}),$e(f,"toString",function(){return"[object Generator]"}),(He=function(){return{w:i,m:h}})()}function $e(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}$e=function(e,t,r,n){function i(t,r){$e(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},$e(e,t,r,n)}function Qe(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Ve(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Qe(i,n,o,a,c,"next",e)}function c(e){Qe(i,n,o,a,c,"throw",e)}a(void 0)})}}function ze(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,et(n.key),n)}}function qe(e,t,r){return t=Ye(t),function(e,t){if(t&&("object"==Ge(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Ke()?Reflect.construct(t,r||[],Ye(e).constructor):t.apply(e,r))}function Ke(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Ke=function(){return!!e})()}function Ye(e){return Ye=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Ye(e)}function Xe(e,t){return Xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Xe(e,t)}function Ze(e,t,r){return(t=et(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function et(e){var t=function(e,t){if("object"!=Ge(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ge(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ge(t)?t:t+""}var tt=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),Ze(r=qe(this,t),"followedTopics",new L),Ze(r,"followedTopicsPromises",new $),Ze(r,"deferredSession",new H),Ze(r,"summariesCache",new Map),r.tracker=e,r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),r.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),r.tracker.client.on("FollowedTopicUpdated",function(e){return r.handleFollowedTopicUpdated(e)}),r.tracker.client.on("TopicFollowed",function(e){return r.handleTopicFollowed(e)}),r.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Xe(e,t)}(t,e),r=t,n=[{key:"cacheForSpace",value:(l=Ve(He().m(function e(t){var r,n,o,i,a=this;return He().w(function(e){for(;;)switch(e.n){case 0:if(!(i=t)){e.n=2;break}return e.n=1,this.tracker.spaces.get();case 1:i=!e.v.has(t);case 2:if(!i){e.n=3;break}throw new Error("You are not in space ".concat(t));case 3:return e.n=4,this.tracker.rooms.get();case 4:if(r=e.v,(n=t?r.findBy("spaceId",t).items.map(function(e){return e.id}):r.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id})).length){e.n=5;break}return e.a(2);case 5:if(!n.every(function(e){return a.followedTopics.has(e)})){e.n=6;break}return e.a(2);case 6:return o="space_fetch_".concat(t||"spaceless"),this.followedTopicsPromises.notExist(o)&&this.followedTopicsPromises.registerByFunction(Ve(He().m(function e(){var r;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,a.tracker.client.send("GetFollowedTopics",{location:{spaceId:t}});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:a.setFollowedTopicsArray(n,r.data.followedTopics);case 3:return e.a(2)}},e)})),o),e.n=7,this.followedTopicsPromises.get(o);case 7:return e.a(2)}},e,this)})),function(e){return l.apply(this,arguments)})},{key:"getForRoom",value:(s=Ve(He().m(function e(t){var r=this;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:if(e.v.has(t)){e.n=2;break}return e.a(2,void 0);case 2:if(this.followedTopics.has(t)){e.n=3;break}return this.followedTopicsPromises.notExist(t)&&this.followedTopicsPromises.registerByFunction(Ve(He().m(function e(){var n;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetFollowedTopics",{location:{roomId:t}});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.setFollowedTopicsArray([t],n.data.followedTopics);case 3:return e.a(2)}},e)})),t),e.n=3,this.followedTopicsPromises.get(t);case 3:return e.a(2,this.followedTopics.get(t))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"ackRoom",value:(u=Ve(He().m(function e(t){var r,n,o,i,a;return He().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.getForRoom(t);case 1:if(r=e.v){e.n=2;break}return e.a(2);case 2:n=Be(r.items),e.p=3,n.s();case 4:if((o=n.n()).done){e.n=6;break}if(!(i=o.value).isUnread){e.n=5;break}return e.n=5,this.tracker.client.send("Ack",{location:i.location});case 5:e.n=4;break;case 6:e.n=8;break;case 7:e.p=7,a=e.v,n.e(a);case 8:return e.p=8,n.f(),e.f(8);case 9:return e.a(2)}},e,this,[[3,7,8,9]])})),function(e){return u.apply(this,arguments)})},{key:"summarize",value:(c=Ve(He().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b;return He().w(function(e){for(;;)switch(e.p=e.n){case 0:if(r=t.topicId?"topic:".concat(t.roomId,":").concat(t.topicId):t.roomId?"room:".concat(t.roomId):t.spaceId?"space:".concat(t.spaceId):"spaceless",!this.summariesCache.has(r)){e.n=1;break}return e.a(2,this.summariesCache.get(r));case 1:return n=[],e.n=2,this.tracker.rooms.get();case 2:if(i=e.v,!t.topicId){e.n=4;break}if(t.roomId){e.n=3;break}throw new Error("roomId is required when querying by topicId");case 3:n=[t.roomId],o=t.topicId,e.n=9;break;case 4:if(!t.roomId){e.n=5;break}n=[t.roomId],e.n=9;break;case 5:if(!t.spaceId){e.n=7;break}return e.n=6,this.cacheForSpace(t.spaceId);case 6:n=i.findBy("spaceId",t.spaceId).items.map(function(e){return e.id}),e.n=9;break;case 7:return e.n=8,this.cacheForSpace(null);case 8:n=i.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id});case 9:a=0,c=!1,u=Be(n),e.p=10,u.s();case 11:if((s=u.n()).done){e.n=22;break}return l=s.value,e.n=12,this.getForRoom(l);case 12:if(f=e.v){e.n=13;break}return e.a(3,21);case 13:h=Be(f.items),e.p=14,h.s();case 15:if((p=h.n()).done){e.n=18;break}if(y=p.value,!o||y.location.topicId===o){e.n=16;break}return e.a(3,17);case 16:y.isUnread&&(c=!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){this.followedTopics.deleteAll(),this.followedTopicsPromises.forgetAll(),this.invalidateUnreadSummaries(),this.deferredSession.resolve()}},{key:"handleNewMessage",value:function(e){this.updateLocallyFollowedTopicOnNewMessage(e)}},{key:"handleFollowedTopicUpdated",value:function(e){var t;null===(t=this.followedTopics.get(e.followedTopic.location.roomId))||void 0===t||t.set(e.followedTopic),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleTopicFollowed",value:function(e){this.setFollowedTopicsArray([e.followedTopic.location.roomId],[e.followedTopic]),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleRoomDeleted",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleRoomJoin",value:function(e){this.clearRoomFollowedTopicsStructures(e.room.id)}},{key:"handleRoomLeft",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleNewTopic",value:(a=Ve(He().m(function e(t){var r,n;return He().w(function(e){for(;;)switch(e.n){case 0:if(!this.followedTopics.has(t.roomId)){e.n=2;break}return e.n=1,this.tracker.client.send("GetFollowedTopics",{location:{roomId:t.roomId,topicId:t.topic.id}});case 1:r=e.v,(n=r.data.followedTopics[0])&&(this.followedTopics.get(t.roomId).set(n),this.invalidateUnreadSummaries(t.roomId,t.topic.id));case 2:return e.a(2)}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t;null===(t=this.followedTopics.get(e.location.roomId))||void 0===t||t.delete(e.location.topicId),this.invalidateUnreadSummaries(e.location.roomId,e.location.topicId)}},{key:"invalidateUnreadSummaries",value:function(e,t){if(e){if(this.summariesCache.delete("room:".concat(e)),t)this.summariesCache.delete("topic:".concat(e,":").concat(t));else{var r,n=Be(this.summariesCache.keys());try{for(n.s();!(r=n.n()).done;){var o=r.value;o.startsWith("topic:".concat(e,":"))&&this.summariesCache.delete(o)}}catch(e){n.e(e)}finally{n.f()}}var i,a=Be(this.summariesCache.keys());try{for(a.s();!(i=a.n()).done;){var c=i.value;(c.startsWith("space:")||"spaceless"===c)&&this.summariesCache.delete(c)}}catch(e){a.e(e)}finally{a.f()}}else this.summariesCache.clear();this.emit("change")}},{key:"invalidateUnreadSummariesForRooms",value:function(e){var t=this,r=new Set(e);e.forEach(function(e){t.summariesCache.delete("room:".concat(e))});var n,o=Be(this.summariesCache.keys());try{for(o.s();!(n=o.n()).done;){var i=n.value;if(i.startsWith("space:")||"spaceless"===i)this.summariesCache.delete(i);else if(i.startsWith("topic:")){var a=i.split(":");a.length>=2&&r.has(a[1])&&this.summariesCache.delete(i)}}}catch(e){o.e(e)}finally{o.f()}this.emit("change")}},{key:"updateLocallyFollowedTopicOnNewMessage",value:(i=Ve(He().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h;return He().w(function(e){for(;;)switch(e.n){case 0:if(r=this.followedTopics.get(t.message.location.roomId),n=null==r?void 0:r.get(t.message.location.topicId),r&&n&&"Ephemeral"!==t.message.type){e.n=1;break}return e.a(2);case 1:return e.n=2,this.tracker.getMe();case 2:if(o=e.v,t.message.author.user.id!==o.id){e.n=3;break}i={missed:0,lastAckMessageId:t.message.id},e.n=6;break;case 3:if("Text"!==t.message.type){e.n=5;break}return e.n=4,this.tracker.rooms.getMe(t.message.location.roomId);case 4:s=e.v,l=[].concat(Ne(null!==(a=null===(c=s.spaceMember)||void 0===c?void 0:c.roles)&&void 0!==a?a:[]),Ne(null!==(u=s.roles)&&void 0!==u?u:[])),f=[].concat(Ne(l.map(function(e){return"<@&".concat(e,">")})),["<@".concat(o.id,">")]),h=f.some(function(e){return t.message.content.includes(e)}),i={missed:null===n.missed?null:n.missed+1,isUnread:!0,mentionCount:n.mentionCount+(h?1:0)},e.n=6;break;case 5:i={missed:null===n.missed?null:n.missed+1,isUnread:!0};case 6:r.set(Ue(Ue({},n),i)),this.invalidateUnreadSummaries(t.message.location.roomId,t.message.location.topicId);case 7:return e.a(2)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"setFollowedTopicsArray",value:function(e,t){var r=this,n={};t.forEach(function(e){var t,r;null!==(r=n[t=e.location.roomId])&&void 0!==r||(n[t]=[]),n[e.location.roomId].push(e)}),e.forEach(function(e){var t;r.followedTopics.has(e)||r.followedTopics.set([e,new G(function(e){return e.location.topicId})]),n[e]&&(t=r.followedTopics.get(e)).set.apply(t,Ne(n[e]))}),this.invalidateUnreadSummariesForRooms(e)}},{key:"clearRoomFollowedTopicsStructures",value:function(e){this.followedTopics.delete(e),this.followedTopicsPromises.forget(e),this.invalidateUnreadSummaries(e)}}],n&&ze(r.prototype,n),o&&ze(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l}(a);function rt(e){return rt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},rt(e)}function nt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ot(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?nt(Object(r),!0).forEach(function(t){dt(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):nt(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function it(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=ct(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function at(e){return function(e){if(Array.isArray(e))return ut(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||ct(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ct(e,t){if(e){if("string"==typeof e)return ut(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ut(e,t):void 0}}function ut(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function st(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return lt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(lt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,lt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,lt(f,"constructor",s),lt(s,"constructor",u),u.displayName="GeneratorFunction",lt(s,o,"GeneratorFunction"),lt(f),lt(f,o,"Generator"),lt(f,n,function(){return this}),lt(f,"toString",function(){return"[object Generator]"}),(st=function(){return{w:i,m:h}})()}function lt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}lt=function(e,t,r,n){function i(t,r){lt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},lt(e,t,r,n)}function ft(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function ht(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){ft(i,n,o,a,c,"next",e)}function c(e){ft(i,n,o,a,c,"throw",e)}a(void 0)})}}function pt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,yt(n.key),n)}}function dt(e,t,r){return(t=yt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function yt(e){var t=function(e,t){if("object"!=rt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=rt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==rt(t)?t:t+""}var mt=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),dt(this,"messages",void 0),dt(this,"followedTopics",void 0),dt(this,"list",new G("id")),dt(this,"topics",new L),dt(this,"members",new L),dt(this,"deferredSession",new H),dt(this,"membersPromises",new $),dt(this,"topicsPromises",new $),this.tracker=t,this.messages=new xe(t),this.followedTopics=new tt(t),this.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),this.tracker.client.on("MessagesRedacted",function(e){return r.handleMessagesRedacted(e)}),this.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoined(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("TopicUpdated",function(e){return r.handleTopicUpdated(e)}),this.tracker.client.on("RoomMemberJoined",function(e){return r.handleRoomMemberJoined(e)}),this.tracker.client.on("RoomMemberLeft",function(e){return r.handleRoomMemberLeft(e)}),this.tracker.client.on("RoomMembers",function(e){return r.handleRoomMembers(e)}),this.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getMembers",value:(a=ht(st().m(function e(t){var r=this;return st().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(ht(st().m(function e(){var n;return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetRoomMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleRoomMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=ht(st().m(function e(t){var r,n;return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){var t,n;return(null!==(t=null===(n=e.user)||void 0===n?void 0:n.id)&&void 0!==t?t:e.spaceMember.user.id)===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"get",value:function(){var e=ht(st().m(function e(){return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getTopics",value:(o=ht(st().m(function e(t,r){var n,o,i,a,c,u,s,l=this;return st().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:if(null==r||!r.length){e.n=8;break}n=function(e){var r;return!(null!==(r=l.topics.get(t))&&void 0!==r&&r.has(e)||l.topicsPromises.has(t+e))},(o=r.filter(n)).length&&(i=this.tracker.client.send("GetTopics",{roomId:t,topicIds:o}).then(function(e){var t;return null===(t=l.topics.get(e.data.location.roomId))||void 0===t?void 0:t.set.apply(t,at(e.data.topics))}),o.forEach(function(e){return l.topicsPromises.register(i,t+e)})),a=it(r),e.p=2,a.s();case 3:if((c=a.n()).done){e.n=5;break}return u=c.value,e.n=4,this.topicsPromises.get(t+u);case 4:e.n=3;break;case 5:e.n=7;break;case 6:e.p=6,s=e.v,a.e(s);case 7:return e.p=7,a.f(),e.f(7);case 8:return e.a(2,this.topics.get(t))}},e,this,[[2,6,7,8]])})),function(e,t){return o.apply(this,arguments)})},{key:"_deleteTopicsFromRoom",value:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];null===(t=this.topics.get(e))||void 0===t||t.delete.apply(t,n)}},{key:"deleteRoom",value:function(){for(var e,t,r,n,o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];(e=this.list).delete.apply(e,i),(t=this.members).delete.apply(t,i),(r=this.membersPromises).forget.apply(r,i);for(var c=0,u=i;c<u.length;c++){var s,l,f,h=u[c],p=null!==(s=null===(l=this.topics.get(h))||void 0===l?void 0:l.items.map(function(e){return e.id}))&&void 0!==s?s:[];(f=this.followedTopics)._deleteByTopicIds.apply(f,[h].concat(at(p)))}(n=this.topics).delete.apply(n,i)}},{key:"deleteRoomsBySpaceId",value:function(e){this.deleteRoom.apply(this,at(this.list.findBy("spaceId",e).items.map(function(e){return e.id})))}},{key:"handleSpaceMemberUpdated",value:function(e){var t,r=it(this.list.findBy("spaceId",e.spaceId).items);try{for(r.s();!(t=r.n()).done;){var n=t.value,o=this.members.get(n.id);if(o&&o.has(e.userId)){var i=o.get(e.userId),a=e.member;a.user=i.spaceMember.user,o.set(ot(ot({},i),{},{spaceMember:a}))}}}catch(e){r.e(e)}finally{r.f()}}},{key:"handleSpaceMemberLeft",value:function(e){var t=this;this.list.findBy("spaceId",e.spaceId).items.forEach(function(r){var n;return null===(n=t.members.get(r.id))||void 0===n?void 0:n.delete(e.userId)})}},{key:"handleRoomMemberUpdated",value:function(e){var t,r;if(this.members.has(e.roomId)){var n=this.members.get(e.roomId),o=n.get(e.userId),i=e.member,a=null!==(t=null===(r=o.spaceMember)||void 0===r?void 0:r.user)&&void 0!==t?t:o.user;i.spaceMember?i.spaceMember.user=a:i.user=a,n.set(i)}}},{key:"handleSpaceDeleted",value:function(e){this.deleteRoomsBySpaceId(e.id)}},{key:"handleTopicDeleted",value:function(e){var t;this.topics.get(e.location.roomId).delete(e.location.topicId);var r=this.list.get(e.location.roomId);(null===(t=r.defaultTopic)||void 0===t?void 0:t.id)===e.location.topicId&&this.list.set(ot(ot({},r),{},{defaultTopic:null}))}},{key:"handleNewTopic",value:function(e){this.addJoinedRoomTopics(e.roomId,e.topic)}},{key:"addJoinedRoomTopics",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o;this.topics.has(e)?(o=this.topics.get(e)).set.apply(o,r):this.topics.set([e,new G("id",r)])}},{key:"handleRoomJoined",value:function(e){this.addJoinedRooms(e.room)}},{key:"handleRoomUpdated",value:function(e){this.list.has(e.room.id)&&this.list.set(e.room)}},{key:"handleRoomDeleted",value:function(e){this.deleteRoom(e.id)}},{key:"handleTopicUpdated",value:function(e){var t,r=this.list.get(e.location.roomId);if(null!==(t=this.topics.get(e.location.roomId))&&void 0!==t&&t.has(e.topic.id)&&this.topics.get(e.location.roomId).set(e.topic),r.defaultTopic.id===e.topic.id){var n=ot({},r);n.defaultTopic=e.topic,this.list.set(n)}}},{key:"addJoinedRooms",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];for(var o=0,i=r;o<i.length;o++){var a=i[o];a.defaultTopic&&this.addJoinedRoomTopics(a.id,a.defaultTopic),"Pm"===a.type&&a.recipients&&(this.handleRoomMembers({id:a.id,members:a.recipients.map(function(e){return{user:e,spaceMember:null,roles:null,customColor:null,customNick:null,extras:""}})}),this.membersPromises.register(Promise.resolve(),a.id))}(e=this.list).set.apply(e,r)}},{key:"handleRoomLeft",value:function(e){this.deleteRoom(e.id)}},{key:"handleRoomMemberJoined",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).set(e.member)}},{key:"handleRoomMemberLeft",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).delete(e.userId)}},{key:"handleRoomMembers",value:function(e){this.members.has(e.id)||this.members.set([e.id,new G(function(e){var t,r;return null!==(t=null===(r=e.user)||void 0===r?void 0:r.id)&&void 0!==t?t:e.spaceMember.user.id},e.members)])}},{key:"handleSession",value:function(e){this.list.deleteAll(),this.topics.deleteAll(),this.topicsPromises.forgetAll(),this.members.deleteAll(),this.membersPromises.forgetAll(),this.addJoinedRooms.apply(this,at(e.state.rooms)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){var t;this.members.items.forEach(function(t){var r=t.get(e.user.id);if(r){var n=ot({},r);r.user?n.user=e.user:n.spaceMember.user=e.user,t.set(n)}});var r=[];this.list.items.forEach(function(t){var n;null!==(n=t.recipients)&&void 0!==n&&n.some(function(t){return t.id===e.user.id})&&(t.recipients=t.recipients.map(function(t){return t.id===e.user.id?e.user:t}),r.push(ot({},t)))}),(t=this.list).set.apply(t,r)}},{key:"handleNewMessage",value:function(e){var t,r=this.topics.get(e.message.location.roomId),n=null==r?void 0:r.get(e.message.location.topicId);if(n){var o=ot(ot({},n),{},{messageCount:n.messageCount+1,lastMessage:e.message});r.set(o);var i=this.list.get(e.message.location.roomId);(null===(t=i.defaultTopic)||void 0===t?void 0:t.id)===e.message.location.topicId&&this.list.set(ot(ot({},i),{},{defaultTopic:o}))}}},{key:"handleMessagesRedacted",value:(n=ht(st().m(function e(t){var r,n,o,i,a;return st().w(function(e){for(;;)switch(e.n){case 0:if(r=this.topics.get(t.location.roomId),!(n=null==r?void 0:r.get(t.location.topicId))){e.n=4;break}if(!((o=Math.max(n.messageCount-t.ids.length,0))>0)){e.n=2;break}return e.n=1,this.messages._resolveLastMessage(t.location);case 1:a=e.v,e.n=3;break;case 2:a=null;case 3:i=a,r.set(ot(ot({},n),{},{messageCount:o,lastMessage:i}));case 4:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})}],t&&pt(e.prototype,t),r&&pt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a}();function vt(e){var t,r;return null!==(t=e.user)&&void 0!==t?t:null===(r=e.spaceMember)||void 0===r?void 0:r.user}function bt(e){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},bt(e)}function gt(e){return function(e){if(Array.isArray(e))return wt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return wt(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wt(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function kt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function St(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?kt(Object(r),!0).forEach(function(t){Et(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):kt(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Ot(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return jt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(jt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,jt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,jt(f,"constructor",s),jt(s,"constructor",u),u.displayName="GeneratorFunction",jt(s,o,"GeneratorFunction"),jt(f),jt(f,o,"Generator"),jt(f,n,function(){return this}),jt(f,"toString",function(){return"[object Generator]"}),(Ot=function(){return{w:i,m:h}})()}function jt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}jt=function(e,t,r,n){function i(t,r){jt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},jt(e,t,r,n)}function Tt(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Pt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Tt(i,n,o,a,c,"next",e)}function c(e){Tt(i,n,o,a,c,"throw",e)}a(void 0)})}}function It(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Rt(n.key),n)}}function Et(e,t,r){return(t=Rt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Rt(e){var t=function(e,t){if("object"!=bt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==bt(t)?t:t+""}var _t=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Et(this,"list",new G("id")),Et(this,"roles",new L),Et(this,"rooms",new L),Et(this,"roomIdToSpaceId",new L),Et(this,"members",new L),Et(this,"deferredSession",new H),Et(this,"roomsPromises",new $),Et(this,"membersPromises",new $),this.tracker=t,this.tracker.client.on("NewRoom",function(e){return r.handleNewRoom(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceUpdated",function(e){return r.handleSpaceUpdated(e)}),this.tracker.client.on("SpaceJoined",function(e){return r.handleSpaceJoined(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceMemberJoined",function(e){return r.handleSpaceMemberJoined(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMembers",function(e){return r.handleSpaceMembers(e)}),this.tracker.client.on("SpaceRooms",function(e){return r.handleSpaceRooms(e)}),this.tracker.client.on("RoomSummaryUpdated",function(e){return r.handleRoomSummaryUpdated(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("NewRole",function(e){return r.handleNewRole(e)}),this.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),this.tracker.client.on("RoleUpdated",function(e){return r.handleRoleUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"get",value:function(){var e=Pt(Ot().m(function e(){return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getRoles",value:(u=Pt(Ot().m(function e(t){return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roles.get(t))}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"getRooms",value:(c=Pt(Ot().m(function e(t){var r=this;return Ot().w(function(e){for(;;)switch(e.n){case 0:return this.roomsPromises.notExist(t)&&this.roomsPromises.registerByFunction(Pt(Ot().m(function e(){var n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceRooms",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceRooms(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.roomsPromises.get(t);case 1:return e.a(2,this.rooms.get(t))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getMembers",value:(a=Pt(Ot().m(function e(t){var r=this;return Ot().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(Pt(Ot().m(function e(){var n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=Pt(Ot().m(function e(t){var r,n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){return e.user.id===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"handleNewRole",value:function(e){var t=this.roles.get(e.spaceId);t.set(e.role),this.list.get(e.spaceId).roles=t.items}},{key:"handleNewRoom",value:function(e){var t;null===(t=this.rooms.get(e.spaceId))||void 0===t||t.set(e.summary),this.roomIdToSpaceId.set([e.summary.id,e.spaceId])}},{key:"handleRoomUpdated",value:function(e){if(e.room.spaceId&&this.rooms.has(e.room.spaceId)){var t=this.rooms.get(e.room.spaceId);t.set(St(St({},t.get(e.room.id)),{},{name:e.room.name,description:e.room.description}))}}},{key:"handleRoomDeleted",value:(o=Pt(Ot().m(function e(t){var r,n,o,i;return Ot().w(function(e){for(;;)switch(e.n){case 0:if(n=this.roomIdToSpaceId.get(t.id),this.roomIdToSpaceId.delete(t.id),n){e.n=1;break}return e.a(2);case 1:o=this.list.get(n),i=!1,null===(r=this.rooms.get(n))||void 0===r||r.delete(t.id),o.systemRoom===t.id&&(o.systemRoom=null,i=!0),o.defaultRooms.includes(t.id)&&(o.defaultRooms=o.defaultRooms.filter(function(e){return e!==t.id}),i=!0),i&&this.list.set(o);case 2:return e.a(2)}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoleDeleted",value:function(e){var t=this.roles.get(e.spaceId);t.delete(e.id),this.list.get(e.spaceId).roles=t.items}},{key:"handleSpaceUpdated",value:function(e){this.list.set(e.space)}},{key:"handleSpaceDeleted",value:function(e){var t,r,n,o=null!==(t=null===(r=this.rooms.get(e.id))||void 0===r?void 0:r.items.map(function(e){return e.id}))&&void 0!==t?t:[];(n=this.roomIdToSpaceId).delete.apply(n,gt(o)),this.roles.delete(e.id),this.members.delete(e.id),this.membersPromises.forget(e.id),this.rooms.delete(e.id),this.roomsPromises.forget(e.id),this.list.delete(e.id)}},{key:"handleSpaceJoined",value:function(e){this.addJoinedSpaces(e.space)}},{key:"addJoinedSpaces",value:function(){for(var e,t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this.roles).set.apply(e,gt(n.map(function(e){return[e.id,new G("id",e.roles)]}))),(t=this.list).set.apply(t,n)}},{key:"handleSpaceMemberJoined",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).set(e.member)}},{key:"handleSpaceMemberLeft",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).delete(e.userId)}},{key:"handleSpaceMembers",value:function(e){this.members.has(e.id)||this.members.set([e.id,new G(function(e){return null==e?void 0:e.user.id},e.members)])}},{key:"handleSpaceRooms",value:function(e){var t=this;this.rooms.has(e.id)||(this.rooms.set([e.id,new G("id",e.summaries)]),e.summaries.forEach(function(r){return t.roomIdToSpaceId.set([r.id,e.id])}))}},{key:"handleRoomSummaryUpdated",value:(n=Pt(Ot().m(function e(t){var r,n,o,i,a;return Ot().w(function(e){for(;;)switch(e.n){case 0:if(r=this.roomIdToSpaceId.get(t.summary.id),n=this.roomsPromises.get(r),!r||!n){e.n=2;break}return e.n=1,n;case 1:o=this.rooms.get(r),i=o.get(t.summary.id),a=i?St(St({},i),t.summary):t.summary,o.set(a);case 2:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleSpaceMemberUpdated",value:function(e){if(this.members.has(e.spaceId)){var t=this.members.get(e.spaceId),r=t.get(e.userId);t.set(St(St({},e.member),{},{user:r.user}))}}},{key:"handleRoleUpdated",value:function(e){var t,r=this.roles.get(e.spaceId),n=r.get(e.role.id),o=e.role,i=[o];n.priority!==o.priority&&i.push.apply(i,gt(function(e,t,r){var n=r.priority-t.priority>0,o=!n,i=[];return e.forEach(function(e){e.id!==r.id&&(n&&t.priority<=e.priority&&(e.priority--,i.push(e)),o&&r.priority<=e.priority&&(e.priority++,i.push(e)))}),i}(r.items,n,o))),(t=this.roles.get(e.spaceId)).set.apply(t,i)}},{key:"handleSession",value:function(e){this.list.deleteAll(),this.roles.deleteAll(),this.rooms.deleteAll(),this.roomsPromises.forgetAll(),this.members.deleteAll(),this.membersPromises.forgetAll(),this.roomIdToSpaceId.deleteAll(),this.addJoinedSpaces.apply(this,gt(e.state.spaces)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){this.members.items.forEach(function(t){var r=t.get(e.user.id);r&&t.set(St(St({},r),{},{user:e.user}))})}}],t&&It(e.prototype,t),r&&It(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a,c,u}();function At(e){return At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},At(e)}function Mt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,xt(n.key),n)}}function Ft(e,t,r){return t&&Mt(e.prototype,t),r&&Mt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Lt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ct(e,t,r){return(t=xt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function xt(e){var t=function(e,t){if("object"!=At(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=At(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==At(t)?t:t+""}var Gt=function(e){return e[e.Global=0]="Global",e[e.Space=1]="Space",e[e.Room=2]="Room",e[e.Topic=3]="Topic",e}({}),Dt=Ft(function e(){Lt(this,e),Ct(this,"value",void 0),Ct(this,"maxLayer",void 0)}),Ut=function(){return Ft(function e(){Lt(this,e)},null,[{key:"getNames",value:function(){return Object.keys(this.list)}},{key:"getByName",value:function(e){return this.list[e]}},{key:"canBeDefinedOnLayer",value:function(e,t){if(!this.getByName(e))throw new Error("Invalid permission name: ".concat(e));return t<=this.getByName(e).maxLayer}}])}();function Nt(e){return Nt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Nt(e)}function Bt(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Ht(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function Wt(e){return function(e){if(Array.isArray(e))return $t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Ht(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Jt(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||Ht(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ht(e,t){if(e){if("string"==typeof e)return $t(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$t(e,t):void 0}}function $t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Qt(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Vt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Vt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Vt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Vt(f,"constructor",s),Vt(s,"constructor",u),u.displayName="GeneratorFunction",Vt(s,o,"GeneratorFunction"),Vt(f),Vt(f,o,"Generator"),Vt(f,n,function(){return this}),Vt(f,"toString",function(){return"[object Generator]"}),(Qt=function(){return{w:i,m:h}})()}function Vt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Vt=function(e,t,r,n){function i(t,r){Vt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Vt(e,t,r,n)}function zt(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function qt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){zt(i,n,o,a,c,"next",e)}function c(e){zt(i,n,o,a,c,"throw",e)}a(void 0)})}}function Kt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,rr(n.key),n)}}function Yt(e,t,r){return t=Zt(t),function(e,t){if(t&&("object"==Nt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Xt()?Reflect.construct(t,r||[],Zt(e).constructor):t.apply(e,r))}function Xt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Xt=function(){return!!e})()}function Zt(e){return Zt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Zt(e)}function er(e,t){return er=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},er(e,t)}function tr(e,t,r){return(t=rr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function rr(e){var t=function(e,t){if("object"!=Nt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Nt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Nt(t)?t:t+""}Ct(Ut,"list",{Root:{value:1,maxLayer:Gt.Room},CreateSpaces:{value:2,maxLayer:Gt.Global},ManageSpace:{value:4,maxLayer:Gt.Space},ManageRoles:{value:8,maxLayer:Gt.Space},CreateTopics:{value:32,maxLayer:Gt.Room},ManageTopic:{value:64,maxLayer:Gt.Topic},ManageMemberProfiles:{value:128,maxLayer:Gt.Space},ManageMemberRoles:{value:256,maxLayer:Gt.Room},CreateMessages:{value:512,maxLayer:Gt.Topic},ManagePermissions:{value:1024,maxLayer:Gt.Topic},CreateRooms:{value:2048,maxLayer:Gt.Space},ManageRoom:{value:4096,maxLayer:Gt.Room},CreateEmoticons:{value:8192,maxLayer:Gt.Space},ManageEmoticons:{value:16384,maxLayer:Gt.Space},ManageBans:{value:32768,maxLayer:Gt.Room},Kick:{value:65536,maxLayer:Gt.Room},ChangeOwnNick:{value:1<<17,maxLayer:Gt.Space},ChangeOwnColor:{value:1<<18,maxLayer:Gt.Room},RedactMessages:{value:1<<19,maxLayer:Gt.Topic}});var nr=function(e,t){return[e.spaceId,e.roomId,e.topicId,null==t?void 0:t.type,null==t?void 0:t.userId,null==t?void 0:t.roleId].filter(Boolean).join("/")},or=function(e){return nr(e.location,e.target)},ir=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),tr(r=Yt(this,t),"overwrites",new L),tr(r,"overwritesPromises",new $),r.tracker=e,r.tracker.client.on("PermissionOverwrites",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("PermissionOverwritesUpdated",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),r.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),r.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&er(e,t)}(t,e),r=t,n=[{key:"getOverwrites",value:(f=qt(Qt().m(function e(t,r){var n,o=this;return Qt().w(function(e){for(;;)switch(e.n){case 0:return this.validateLocation(t),n=nr(t,r),this.overwritesPromises.notExist(n)&&this.overwritesPromises.registerByFunction(qt(Qt().m(function e(){var n;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.tracker.client.send("GetPermissionOverwrites",{location:t,target:r});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:o.handlePermissionOverwrites(n.data);case 3:return e.a(2)}},e)})),n),e.n=1,this.overwritesPromises.get(n);case 1:return e.a(2,this.overwrites.get(n))}},e,this)})),function(e,t){return f.apply(this,arguments)})},{key:"check",value:(l=qt(Qt().m(function e(t,r){var n,o;return Qt().w(function(e){for(;;)switch(e.n){case 0:if(t.length){e.n=1;break}throw new Error("Permission names array cannot be empty");case 1:return e.n=2,this.calculatePermissions(r);case 2:return n=e.v,o=[],t.forEach(function(e){~n&Ut.getByName(e).value&&o.push(e)}),e.a(2,{ok:0===o.length,hasAll:0===o.length,hasAny:o.length<t.length,missing:o})}},e,this)})),function(e,t){return l.apply(this,arguments)})},{key:"calculatePermissions",value:(s=qt(Qt().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b,g,w,k,S,O,j,T,P;return Qt().w(function(e){for(;;)switch(e.n){case 0:if(!t.roomId){e.n=2;break}return e.n=1,this.tracker.rooms.get();case 1:v=e.v.get(t.roomId),e.n=3;break;case 2:v=null;case 3:return c=v,t={spaceId:null!==(r=t.spaceId)&&void 0!==r?r:null==c?void 0:c.spaceId,roomId:t.roomId,topicId:t.topicId},this.validateLocation(t),e.n=4,this.tracker.getMe();case 4:return u=e.v.id,e.n=5,this.fetchMembersOrFail(t);case 5:if(s=e.v,l=Jt(s,2),f=l[0],h=l[1],p=[].concat(Wt(null!==(n=null==f?void 0:f.roles)&&void 0!==n?n:[]),Wt(null!==(o=null==h?void 0:h.roles)&&void 0!==o?o:[])),d=[this.getOverwrites({},{type:"User",userId:u}).then(function(e){return e.overwrites})],!(b=t.spaceId)){e.n=9;break}return e.n=6,this.tracker.spaces.get();case 6:if(k=i=e.v,!(w=null!==k)){e.n=7;break}w=void 0!==i;case 7:if(!(g=w)){e.n=8;break}g=i.has(t.spaceId);case 8:b=g;case 9:if(!b){e.n=10;break}y={spaceId:t.spaceId},d.push(this.collectRoleOverwrites(y,p)),d.push(this.getOverwrites(y,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 10:if(c&&(m={spaceId:t.spaceId,roomId:t.roomId},p.length&&d.push(this.collectRoleOverwrites(m,p)),d.push(this.getOverwrites(m,{type:"User",userId:u}).then(function(e){return e.overwrites}))),!(S=t.topicId)){e.n=14;break}return e.n=11,this.tracker.rooms.getTopics(t.roomId);case 11:if(T=a=e.v,!(j=null!==T)){e.n=12;break}j=void 0!==a;case 12:if(!(O=j)){e.n=13;break}O=a.has(t.topicId);case 13:S=O;case 14:if(!S){e.n=15;break}p.length&&d.push(this.collectRoleOverwrites(t,p)),d.push(this.getOverwrites(t,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 15:return P=this,e.n=16,Promise.all(d);case 16:return e.a(2,P.resolveOverwritesHierarchy.call(P,e.v))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"handlePermissionOverwrites",value:function(e){this.overwrites.set([or(e),e]),this.emit("change")}},{key:"handleSpaceDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr({spaceId:e.id}));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleRoomDeleted",value:(u=qt(Qt().m(function e(t){var r,n,o;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:(r=e.v.get(t.id))&&(o=this.deleteOverwritesByIdPrefix(nr({spaceId:r.spaceId,roomId:r.id})),(n=this.overwritesPromises).forget.apply(n,Wt(o)));case 2:return e.a(2)}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr(e.location));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleRoleDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr({spaceId:e.spaceId},{type:"Role",roleId:e.id}));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleSpaceMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"handleRoomMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"deleteOverwritesByIdPrefix",value:function(e){var t=this,r=[];return this.overwrites.items.forEach(function(n){var o=or(n);o.startsWith(e)&&(r.push(o),t.overwrites.delete(o))}),r}},{key:"collectRoleOverwrites",value:(c=qt(Qt().m(function e(t,r){var n,o=this;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all(r.map(function(e){return o.getOverwrites(t,{type:"Role",roleId:e})}));case 1:return n=e.v,e.a(2,this.resolveOverwritesFromRolesByOrder(t.spaceId,n))}},e,this)})),function(e,t){return c.apply(this,arguments)})},{key:"resolveOverwritesFromRolesByOrder",value:(a=qt(Qt().m(function e(t,r){var n,o,i,a,c;return Qt().w(function(e){for(;;)switch(e.n){case 0:return n=0,o=0,e.n=1,this.tracker.spaces.getRoles(t);case 1:return i=e.v,a=r.sort(function(e,t){return i.get(e.target.roleId).priority-i.get(t.target.roleId).priority}),c=r.reduce(function(e,t){var r,n,o,i;return Math.max(e,null!==(r=null===(n=t.overwrites.allow)||void 0===n?void 0:n.toString(2).length)&&void 0!==r?r:0,null!==(o=null===(i=t.overwrites.deny)||void 0===i?void 0:i.toString(2).length)&&void 0!==o?o:0)},0),a.forEach(function(e){for(var t,r,i,a,u=e.overwrites,s=null!==(t=null===(r=u.deny)||void 0===r?void 0:r.toString(2).split("").reverse().join(""))&&void 0!==t?t:"",l=null!==(i=null===(a=u.allow)||void 0===a?void 0:a.toString(2).split("").reverse().join(""))&&void 0!==i?i:"",f=0;f<c;f++){var h,p,d=parseInt(null!==(h=s[f])&&void 0!==h?h:"0"),y=parseInt(null!==(p=l[f])&&void 0!==p?p:"0");d&&(o|=1<<f),y&&(n|=1<<f)}}),e.a(2,{allow:n,deny:o})}},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"resolveOverwritesHierarchy",value:function(e){var t,r=0,n=Bt(e);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(o.allow&Ut.getByName("Root").value)return this.getRootAccessValue();r=r&~o.deny|o.allow}}catch(e){n.e(e)}finally{n.f()}return r}},{key:"getRootAccessValue",value:function(){var e,t=0,r=Bt(Ut.getNames());try{for(r.s();!(e=r.n()).done;){var n=e.value;t|=Ut.getByName(n).value}}catch(e){r.e(e)}finally{r.f()}return t}},{key:"fetchMembersOrFail",value:(i=qt(Qt().m(function e(t){var r,n,o,i;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all([t.spaceId?this.tracker.spaces.getMe(t.spaceId):null,t.roomId?this.tracker.rooms.getMe(t.roomId):null]);case 1:if(r=e.v,n=t.spaceId&&!r[0],o=t.roomId&&!r[1],!n&&!o){e.n=2;break}throw i=n?"space (".concat(t.spaceId,")"):"room (".concat(t.roomId,")"),new Error("Attempting to calculate permissions for a ".concat(i," that the user does not belong to"));case 2:return e.a(2,r)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"validateLocation",value:function(e){if(e.topicId&&!e.roomId)throw new Error("Corrupted arguments hierarchy")}},{key:"handleSession",value:function(e){this.overwrites.deleteAll(),this.overwritesPromises.forgetAll()}}],n&&Kt(r.prototype,n),o&&Kt(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l,f}(a);function ar(e){return ar="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ar(e)}function cr(e){return function(e){if(Array.isArray(e))return ur(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return ur(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ur(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ur(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function sr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return lr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(lr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,lr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,lr(f,"constructor",s),lr(s,"constructor",u),u.displayName="GeneratorFunction",lr(s,o,"GeneratorFunction"),lr(f),lr(f,o,"Generator"),lr(f,n,function(){return this}),lr(f,"toString",function(){return"[object Generator]"}),(sr=function(){return{w:i,m:h}})()}function lr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}lr=function(e,t,r,n){function i(t,r){lr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},lr(e,t,r,n)}function fr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function hr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){fr(i,n,o,a,c,"next",e)}function c(e){fr(i,n,o,a,c,"throw",e)}a(void 0)})}}function pr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,yr(n.key),n)}}function dr(e,t,r){return(t=yr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function yr(e){var t=function(e,t){if("object"!=ar(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ar(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ar(t)?t:t+""}var mr="global",vr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),dr(this,"list",new L),dr(this,"emoticonsPromises",new $),this.tracker=t,this.tracker.client.on("Emoticons",function(e){return r.handleEmoticons(e)}),this.tracker.client.on("NewEmoticon",function(e){return r.handleNewEmoticon(e)}),this.tracker.client.on("EmoticonDeleted",function(e){return r.handleEmoticonDeleted(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=hr(sr().m(function e(t){var r,n=this;return sr().w(function(e){for(;;)switch(e.n){case 0:return r=null!=t?t:mr,this.emoticonsPromises.notExist(r)&&this.emoticonsPromises.registerByFunction(hr(sr().m(function e(){var r;return sr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,n.tracker.client.send("GetEmoticons",{spaceId:t});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:n.handleEmoticons(r.data);case 3:return e.a(2)}},e)})),r),e.n=1,this.emoticonsPromises.get(r);case 1:return e.a(2,this.list.get(r))}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"handleEmoticons",value:function(e){var t,r=null!==(t=e.location.spaceId)&&void 0!==t?t:mr;this.list.has(r)||this.list.set([r,new G("id")]);var n=this.list.get(r);n.set.apply(n,cr(e.emoticons))}},{key:"handleNewEmoticon",value:function(e){var t,r=this.list.get(null!==(t=e.emoticon.spaceId)&&void 0!==t?t:mr);null==r||r.set(e.emoticon)}},{key:"handleEmoticonDeleted",value:function(e){var t,r=this.list.get(null!==(t=e.spaceId)&&void 0!==t?t:mr);null==r||r.delete(e.emoticonId)}},{key:"handleSpaceDeleted",value:function(e){this.list.delete(e.id)}},{key:"handleSession",value:function(){this.list.deleteAll(),this.emoticonsPromises.forgetAll()}}],t&&pr(e.prototype,t),r&&pr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function br(e){return br="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},br(e)}function gr(e){return function(e){if(Array.isArray(e))return wr(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return wr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wr(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function kr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Sr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Sr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Sr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Sr(f,"constructor",s),Sr(s,"constructor",u),u.displayName="GeneratorFunction",Sr(s,o,"GeneratorFunction"),Sr(f),Sr(f,o,"Generator"),Sr(f,n,function(){return this}),Sr(f,"toString",function(){return"[object Generator]"}),(kr=function(){return{w:i,m:h}})()}function Sr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Sr=function(e,t,r,n){function i(t,r){Sr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Sr(e,t,r,n)}function Or(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Pr(n.key),n)}}function Tr(e,t,r){return(t=Pr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pr(e){var t=function(e,t){if("object"!=br(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=br(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==br(t)?t:t+""}var Ir=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Tr(this,"onlineStatus",new a),Tr(this,"users",new G("id")),this.tracker=t,t.client.on("UserUpdated",function(e){return r.handleUsers([e.user])}),t.client.on("RoomMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMembers",function(e){return r.handleMembers(e.members)}),t.client.on("RoomMembers",function(e){return r.handleMembers(e.members)}),t.client.on("Messages",function(e){return r.handleUsers(e.messages.map(function(e){return e.author.user}))}),t.client.on("NewMessage",function(e){return r.handleUsers([e.message.author.user])}),t.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getAvailable",value:(n=kr().m(function e(){return kr().w(function(e){for(;;)if(0===e.n)return e.a(2,this.users)},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Or(i,r,o,a,c,"next",e)}function c(e){Or(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleMembers",value:function(e){this.handleUsers(e.map(vt))}},{key:"handleSession",value:function(e){this.users.deleteAll(),this.handleUsers([e.user])}},{key:"handleUsers",value:function(e){var t,r=this;e.forEach(function(e){var t=r.users.get(e.id);t&&t.online!==e.online&&r.onlineStatus.emit("change",e)}),(t=this.users).set.apply(t,gr(e))}}],t&&jr(e.prototype,t),r&&jr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Er(e){return Er="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Er(e)}function Rr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return _r(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(_r(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,_r(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,_r(f,"constructor",s),_r(s,"constructor",u),u.displayName="GeneratorFunction",_r(s,o,"GeneratorFunction"),_r(f),_r(f,o,"Generator"),_r(f,n,function(){return this}),_r(f,"toString",function(){return"[object Generator]"}),(Rr=function(){return{w:i,m:h}})()}function _r(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}_r=function(e,t,r,n){function i(t,r){_r(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},_r(e,t,r,n)}function Ar(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Mr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ar(i,n,o,a,c,"next",e)}function c(e){Ar(i,n,o,a,c,"throw",e)}a(void 0)})}}function Fr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Cr(n.key),n)}}function Lr(e,t,r){return(t=Cr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Cr(e){var t=function(e,t){if("object"!=Er(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Er(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Er(t)?t:t+""}var xr=function(e,t){return"".concat(e,"-").concat(t)},Gr=function(e){return xr(e.refUser.id,e.type)},Dr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Lr(this,"relationships",new G(Gr)),Lr(this,"promises",new $),this.tracker=t,this.tracker.client.on("Relationships",function(e){return r.handleRelationships(e)}),this.tracker.client.on("NewRelationship",function(e){return r.handleNewRelationship(e)}),this.tracker.client.on("RelationshipDeleted",function(e){return r.handleRelationshipDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=Mr(Rr().m(function e(){var t=this;return Rr().w(function(e){for(;;)switch(e.n){case 0:return this.promises.notExist("all")&&this.promises.registerByFunction(Mr(Rr().m(function e(){var r;return Rr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,t.tracker.client.send("GetRelationships",{});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:return e.a(2)}},e)})),"all"),e.n=1,this.promises.get("all");case 1:return e.a(2,this.relationships)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"exists",value:(n=Mr(Rr().m(function e(t,r){return Rr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.get();case 1:return e.a(2,this.relationships.has(xr(t,r)))}},e,this)})),function(e,t){return n.apply(this,arguments)})},{key:"handleRelationships",value:function(e){var t=this;this.relationships.deleteAll(),e.relationships.forEach(function(e){t.relationships.set(e)})}},{key:"handleNewRelationship",value:function(e){this.promises.has("all")&&this.relationships.set(e.relationship)}},{key:"handleRelationshipDeleted",value:function(e){this.promises.has("all")&&this.relationships.delete(Gr(e.relationship))}},{key:"handleSession",value:function(){this.promises.forgetAll(),this.relationships.deleteAll()}}],t&&Fr(e.prototype,t),r&&Fr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n}();function Ur(e){return Ur="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ur(e)}function Nr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Br(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Br(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Br(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Br(f,"constructor",s),Br(s,"constructor",u),u.displayName="GeneratorFunction",Br(s,o,"GeneratorFunction"),Br(f),Br(f,o,"Generator"),Br(f,n,function(){return this}),Br(f,"toString",function(){return"[object Generator]"}),(Nr=function(){return{w:i,m:h}})()}function Br(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Br=function(e,t,r,n){function i(t,r){Br(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Br(e,t,r,n)}function Wr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,$r(n.key),n)}}function Hr(e,t,r){return(t=$r(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function $r(e){var t=function(e,t){if("object"!=Ur(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ur(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ur(t)?t:t+""}var Qr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Hr(this,"client",void 0),Hr(this,"permissions",void 0),Hr(this,"rooms",void 0),Hr(this,"spaces",void 0),Hr(this,"emoticons",void 0),Hr(this,"users",void 0),Hr(this,"relationships",void 0),Hr(this,"_me",null),Hr(this,"deferredSession",new H),this.client=t,this.client.on("Session",function(e){return r.handleSession(e)}),this.permissions=new ir(this),this.rooms=new mt(this),this.spaces=new _t(this),this.emoticons=new vr(this),this.users=new Ir(this),this.relationships=new Dr(this)},t=[{key:"me",get:function(){return this._me}},{key:"getMe",value:(n=Nr().m(function e(){return Nr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this._me)}},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Wr(i,r,o,a,c,"next",e)}function c(e){Wr(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleSession",value:function(e){this._me=e.user,this.deferredSession.resolve()}}],t&&Jr(e.prototype,t),r&&Jr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Vr(e){return Vr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Vr(e)}function zr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return qr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(qr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,qr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,qr(f,"constructor",s),qr(s,"constructor",u),u.displayName="GeneratorFunction",qr(s,o,"GeneratorFunction"),qr(f),qr(f,o,"Generator"),qr(f,n,function(){return this}),qr(f,"toString",function(){return"[object Generator]"}),(zr=function(){return{w:i,m:h}})()}function qr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}qr=function(e,t,r,n){function i(t,r){qr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},qr(e,t,r,n)}function Kr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Yr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Kr(i,n,o,a,c,"next",e)}function c(e){Kr(i,n,o,a,c,"throw",e)}a(void 0)})}}function Xr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,on(n.key),n)}}function Zr(e,t,r){return t=tn(t),function(e,t){if(t&&("object"==Vr(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,en()?Reflect.construct(t,r||[],tn(e).constructor):t.apply(e,r))}function en(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(en=function(){return!!e})()}function tn(e){return tn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},tn(e)}function rn(e,t){return rn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},rn(e,t)}function nn(e,t,r){return(t=on(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function on(e){var t=function(e,t){if("object"!=Vr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Vr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Vr(t)?t:t+""}var an=function(e){return e.connect="connect",e.disconnect="disconnect",e.message="message",e.error="error",e}(an||{}),cn=function(e){function t(e){var r,n,o,i,a,c,u,s,l;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),nn(l=Zr(this,t),"Event",an),nn(l,"state",void 0),nn(l,"ws",null),nn(l,"sendQueue",[]),nn(l,"connectingTimeoutId",void 0),nn(l,"authenticated",void 0),nn(l,"authenticatedResolvers",void 0),nn(l,"pingMonitorInterval",void 0),nn(l,"inFlightPingTimeout",void 0),nn(l,"lastReceivedMessageAt",void 0),l.options=e,(null===(r=l.options.stateTracking)||void 0===r||r)&&(l.state=new Qr(l)),null!==(n=e.ping)&&void 0!==n||(e.ping={}),null!==(i=(o=e.ping).enabled)&&void 0!==i||(o.enabled=!0),null!==(c=(a=e.ping).noActivityTimeoutMs)&&void 0!==c||(a.noActivityTimeoutMs=15e3),null!==(s=(u=e.ping).pongBackTimeoutMs)&&void 0!==s||(u.pongBackTimeoutMs=5e3),l}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&rn(e,t)}(t,e),r=t,n=[{key:"connect",value:(a=Yr(zr().m(function e(){var t,r,n,o=this;return zr().w(function(e){for(;;)switch(e.n){case 0:if(!this.isOpenWsState()&&!this.isConnectingWsState()){e.n=1;break}return e.a(2);case 1:return(n=new URLSearchParams(null!==(t=this.options.queryParams)&&void 0!==t?t:{})).set("token",this.options.token),this.ws=new WebSocket("".concat(this.options.url,"?").concat(n)),this.ws.onclose=function(e){return o.onClose(e)},this.ws.onmessage=function(e){return o.onMessage(e)},this.connectingTimeoutId=setTimeout(function(){return o.triggerConnectionTimeout()},null!==(r=this.options.connectingTimeoutMs)&&void 0!==r?r:1e4),this.authenticated=!1,e.a(2,new Promise(function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return o.authenticatedResolvers=t}))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"disconnect",value:function(){var e;this.sendQueue=[],null===(e=this.ws)||void 0===e||e.close(1e3),this.ws=null}},{key:"send",value:(i=Yr(zr().m(function e(t,r){var n,o;return zr().w(function(e){for(;;)switch(e.n){case 0:if(n=this.createEnvelope(t,r),o=this.createPromiseFromCommandEnvelope(n),!(this.isConnectingWsState()||!this.authenticated&&this.isOpenWsState())){e.n=1;break}return this.sendQueue.push(n),e.a(2,o);case 1:return this.sendEnvelope(n),e.a(2,o)}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"isReady",get:function(){return this.isOpenWsState()&&this.authenticated}},{key:"sendEnvelope",value:function(e){var t,r;this.isReady?this.ws.send(JSON.stringify(e)):this.handleEnvelopeSendError(e,new Error("Cannot send - client is not ready (state=".concat(null!==(t=null===(r=this.ws)||void 0===r?void 0:r.readyState)&&void 0!==t?t:"[no connection]","; authenticated=").concat(this.authenticated,")")))}},{key:"onMessage",value:function(e){this.lastReceivedMessageAt=Date.now();var t=JSON.parse(e.data);if(this.handleIncomingEnvelope(t),this.emit(t.type,t.data),this.emit(this.Event.message,t),!this.authenticated){var r="Bye"!==t.type;this.authenticated=r,r?(this.startConnectionMonitor(),this.authenticatedResolvers[0](),this.emit(this.Event.connect),this.sendFromQueue()):this.authenticatedResolvers[1](t.data)}}},{key:"onClose",value:function(e){this.stopConnectionMonitor(),clearTimeout(this.connectingTimeoutId);var t=1e3!==e.code;t&&this.connect(),this.emit(this.Event.disconnect,t)}},{key:"sendFromQueue",value:function(){var e=this,t=0,r=function(){var r,o=e.sendQueue[n];setTimeout(function(){return e.sendEnvelope(o)},t),t+=null!==(r=e.options.awaitQueueSendDelayMs)&&void 0!==r?r:500};for(var n in this.sendQueue)r();this.sendQueue=[],clearTimeout(this.connectingTimeoutId)}},{key:"triggerConnectionTimeout",value:function(){this.disconnect(),this.emit(this.Event.error,new Error("Connection timeout"))}},{key:"isConnectingWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.CONNECTING}},{key:"isOpenWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.OPEN}},{key:"startConnectionMonitor",value:function(){var e=this;this.options.ping.enabled&&(this.lastReceivedMessageAt=Date.now(),this.pingMonitorInterval=setInterval(Yr(zr().m(function t(){return zr().w(function(t){for(;;)switch(t.n){case 0:if(e.isReady&&!e.inFlightPingTimeout){t.n=1;break}return t.a(2);case 1:if(!(Date.now()-e.lastReceivedMessageAt<e.options.ping.noActivityTimeoutMs)){t.n=2;break}return t.a(2);case 2:e.inFlightPingTimeout=setTimeout(function(){e.inFlightPingTimeout=void 0,e.ws.close(3e3)},e.options.ping.pongBackTimeoutMs),e.send("Ping",{}).then(function(){clearTimeout(e.inFlightPingTimeout),e.inFlightPingTimeout=void 0});case 3:return t.a(2)}},t)})),1e3))}},{key:"stopConnectionMonitor",value:function(){this.inFlightPingTimeout&&(clearTimeout(this.inFlightPingTimeout),this.inFlightPingTimeout=void 0),this.pingMonitorInterval&&(clearInterval(this.pingMonitorInterval),this.pingMonitorInterval=void 0)}}],n&&Xr(r.prototype,n),o&&Xr(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function un(e){return un="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},un(e)}function sn(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ln(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ln(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ln(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ln(f,"constructor",s),ln(s,"constructor",u),u.displayName="GeneratorFunction",ln(s,o,"GeneratorFunction"),ln(f),ln(f,o,"Generator"),ln(f,n,function(){return this}),ln(f,"toString",function(){return"[object Generator]"}),(sn=function(){return{w:i,m:h}})()}function ln(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ln=function(e,t,r,n){function i(t,r){ln(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ln(e,t,r,n)}function fn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function hn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){fn(i,n,o,a,c,"next",e)}function c(e){fn(i,n,o,a,c,"throw",e)}a(void 0)})}}function pn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,gn(n.key),n)}}function dn(e,t,r){return t=mn(t),function(e,t){if(t&&("object"==un(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,yn()?Reflect.construct(t,r||[],mn(e).constructor):t.apply(e,r))}function yn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(yn=function(){return!!e})()}function mn(e){return mn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},mn(e)}function vn(e,t){return vn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},vn(e,t)}function bn(e,t,r){return(t=gn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function gn(e){var t=function(e,t){if("object"!=un(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=un(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==un(t)?t:t+""}var wn=function(e){return e.message="message",e.error="error",e.destroy="destroy",e}(wn||{}),kn=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),bn(r=dn(this,t),"Event",wn),bn(r,"sendStack",void 0),r.options=e,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&vn(e,t)}(t,e),r=t,n=[{key:"send",value:(a=hn(sn().m(function e(t,r){var n;return sn().w(function(e){for(;;)if(0===e.n)return n=this.createEnvelope(t,r),this.sendStack.push({data:n,attempts:0,lastTimeoutId:null}),this.makeApiCall(this.sendStack.length-1),e.a(2,this.createPromiseFromCommandEnvelope(n))},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"destroy",value:function(){var e=this;this.sendStack.forEach(function(t){t.lastTimeoutId&&clearTimeout(t.lastTimeoutId),e.awaitingResponse.delete(t.data.ref)}),this.sendStack=[],this.emit(this.Event.destroy,!1)}},{key:"onMessage",value:(i=hn(sn().m(function e(t,r){var n;return sn().w(function(e){for(;;)switch(e.n){case 0:return this.sendStack.splice(t,1),e.n=1,r.json();case 1:n=e.v,this.handleIncomingEnvelope(n),this.emit(n.type,n.data),this.emit(this.Event.message,n);case 2:return e.a(2)}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"onError",value:function(e,t){var r,n,o=this;if(this.sendStack[e].attempts>=(null!==(r=this.options.attemptsToSend)&&void 0!==r?r:10))return this.sendStack.splice(e,1),void this.handleEnvelopeSendError(this.sendStack[e].data,new Error("Cannot send ".concat(t,"; aborting after reaching the maximum connection errors")));this.sendStack[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;this.sendStack[e].attempts++;var n=JSON.stringify(this.sendStack[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:{}),a="".concat(this.options.url).concat(i?"?"+i:"");fetch(a,{headers:o,body:n,method:"POST"}).then(function(t){return r.onMessage(e,t)}).catch(function(){return r.onError(e,n)})}}],n&&pn(r.prototype,n),o&&pn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function Sn(e){return Sn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Sn(e)}function On(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return jn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(jn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,jn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,jn(f,"constructor",s),jn(s,"constructor",u),u.displayName="GeneratorFunction",jn(s,o,"GeneratorFunction"),jn(f),jn(f,o,"Generator"),jn(f,n,function(){return this}),jn(f,"toString",function(){return"[object Generator]"}),(On=function(){return{w:i,m:h}})()}function jn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}jn=function(e,t,r,n){function i(t,r){jn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},jn(e,t,r,n)}function Tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Pn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Tn(Object(r),!0).forEach(function(t){In(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Tn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function In(e,t,r){return(t=An(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function En(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Rn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){En(i,n,o,a,c,"next",e)}function c(e){En(i,n,o,a,c,"throw",e)}a(void 0)})}}function _n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,An(n.key),n)}}function An(e){var t=function(e,t){if("object"!=Sn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Sn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Sn(t)?t:t+""}var Mn=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=t},t=[{key:"send",value:(o=Rn(On().m(function e(t,r){var n,o,i,a,c,u,s=arguments;return On().w(function(e){for(;;)switch(e.n){case 0:return n=s.length>2&&void 0!==s[2]?s[2]:void 0,o=s.length>3&&void 0!==s[3]?s[3]:{},i=this.getUrl(r),a=void 0,n&&(["GET","DELETE"].includes(t)?i+="?"+new URLSearchParams(n).toString():a=JSON.stringify(n)),c=Pn(Pn({"Content-Type":"application/json",Accept:"application/json"},o),this.getAuthHeaders()),e.n=1,fetch(i,{method:t,body:a,headers:c});case 1:return u=e.v,e.a(2,this.convertFetchResponse(u))}},e,this)})),function(e,t){return o.apply(this,arguments)})},{key:"getAuthHeaders",value:function(){var e={};return this.options.token&&(e.Authorization="Bearer ".concat(this.options.token)),e}},{key:"getUrl",value:function(e){var t;return this.removeEndingSlash(null!==(t=this.options.url)&&void 0!==t?t:this.defaultUrl)+"/"+this.removeStartingSlash(e)}},{key:"convertFetchResponse",value:(n=Rn(On().m(function e(t){var r,n,o,i,a;return On().w(function(e){for(;;)switch(e.n){case 0:if(n=t.ok,o=t.status,null===(r=t.headers.get("content-type"))||void 0===r||!r.includes("json")){e.n=2;break}return e.n=1,t.json();case 1:i=e.v,e.n=4;break;case 2:return e.n=3,t.text();case 3:i=e.v;case 4:return a=i,e.a(2,{ok:n,status:o,data:a})}},e)})),function(e){return n.apply(this,arguments)})},{key:"removeStartingSlash",value:function(e){return e.replace(/^\/+/,"")}},{key:"removeEndingSlash",value:function(e){return e.replace(/\/+$/,"")}}],t&&_n(e.prototype,t),r&&_n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Fn(e){return Fn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Fn(e)}function Ln(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Cn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Cn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Cn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Cn(f,"constructor",s),Cn(s,"constructor",u),u.displayName="GeneratorFunction",Cn(s,o,"GeneratorFunction"),Cn(f),Cn(f,o,"Generator"),Cn(f,n,function(){return this}),Cn(f,"toString",function(){return"[object Generator]"}),(Ln=function(){return{w:i,m:h}})()}function Cn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Cn=function(e,t,r,n){function i(t,r){Cn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Cn(e,t,r,n)}function xn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Gn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?xn(Object(r),!0).forEach(function(t){$n(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):xn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Dn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Un(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Dn(i,n,o,a,c,"next",e)}function c(e){Dn(i,n,o,a,c,"throw",e)}a(void 0)})}}function Nn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Qn(n.key),n)}}function Bn(e,t,r){return t=Jn(t),function(e,t){if(t&&("object"==Fn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Wn()?Reflect.construct(t,r||[],Jn(e).constructor):t.apply(e,r))}function Wn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Wn=function(){return!!e})()}function Jn(e){return Jn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Jn(e)}function Hn(e,t){return Hn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Hn(e,t)}function $n(e,t,r){return(t=Qn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Qn(e){var t=function(e,t){if("object"!=Fn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Fn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Fn(t)?t:t+""}var Vn=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return $n(e=Bn(this,t,[].concat(n)),"defaultUrl","https://files.devana.pl"),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Hn(e,t)}(t,e),r=t,n=[{key:"uploadFile",value:(c=Un(Ln().m(function e(t){var r,n,o,i;return Ln().w(function(e){for(;;)switch(e.n){case 0:return n=encodeURIComponent(null!==(r=t.name)&&void 0!==r?r:""),o=Gn(Gn({},this.getAuthHeaders()),{},{Accept:"application/json","Content-Disposition":'attachment; filename="'.concat(n,'"'),"Content-Length":t.size}),e.n=1,fetch(this.getUrl("files"),{method:"POST",body:t,headers:o});case 1:return i=e.v,e.a(2,this.convertFetchResponse(i))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getFileMeta",value:(a=Un(Ln().m(function e(t){return Ln().w(function(e){for(;;)if(0===e.n)return e.a(2,this.send("GET","files/"+t))},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getFileMetaBulk",value:(i=Un(Ln().m(function e(t){var r;return Ln().w(function(e){for(;;)if(0===e.n)return r=new URLSearchParams,t.forEach(function(e){return r.append("id[]",e)}),e.a(2,this.send("GET","files?"+r))},e,this)})),function(e){return i.apply(this,arguments)})}],n&&Nn(r.prototype,n),o&&Nn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c}(Mn);return t})());
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.PservClient=t():e.PservClient=t()}(this,()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,i(n.key),n)}}function o(e,t,r){return(t=i(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e){var t=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=r(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==r(t)?t:t+""}e.r(t),e.d(t,{AbstractRestClient:()=>Mn,FilesClient:()=>Vn,IndexedCollection:()=>L,IndexedObjectCollection:()=>C,Layer:()=>Gt,ObservableIndexedCollection:()=>x,ObservableIndexedObjectCollection:()=>G,PermissionDefinition:()=>Dt,Permissions:()=>Ut,WebApiChatClient:()=>kn,WebSocketChatClient:()=>cn,extractUserFromMember:()=>vt});var a=function(){return e=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),o(this,"events",new Map),o(this,"onceEvents",new Map)},(t=[{key:"on",value:function(e,t){return this.addHandler(this.events,e,t),this}},{key:"once",value:function(e,t){return this.addHandler(this.onceEvents,e,t),this}},{key:"off",value:function(e,t){var r,n,o=null===(r=this.events.get(e))||void 0===r?void 0:r.indexOf(t);return void 0===o||o<0||null===(n=this.events.get(e))||void 0===n||n.splice(o,1),this}},{key:"emit",value:function(e,t){return this.callHandlers(this.events,e,t),this.callHandlers(this.onceEvents,e,t),this.onceEvents.delete(e),this}},{key:"addHandler",value:function(e,t,r){var n,o=null!==(n=e.get(t))&&void 0!==n?n:[];o.push(r),e.set(t,o)}},{key:"callHandlers",value:function(e,t,r){var n;null===(n=e.get(t))||void 0===n||n.forEach(function(e){return e(r)})}}])&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,d(n.key),n)}}function s(e,t,r){return t=f(t),function(e,t){if(t&&("object"==c(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,l()?Reflect.construct(t,r||[],f(e).constructor):t.apply(e,r))}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function p(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(e){var t=function(e,t){if("object"!=c(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==c(t)?t:t+""}var y=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return p(e=s(this,t,[].concat(n)),"awaitingResponse",new Map),p(e,"sentCounter",0),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}(t,e),r=t,n=[{key:"createEnvelope",value:function(e,t){return{type:e,data:t,ref:(++this.sentCounter).toString()}}},{key:"createPromiseFromCommandEnvelope",value:function(e){var t=this;return new Promise(function(){for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return t.awaitingResponse.set(e.ref,n)})}},{key:"handleIncomingEnvelope",value:function(e){if(this.awaitingResponse.has(e.ref)){var t="Error"===e.type;this.awaitingResponse.get(e.ref)[0]({data:t?null:e.data,error:t?e.data:null}),this.awaitingResponse.delete(e.ref)}}},{key:"handleEnvelopeSendError",value:function(e,t){this.awaitingResponse.has(e.ref)&&(this.awaitingResponse.get(e.ref)[1](t),this.awaitingResponse.delete(e.ref))}}],n&&u(r.prototype,n),o&&u(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o}(a);function m(e){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m(e)}function v(e,t,r){return t=k(t),function(e,t){if(t&&("object"==m(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,b()?Reflect.construct(t,r||[],k(e).constructor):t.apply(e,r))}function b(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(b=function(){return!!e})()}function g(e,t,r,n){var o=w(k(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function w(){return w="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=k(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},w.apply(null,arguments)}function k(e){return k=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},k(e)}function S(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&O(e,t)}function O(e,t){return O=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},O(e,t)}function j(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||I(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=I(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function P(e){return function(e){if(Array.isArray(e))return E(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||I(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e,t){if(e){if("string"==typeof e)return E(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,t):void 0}}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function R(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,F(n.key),n)}}function A(e,t,r){return t&&_(e.prototype,t),r&&_(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function M(e,t,r){return(t=F(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(e){var t=function(e,t){if("object"!=m(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=m(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==m(t)?t:t+""}var L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];R(this,e),M(this,"_items",new Map),this.set.apply(this,P(t))}return A(e,[{key:"items",get:function(){return this._items}},{key:"length",get:function(){return this._items.size}},{key:"set",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this._items.set(i[0],i[1])}}},{key:"get",value:function(e){return this.items.get(e)}},{key:"has",value:function(e){return this.items.has(e)}},{key:"delete",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];for(var n=0,o=t;n<o.length;n++){var i=o[n];this.items.delete(i)}}},{key:"deleteAll",value:function(){this.items.clear()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1/0,i=new e,a=T(this.items.entries());try{for(a.s();!(n=a.n()).done;){var c=j(n.value,2),u=c[0],s=c[1];if(i.length>=o)break;s[t]===r&&i.set([u,s])}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e;return t._items=this._items,t}}])}(),C=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];R(this,e),M(this,"_items",void 0),this.id=t,this._items=new L,this.set.apply(this,P(r))}return A(e,[{key:"items",get:function(){return Array.from(this._items.items.values())}},{key:"length",get:function(){return this._items.length}},{key:"set",value:function(){for(var e,t=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this._items).set.apply(e,P(n.map(function(e){return[t.getId(e),e]})))}},{key:"get",value:function(e){return this._items.get(e)}},{key:"getAt",value:function(e){return this.items[e]}},{key:"has",value:function(e){return this._items.has(e)}},{key:"delete",value:function(){var e;(e=this._items).delete.apply(e,arguments)}},{key:"deleteAll",value:function(){this._items.deleteAll()}},{key:"findBy",value:function(t,r){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new e(this.id),a=T(this.items);try{for(a.s();!(n=a.n()).done;){var c=n.value;if(o&&i.length===o)break;c[t]===r&&i.set(c)}}catch(e){a.e(e)}finally{a.f()}return i}},{key:"createMirror",value:function(){var t=new e(this.id);return t._items=this._items,t}},{key:"getId",value:function(e){return"function"==typeof this.id?this.id(e):e[this.id]}}])}(),x=function(e){function t(){var e,r,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return R(this,t),M(r=v(this,t),"eventTarget",void 0),r.eventTarget=new a,(e=r).set.apply(e,P(n)),r}return S(t,e),A(t,[{key:"set",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"set",this,3)(r),this.eventTarget.emit("change",{setItems:r.map(function(e){return e[0]})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){if(this.length){var e=Array.from(this._items.keys());g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:Array.from(e)})}}},{key:"createMirror",value:function(){var e=new t;return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(L),G=function(e){function t(e){var r,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return R(this,t),M(n=v(this,t,[e]),"eventTarget",void 0),n.eventTarget=new a,(r=n).set.apply(r,P(o)),n}return S(t,e),A(t,[{key:"set",value:function(){for(var e=this,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];n.length&&(g(t,"set",this,3)(n),this.eventTarget.emit("change",{setItems:n.map(function(t){return e.getId(t)})}))}},{key:"delete",value:function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];r.length&&(g(t,"delete",this,3)(r),this.eventTarget.emit("change",{deletedItems:r}))}},{key:"deleteAll",value:function(){var e=this;if(this.length){var r=this.items.map(function(t){return e.getId(t)});g(t,"deleteAll",this,3)([]),this.eventTarget.emit("change",{deletedItems:r})}}},{key:"createMirror",value:function(){var e=new t(this.id);return e.eventTarget=this.eventTarget,e._items=this._items,e}},{key:"on",value:function(e,t){return this.eventTarget.on(e,t),this}},{key:"once",value:function(e,t){return this.eventTarget.once(e,t),this}},{key:"off",value:function(e,t){return this.eventTarget.off(e,t),this}}])}(C);function D(e){return D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},D(e)}function U(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,J(n.key),n)}}function N(e,t,r){return t&&U(e.prototype,t),r&&U(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function B(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function W(e,t,r){return(t=J(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function J(e){var t=function(e,t){if("object"!=D(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=D(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==D(t)?t:t+""}var H=N(function e(){var t=this;B(this,e),W(this,"promise",void 0),W(this,"resolve",void 0),this.promise=new Promise(function(e){return t.resolve=e})}),$=function(){return N(function e(){B(this,e),W(this,"promises",new L)},[{key:"register",value:function(e,t){this.promises.set([t,e])}},{key:"registerByFunction",value:function(e,t){this.register(e(),t)}},{key:"get",value:function(e){return this.promises.get(e)}},{key:"has",value:function(e){return this.promises.has(e)}},{key:"notExist",value:function(e){return!this.has(e)}},{key:"forget",value:function(){var e;(e=this.promises).delete.apply(e,arguments)}},{key:"forgetAll",value:function(){this.promises.deleteAll()}}])}();function Q(e){return Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Q(e)}function V(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?V(Object(r),!0).forEach(function(t){fe(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):V(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function q(e,t,r,n){var o=K(ue(1&n?e.prototype:e),t,r);return 2&n&&"function"==typeof o?function(e){return o.apply(r,e)}:o}function K(){return K="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=ue(e)););return e}(e,t);if(n){var o=Object.getOwnPropertyDescriptor(n,t);return o.get?o.get.call(arguments.length<3?e:r):o.value}},K.apply(null,arguments)}function Y(e){return function(e){if(Array.isArray(e))return X(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?X(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Z(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ee(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ee(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ee(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ee(f,"constructor",s),ee(s,"constructor",u),u.displayName="GeneratorFunction",ee(s,o,"GeneratorFunction"),ee(f),ee(f,o,"Generator"),ee(f,n,function(){return this}),ee(f,"toString",function(){return"[object Generator]"}),(Z=function(){return{w:i,m:h}})()}function ee(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ee=function(e,t,r,n){function i(t,r){ee(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ee(e,t,r,n)}function te(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function re(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){te(i,n,o,a,c,"next",e)}function c(e){te(i,n,o,a,c,"throw",e)}a(void 0)})}}function ne(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function oe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,he(n.key),n)}}function ie(e,t,r){return t&&oe(e.prototype,t),r&&oe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function ae(e,t,r){return t=ue(t),function(e,t){if(t&&("object"==Q(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,ce()?Reflect.construct(t,r||[],ue(e).constructor):t.apply(e,r))}function ce(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ce=function(){return!!e})()}function ue(e){return ue=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},ue(e)}function se(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&le(e,t)}function le(e,t){return le=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},le(e,t)}function fe(e,t,r){return(t=he(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function he(e){var t=function(e,t){if("object"!=Q(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Q(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Q(t)?t:t+""}var pe=function(e){return e[e.LIVE=0]="LIVE",e[e.LATEST=1]="LATEST",e[e.PAST=2]="PAST",e[e.OLDEST=3]="OLDEST",e}({}),de=function(e){function t(e,r,n){var o,i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3];return ne(this,t),fe(o=ae(this,t,["id"]),"WindowState",pe),o.roomId=e,o.topicId=r,o.tracker=n,o.internalState.traverseLock=!1,i&&(o.tracker.client.on("NewMessage",function(e){return o.handleNewMessage(e)}),o.tracker.client.on("MessagesRedacted",function(e){return o.handleMessagesRedacted(e)})),o}return se(t,e),ie(t,[{key:"createMirror",value:function(){var e=new t(this.roomId,this.topicId,this.tracker,!1);return e.eventTarget=this.eventTarget,e._items=this._items,e.internalState=this.internalState,e}},{key:"isTraverseLocked",get:function(){return this.internalState.traverseLock}},{key:"setTraverseLock",value:(y=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(this.internalState.traverseLock=r,!r||this.state===pe.LIVE||this.state===pe.LATEST){e.n=1;break}return e.n=1,q(t,"resetToLatest",this,3)([]);case 1:return e.a(2)}},e,this)})),function(e){return y.apply(this,arguments)})},{key:"resetToLatest",value:(d=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"resetToLatest",this,3)([]))}},e,this)})),function(){return d.apply(this,arguments)})},{key:"fetchNext",value:(p=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchNext",this,3)([]))}},e,this)})),function(){return p.apply(this,arguments)})},{key:"fetchPrevious",value:(h=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"fetchPrevious",this,3)([]))}},e,this)})),function(){return h.apply(this,arguments)})},{key:"jumpTo",value:(f=re(Z().m(function e(r){return Z().w(function(e){for(;;)switch(e.n){case 0:if(!this.internalState.traverseLock){e.n=1;break}return e.a(2);case 1:return e.a(2,q(t,"jumpTo",this,3)([r]))}},e,this)})),function(e){return f.apply(this,arguments)})},{key:"_updateMessageReference",value:function(e){var t=this.get(e.refMessage.id);t&&this.set(z(z({},t),{},{topicRef:e.id}))}},{key:"fetchItemsAfter",value:(l=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(this.length-1))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},after:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return l.apply(this,arguments)})},{key:"fetchItemsAround",value:(s=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},around:t,limit:this.internalState.fetchLimit});case 1:if(!(r=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(r.error.message));case 2:return e.a(2,r.data.messages)}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"fetchItemsBefore",value:(u=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.n){case 0:if(r=null===(t=this.getAt(0))||void 0===t?void 0:t.id){e.n=1;break}return e.a(2,null);case 1:return e.n=2,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},before:r,limit:this.internalState.fetchLimit});case 2:if(!(n=e.v).error){e.n=3;break}throw new Error("Cannot fetch messages: ".concat(n.error.message));case 3:return e.a(2,n.data.messages)}},e,this)})),function(){return u.apply(this,arguments)})},{key:"fetchLatestItems",value:(c=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.client.send("GetMessages",{location:{roomId:this.roomId,topicId:this.topicId},limit:this.internalState.fetchLimit});case 1:if(!(t=e.v).error){e.n=2;break}throw new Error("Cannot fetch messages: ".concat(t.error.message));case 2:return e.a(2,t.data.messages)}},e,this)})),function(){return c.apply(this,arguments)})},{key:"getTopic",value:(a=re(Z().m(function e(){return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.getTopics(this.roomId,[this.topicId]);case 1:return e.a(2,e.v.get(this.topicId))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"getLatestMessageId",value:(i=re(Z().m(function e(){var t,r,n,o,i;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getTopic();case 1:if(o=t=e.v,n=null===o){e.n=2;break}n=void 0===t;case 2:if(r=n){e.n=3;break}r=null===(t=t.lastMessage)||void 0===t;case 3:if(!r){e.n=4;break}i=void 0,e.n=5;break;case 4:i=t.id;case 5:return e.a(2,i)}},e,this)})),function(){return i.apply(this,arguments)})},{key:"isLatestItemLoaded",value:(o=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getLatestMessageId();case 1:return t=e.v,e.a(2,!t||this.has(t))}},e,this)})),function(){return o.apply(this,arguments)})},{key:"handleNewMessage",value:(n=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:[pe.LATEST,pe.LIVE].includes(this.state)&&t.message.location.roomId===this.roomId&&t.message.location.topicId===this.topicId&&(r=this.state,this.addItems([t.message],"tail"),this.emitChangeWithDiff(!0,r));case 1:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleMessagesRedacted",value:(r=re(Z().m(function e(t){var r;return Z().w(function(e){for(;;)switch(e.n){case 0:if(t.location.topicId===this.topicId&&t.location.roomId===this.roomId){e.n=1;break}return e.a(2);case 1:if(r=this.items.filter(function(e){return e.topicRef&&t.ids.includes(e.id)}).map(function(e){return e.topicRef}),this.delete.apply(this,Y(t.ids)),0!==this.length){e.n=2;break}return e.n=2,this.resetToLatest();case 2:r.length>0&&this.eventTarget.emit("reftopicsdeleted",r);case 3:return e.a(2)}},e,this)})),function(e){return r.apply(this,arguments)})}]);var r,n,o,i,a,c,u,s,l,f,h,p,d,y}(function(e){function t(){var e;ne(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return fe(e=ae(this,t,[].concat(n)),"internalState",{current:pe.LIVE,ongoing:void 0,limit:1e3,retainRatio:1,fetchLimit:50,lastFetchCount:0,oldestId:null}),e}return se(t,e),ie(t,[{key:"state",get:function(){return this.internalState.current}},{key:"fetchLimit",get:function(){return this.internalState.fetchLimit},set:function(e){this.internalState.fetchLimit=e}},{key:"limit",get:function(){return this.internalState.limit},set:function(e){this.internalState.limit=e}},{key:"retainRatio",get:function(){return this.internalState.retainRatio},set:function(e){this.internalState.retainRatio=e}},{key:"hasLatest",get:function(){return[pe.LATEST,pe.LIVE].includes(this.state)}},{key:"hasOldest",get:function(){return this.state===pe.OLDEST||this.state===pe.LATEST&&this.length<this.fetchLimit||null!==this.internalState.oldestId&&this.has(this.internalState.oldestId)}},{key:"resetToLatest",value:(a=re(Z().m(function e(){var t,r;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&this.internalState.current!==pe.LATEST){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.LATEST,e.p=2,e.n=3,this.fetchLatestItems();case 3:t=e.v,this.internalState.lastFetchCount=t.length;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:this._items.deleteAll(),this.addItems(t,"tail"),this.internalState.current=pe.LATEST,this.emitChangeWithDiff(!0,r);case 6:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return a.apply(this,arguments)})},{key:"fetchPrevious",value:(i=re(Z().m(function e(){var t,r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasOldest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsBefore();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=6;break}return e.a(2,this.resetToLatest());case 6:if(t.length){e.n=8;break}return n=this.getAt(0),this.internalState.oldestId=n?this.getId(n):null,e.n=7,this.refreshFetchedState();case 7:return this.internalState.current===pe.PAST&&(this.internalState.current=pe.OLDEST),this.emitChangeWithDiff(!1,r),e.a(2);case 8:return this.addItems(t,"head"),e.n=9,this.refreshFetchedState();case 9:this.emitChangeWithDiff(!0,r);case 10:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return i.apply(this,arguments)})},{key:"fetchNext",value:(o=re(Z().m(function e(){var t,r;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this.hasLatest){e.n=1;break}return e.a(2);case 1:return r=this.state,this.internalState.ongoing=pe.PAST,e.p=2,e.n=3,this.fetchItemsAfter();case 3:t=e.v,this.internalState.lastFetchCount=t?t.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(t){e.n=7;break}return e.n=6,this.resetToLatest();case 6:return e.a(2);case 7:if(!t.length){e.n=9;break}return this.addItems(t,"tail"),e.n=8,this.refreshFetchedState();case 8:return this.emitChangeWithDiff(!0,r),e.a(2);case 9:return e.a(2)}},e,this,[[2,,4,5]])})),function(){return o.apply(this,arguments)})},{key:"jumpTo",value:(n=re(Z().m(function e(t){var r,n;return Z().w(function(e){for(;;)switch(e.p=e.n){case 0:if(!this.internalState.ongoing&&!this._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:r=e.v,this.internalState.lastFetchCount=r?r.length:0;case 4:return e.p=4,this.internalState.ongoing=void 0,e.f(4);case 5:if(r){e.n=6;break}return e.a(2);case 6:this._items.deleteAll(),this.addItems(r,"tail"),this.internalState.current=pe.PAST,this.emitChangeWithDiff(!0,n);case 7:return e.a(2)}},e,this,[[2,,4,5]])})),function(e){return n.apply(this,arguments)})},{key:"refreshFetchedState",value:(r=re(Z().m(function e(){var t;return Z().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.isLatestItemLoaded();case 1:if(!e.v){e.n=2;break}t=pe.LATEST,e.n=3;break;case 2:t=pe.PAST;case 3:this.internalState.current=t;case 4:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"addItems",value:function(e,t){var r,n,o=this;"head"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(e),Y(this.items)),"tail")),"tail"===t&&(n=this.trimItemsArrayToLimit([].concat(Y(this.items),Y(e)),"head")),this._items.deleteAll(),(r=this._items).set.apply(r,Y(n.map(function(e){return[o.getId(e),e]})))}},{key:"emitChangeWithDiff",value:function(e,t){(e||t!==this.state)&&this.eventTarget.emit("change",{setItems:Array.from(this._items.items.keys())})}},{key:"trimItemsArrayToLimit",value:function(e,t){var r=this.limit;if(null===r||e.length<=r)return e;var n=Math.floor(r*this.internalState.retainRatio);return"head"===t?e.slice(-n):"tail"===t?e.slice(0,n):e}}]);var r,n,o,i,a}(G));function ye(e){return ye="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ye(e)}function me(e){return function(e){if(Array.isArray(e))return ge(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||be(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ve(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||be(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function be(e,t){if(e){if("string"==typeof e)return ge(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ge(e,t):void 0}}function ge(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function we(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ke(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ke(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ke(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ke(f,"constructor",s),ke(s,"constructor",u),u.displayName="GeneratorFunction",ke(s,o,"GeneratorFunction"),ke(f),ke(f,o,"Generator"),ke(f,n,function(){return this}),ke(f,"toString",function(){return"[object Generator]"}),(we=function(){return{w:i,m:h}})()}function ke(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ke=function(e,t,r,n){function i(t,r){ke(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ke(e,t,r,n)}function Se(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Oe(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Se(i,n,o,a,c,"next",e)}function c(e){Se(i,n,o,a,c,"throw",e)}a(void 0)})}}function je(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Pe(n.key),n)}}function Te(e,t,r){return(t=Pe(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pe(e){var t=function(e,t){if("object"!=ye(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ye(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ye(t)?t:t+""}var Ie=function(){return e=function e(t,r){var n=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Te(this,"historyWindows",new L),Te(this,"traverseLock",!1),this.room=t,this.tracker=r,this.tracker.client.on("RoomUpdated",function(e){return n.handleRoomUpdated(e)}),this.tracker.client.on("NewTopic",function(e){return n.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return n.handleTopicDeleted(e)}),this.updateTraverseLock(this.room),this.room.defaultTopic&&this.createHistoryWindowForTopic(this.room.defaultTopic)},t=[{key:"getMessagesWindow",value:(o=Oe(we().m(function e(t){var r,n,o=arguments;return we().w(function(e){for(;;)switch(e.n){case 0:if(r=o.length>1&&void 0!==o[1]&&o[1],this.historyWindows.has(t)||r){e.n=2;break}return e.n=1,this.tracker.rooms.getTopics(this.room.id,[t]);case 1:(n=e.v.get(t))&&this.createHistoryWindowForTopic(n);case 2:return e.a(2,this.historyWindows.get(t))}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoomUpdated",value:(n=Oe(we().m(function e(t){var r,n,o,i;return we().w(function(e){for(;;)switch(e.n){case 0:if(this.room.id!==t.room.id){e.n=3;break}this.room=t.room,this.updateTraverseLock(t.room),t.room.defaultTopic&&this.createHistoryWindowForTopic(t.room.defaultTopic),r=0,n=Array.from(this.historyWindows.items);case 1:if(!(r<n.length)){e.n=3;break}return o=ve(n[r],2),i=o[1],e.n=2,i.setTraverseLock(this.traverseLock);case 2:r++,e.n=1;break;case 3:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleNewTopic",value:function(e){this.room.id===e.roomId&&this.createHistoryWindowForTopic(e.topic)}},{key:"handleTopicDeleted",value:function(e){this.room.id===e.location.roomId&&this.historyWindows.delete(e.location.topicId)}},{key:"createHistoryWindowForTopic",value:function(e){var t=this;if(!this.historyWindows.has(e.id)){var r=new de(this.room.id,e.id,this.tracker);if(r.setTraverseLock(this.traverseLock),this.historyWindows.set([e.id,r]),r.on("reftopicsdeleted",function(e){var r,n,o=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=be(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}(e);try{for(o.s();!(n=o.n()).done;){var i=n.value;t.historyWindows.delete(i)}}catch(e){o.e(e)}finally{o.f()}(r=t.tracker.rooms)._deleteTopicsFromRoom.apply(r,[t.room.id].concat(me(e)))}),e.refMessage){var n=this.historyWindows.get(e.refMessage.location.topicId);null==n||n._updateMessageReference(e)}}}},{key:"updateTraverseLock",value:function(e){this.traverseLock="Ephemeral"===e.history.mode}}],t&&je(e.prototype,t),r&&je(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Ee(e){return Ee="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ee(e)}function Re(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return _e(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(_e(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,_e(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,_e(f,"constructor",s),_e(s,"constructor",u),u.displayName="GeneratorFunction",_e(s,o,"GeneratorFunction"),_e(f),_e(f,o,"Generator"),_e(f,n,function(){return this}),_e(f,"toString",function(){return"[object Generator]"}),(Re=function(){return{w:i,m:h}})()}function _e(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}_e=function(e,t,r,n){function i(t,r){_e(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},_e(e,t,r,n)}function Ae(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Me(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ae(i,n,o,a,c,"next",e)}function c(e){Ae(i,n,o,a,c,"throw",e)}a(void 0)})}}function Fe(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Ce(n.key),n)}}function Le(e,t,r){return(t=Ce(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Ce(e){var t=function(e,t){if("object"!=Ee(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ee(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ee(t)?t:t+""}var xe=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Le(this,"roomHistories",new L),Le(this,"deferredSession",new H),this.tracker=t,this.tracker.client.on("Session",function(e){return r.handleSession(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)})},t=[{key:"getRoomHistory",value:(o=Me(Re().m(function e(t){return Re().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roomHistories.get(t))}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"_resolveLastMessage",value:(n=Me(Re().m(function e(t){var r,n,o;return Re().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.getRoomHistory(t.roomId).then(function(e){return null==e?void 0:e.getMessagesWindow(t.topicId,!0)}).then(function(e){return(null==e?void 0:e.hasLatest)&&e.getAt(e.length-1)});case 1:if(r=e.v){e.n=3;break}return e.n=2,this.tracker.client.send("GetMessages",{location:t,limit:1});case 2:o=e.v,r=null===(n=o.data)||void 0===n?void 0:n.messages[0];case 3:return e.a(2,r||null)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"createHistoryForNewRoom",value:function(e){this.roomHistories.set([e.id,new Ie(e,this.tracker)])}},{key:"handleRoomDeleted",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleRoomJoin",value:function(e){this.createHistoryForNewRoom(e.room)}},{key:"handleRoomLeft",value:function(e){this.roomHistories.delete(e.id)}},{key:"handleSession",value:function(e){var t=this;this.roomHistories.deleteAll(),e.state.rooms.forEach(function(e){return t.createHistoryForNewRoom(e)}),this.deferredSession.resolve()}}],t&&Fe(e.prototype,t),r&&Fe(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Ge(e){return Ge="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ge(e)}function De(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Ue(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?De(Object(r),!0).forEach(function(t){Ze(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):De(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Ne(e){return function(e){if(Array.isArray(e))return Je(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||We(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Be(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=We(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function We(e,t){if(e){if("string"==typeof e)return Je(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Je(e,t):void 0}}function Je(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function He(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return $e(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):($e(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,$e(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,$e(f,"constructor",s),$e(s,"constructor",u),u.displayName="GeneratorFunction",$e(s,o,"GeneratorFunction"),$e(f),$e(f,o,"Generator"),$e(f,n,function(){return this}),$e(f,"toString",function(){return"[object Generator]"}),(He=function(){return{w:i,m:h}})()}function $e(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}$e=function(e,t,r,n){function i(t,r){$e(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},$e(e,t,r,n)}function Qe(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Ve(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Qe(i,n,o,a,c,"next",e)}function c(e){Qe(i,n,o,a,c,"throw",e)}a(void 0)})}}function ze(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,et(n.key),n)}}function qe(e,t,r){return t=Ye(t),function(e,t){if(t&&("object"==Ge(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Ke()?Reflect.construct(t,r||[],Ye(e).constructor):t.apply(e,r))}function Ke(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Ke=function(){return!!e})()}function Ye(e){return Ye=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Ye(e)}function Xe(e,t){return Xe=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Xe(e,t)}function Ze(e,t,r){return(t=et(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function et(e){var t=function(e,t){if("object"!=Ge(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ge(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ge(t)?t:t+""}var tt=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),Ze(r=qe(this,t),"followedTopics",new L),Ze(r,"followedTopicsPromises",new $),Ze(r,"deferredSession",new H),Ze(r,"summariesCache",new Map),r.tracker=e,r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoin(e)}),r.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),r.tracker.client.on("FollowedTopicUpdated",function(e){return r.handleFollowedTopicUpdated(e)}),r.tracker.client.on("TopicFollowed",function(e){return r.handleTopicFollowed(e)}),r.tracker.client.on("TopicUnfollowed",function(e){return r.handleTopicUnfollowed(e)}),r.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Xe(e,t)}(t,e),r=t,n=[{key:"cacheForSpace",value:(l=Ve(He().m(function e(t){var r,n,o,i,a=this;return He().w(function(e){for(;;)switch(e.n){case 0:if(!(i=t)){e.n=2;break}return e.n=1,this.tracker.spaces.get();case 1:i=!e.v.has(t);case 2:if(!i){e.n=3;break}throw new Error("You are not in space ".concat(t));case 3:return e.n=4,this.tracker.rooms.get();case 4:if(r=e.v,(n=t?r.findBy("spaceId",t).items.map(function(e){return e.id}):r.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id})).length){e.n=5;break}return e.a(2);case 5:if(!n.every(function(e){return a.followedTopics.has(e)})){e.n=6;break}return e.a(2);case 6:return o="space_fetch_".concat(t||"spaceless"),this.followedTopicsPromises.notExist(o)&&this.followedTopicsPromises.registerByFunction(Ve(He().m(function e(){var r;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,a.tracker.client.send("GetFollowedTopics",{location:{spaceId:t}});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:a.setFollowedTopicsArray(n,r.data.followedTopics);case 3:return e.a(2)}},e)})),o),e.n=7,this.followedTopicsPromises.get(o);case 7:return e.a(2)}},e,this)})),function(e){return l.apply(this,arguments)})},{key:"getForRoom",value:(s=Ve(He().m(function e(t){var r=this;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:if(e.v.has(t)){e.n=2;break}return e.a(2,void 0);case 2:if(this.followedTopics.has(t)){e.n=3;break}return this.followedTopicsPromises.notExist(t)&&this.followedTopicsPromises.registerByFunction(Ve(He().m(function e(){var n;return He().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetFollowedTopics",{location:{roomId:t}});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.setFollowedTopicsArray([t],n.data.followedTopics);case 3:return e.a(2)}},e)})),t),e.n=3,this.followedTopicsPromises.get(t);case 3:return e.a(2,this.followedTopics.get(t))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"ackRoom",value:(u=Ve(He().m(function e(t){var r,n,o,i,a;return He().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.getForRoom(t);case 1:if(r=e.v){e.n=2;break}return e.a(2);case 2:n=Be(r.items),e.p=3,n.s();case 4:if((o=n.n()).done){e.n=6;break}if(!(i=o.value).isUnread){e.n=5;break}return e.n=5,this.tracker.client.send("Ack",{location:i.location});case 5:e.n=4;break;case 6:e.n=8;break;case 7:e.p=7,a=e.v,n.e(a);case 8:return e.p=8,n.f(),e.f(8);case 9:return e.a(2)}},e,this,[[3,7,8,9]])})),function(e){return u.apply(this,arguments)})},{key:"summarize",value:(c=Ve(He().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b;return He().w(function(e){for(;;)switch(e.p=e.n){case 0:if(r=t.topicId?"topic:".concat(t.roomId,":").concat(t.topicId):t.roomId?"room:".concat(t.roomId):t.spaceId?"space:".concat(t.spaceId):"spaceless",!this.summariesCache.has(r)){e.n=1;break}return e.a(2,this.summariesCache.get(r));case 1:return n=[],e.n=2,this.tracker.rooms.get();case 2:if(i=e.v,!t.topicId){e.n=4;break}if(t.roomId){e.n=3;break}throw new Error("roomId is required when querying by topicId");case 3:n=[t.roomId],o=t.topicId,e.n=9;break;case 4:if(!t.roomId){e.n=5;break}n=[t.roomId],e.n=9;break;case 5:if(!t.spaceId){e.n=7;break}return e.n=6,this.cacheForSpace(t.spaceId);case 6:n=i.findBy("spaceId",t.spaceId).items.map(function(e){return e.id}),e.n=9;break;case 7:return e.n=8,this.cacheForSpace(null);case 8:n=i.items.filter(function(e){return!e.spaceId}).map(function(e){return e.id});case 9:a=0,c=!1,u=Be(n),e.p=10,u.s();case 11:if((s=u.n()).done){e.n=22;break}return l=s.value,e.n=12,this.getForRoom(l);case 12:if(f=e.v){e.n=13;break}return e.a(3,21);case 13:h=Be(f.items),e.p=14,h.s();case 15:if((p=h.n()).done){e.n=18;break}if(y=p.value,!o||y.location.topicId===o){e.n=16;break}return e.a(3,17);case 16:y.isUnread&&(c=!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){this.followedTopics.deleteAll(),this.followedTopicsPromises.forgetAll(),this.invalidateUnreadSummaries(),this.deferredSession.resolve()}},{key:"handleNewMessage",value:function(e){this.updateLocallyFollowedTopicOnNewMessage(e)}},{key:"handleFollowedTopicUpdated",value:function(e){var t;null===(t=this.followedTopics.get(e.followedTopic.location.roomId))||void 0===t||t.set(e.followedTopic),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleTopicFollowed",value:function(e){this.setFollowedTopicsArray([e.followedTopic.location.roomId],[e.followedTopic]),this.invalidateUnreadSummaries(e.followedTopic.location.roomId,e.followedTopic.location.topicId)}},{key:"handleTopicUnfollowed",value:function(e){var t;null===(t=this.followedTopics.get(e.location.roomId))||void 0===t||t.delete(e.location.topicId),this.invalidateUnreadSummaries(e.location.roomId,e.location.topicId)}},{key:"handleRoomDeleted",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleRoomJoin",value:function(e){this.clearRoomFollowedTopicsStructures(e.room.id)}},{key:"handleRoomLeft",value:function(e){this.clearRoomFollowedTopicsStructures(e.id)}},{key:"handleNewTopic",value:(a=Ve(He().m(function e(t){var r,n;return He().w(function(e){for(;;)switch(e.n){case 0:if(!this.followedTopics.has(t.roomId)){e.n=2;break}return e.n=1,this.tracker.client.send("GetFollowedTopics",{location:{roomId:t.roomId,topicId:t.topic.id}});case 1:r=e.v,(n=r.data.followedTopics[0])&&(this.followedTopics.get(t.roomId).set(n),this.invalidateUnreadSummaries(t.roomId,t.topic.id));case 2:return e.a(2)}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t;null===(t=this.followedTopics.get(e.location.roomId))||void 0===t||t.delete(e.location.topicId),this.invalidateUnreadSummaries(e.location.roomId,e.location.topicId)}},{key:"invalidateUnreadSummaries",value:function(e,t){if(e){if(this.summariesCache.delete("room:".concat(e)),t)this.summariesCache.delete("topic:".concat(e,":").concat(t));else{var r,n=Be(this.summariesCache.keys());try{for(n.s();!(r=n.n()).done;){var o=r.value;o.startsWith("topic:".concat(e,":"))&&this.summariesCache.delete(o)}}catch(e){n.e(e)}finally{n.f()}}var i,a=Be(this.summariesCache.keys());try{for(a.s();!(i=a.n()).done;){var c=i.value;(c.startsWith("space:")||"spaceless"===c)&&this.summariesCache.delete(c)}}catch(e){a.e(e)}finally{a.f()}}else this.summariesCache.clear();this.emit("change")}},{key:"invalidateUnreadSummariesForRooms",value:function(e){var t=this,r=new Set(e);e.forEach(function(e){t.summariesCache.delete("room:".concat(e))});var n,o=Be(this.summariesCache.keys());try{for(o.s();!(n=o.n()).done;){var i=n.value;if(i.startsWith("space:")||"spaceless"===i)this.summariesCache.delete(i);else if(i.startsWith("topic:")){var a=i.split(":");a.length>=2&&r.has(a[1])&&this.summariesCache.delete(i)}}}catch(e){o.e(e)}finally{o.f()}this.emit("change")}},{key:"updateLocallyFollowedTopicOnNewMessage",value:(i=Ve(He().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h;return He().w(function(e){for(;;)switch(e.n){case 0:if(r=this.followedTopics.get(t.message.location.roomId),n=null==r?void 0:r.get(t.message.location.topicId),r&&n&&"Ephemeral"!==t.message.type){e.n=1;break}return e.a(2);case 1:return e.n=2,this.tracker.getMe();case 2:if(o=e.v,t.message.author.user.id!==o.id){e.n=3;break}i={missed:0,lastAckMessageId:t.message.id},e.n=6;break;case 3:if("Text"!==t.message.type){e.n=5;break}return e.n=4,this.tracker.rooms.getMe(t.message.location.roomId);case 4:s=e.v,l=[].concat(Ne(null!==(a=null===(c=s.spaceMember)||void 0===c?void 0:c.roles)&&void 0!==a?a:[]),Ne(null!==(u=s.roles)&&void 0!==u?u:[])),f=[].concat(Ne(l.map(function(e){return"<@&".concat(e,">")})),["<@".concat(o.id,">")]),h=f.some(function(e){return t.message.content.includes(e)}),i={missed:null===n.missed?null:n.missed+1,isUnread:!0,mentionCount:n.mentionCount+(h?1:0)},e.n=6;break;case 5:i={missed:null===n.missed?null:n.missed+1,isUnread:!0};case 6:r.set(Ue(Ue({},n),i)),this.invalidateUnreadSummaries(t.message.location.roomId,t.message.location.topicId);case 7:return e.a(2)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"setFollowedTopicsArray",value:function(e,t){var r=this,n={};t.forEach(function(e){var t,r;null!==(r=n[t=e.location.roomId])&&void 0!==r||(n[t]=[]),n[e.location.roomId].push(e)}),e.forEach(function(e){var t;r.followedTopics.has(e)||r.followedTopics.set([e,new G(function(e){return e.location.topicId})]),n[e]&&(t=r.followedTopics.get(e)).set.apply(t,Ne(n[e]))}),this.invalidateUnreadSummariesForRooms(e)}},{key:"clearRoomFollowedTopicsStructures",value:function(e){this.followedTopics.delete(e),this.followedTopicsPromises.forget(e),this.invalidateUnreadSummaries(e)}}],n&&ze(r.prototype,n),o&&ze(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l}(a);function rt(e){return rt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},rt(e)}function nt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ot(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?nt(Object(r),!0).forEach(function(t){dt(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):nt(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function it(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=ct(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function at(e){return function(e){if(Array.isArray(e))return ut(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||ct(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ct(e,t){if(e){if("string"==typeof e)return ut(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ut(e,t):void 0}}function ut(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function st(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return lt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(lt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,lt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,lt(f,"constructor",s),lt(s,"constructor",u),u.displayName="GeneratorFunction",lt(s,o,"GeneratorFunction"),lt(f),lt(f,o,"Generator"),lt(f,n,function(){return this}),lt(f,"toString",function(){return"[object Generator]"}),(st=function(){return{w:i,m:h}})()}function lt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}lt=function(e,t,r,n){function i(t,r){lt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},lt(e,t,r,n)}function ft(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function ht(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){ft(i,n,o,a,c,"next",e)}function c(e){ft(i,n,o,a,c,"throw",e)}a(void 0)})}}function pt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,yt(n.key),n)}}function dt(e,t,r){return(t=yt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function yt(e){var t=function(e,t){if("object"!=rt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=rt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==rt(t)?t:t+""}var mt=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),dt(this,"messages",void 0),dt(this,"followedTopics",void 0),dt(this,"list",new G("id")),dt(this,"topics",new L),dt(this,"members",new L),dt(this,"deferredSession",new H),dt(this,"membersPromises",new $),dt(this,"topicsPromises",new $),this.tracker=t,this.messages=new xe(t),this.followedTopics=new tt(t),this.tracker.client.on("NewMessage",function(e){return r.handleNewMessage(e)}),this.tracker.client.on("MessagesRedacted",function(e){return r.handleMessagesRedacted(e)}),this.tracker.client.on("NewTopic",function(e){return r.handleNewTopic(e)}),this.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),this.tracker.client.on("RoomJoined",function(e){return r.handleRoomJoined(e)}),this.tracker.client.on("RoomLeft",function(e){return r.handleRoomLeft(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("TopicUpdated",function(e){return r.handleTopicUpdated(e)}),this.tracker.client.on("RoomMemberJoined",function(e){return r.handleRoomMemberJoined(e)}),this.tracker.client.on("RoomMemberLeft",function(e){return r.handleRoomMemberLeft(e)}),this.tracker.client.on("RoomMembers",function(e){return r.handleRoomMembers(e)}),this.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getMembers",value:(a=ht(st().m(function e(t){var r=this;return st().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(ht(st().m(function e(){var n;return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetRoomMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleRoomMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=ht(st().m(function e(t){var r,n;return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){var t,n;return(null!==(t=null===(n=e.user)||void 0===n?void 0:n.id)&&void 0!==t?t:e.spaceMember.user.id)===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"get",value:function(){var e=ht(st().m(function e(){return st().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getTopics",value:(o=ht(st().m(function e(t,r){var n,o,i,a,c,u,s,l=this;return st().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:if(null==r||!r.length){e.n=8;break}n=function(e){var r;return!(null!==(r=l.topics.get(t))&&void 0!==r&&r.has(e)||l.topicsPromises.has(t+e))},(o=r.filter(n)).length&&(i=this.tracker.client.send("GetTopics",{roomId:t,topicIds:o}).then(function(e){var t;return null===(t=l.topics.get(e.data.location.roomId))||void 0===t?void 0:t.set.apply(t,at(e.data.topics))}),o.forEach(function(e){return l.topicsPromises.register(i,t+e)})),a=it(r),e.p=2,a.s();case 3:if((c=a.n()).done){e.n=5;break}return u=c.value,e.n=4,this.topicsPromises.get(t+u);case 4:e.n=3;break;case 5:e.n=7;break;case 6:e.p=6,s=e.v,a.e(s);case 7:return e.p=7,a.f(),e.f(7);case 8:return e.a(2,this.topics.get(t))}},e,this,[[2,6,7,8]])})),function(e,t){return o.apply(this,arguments)})},{key:"_deleteTopicsFromRoom",value:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];null===(t=this.topics.get(e))||void 0===t||t.delete.apply(t,n)}},{key:"deleteRoom",value:function(){for(var e,t,r,n,o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];(e=this.list).delete.apply(e,i),(t=this.members).delete.apply(t,i),(r=this.membersPromises).forget.apply(r,i);for(var c=0,u=i;c<u.length;c++){var s,l,f,h=u[c],p=null!==(s=null===(l=this.topics.get(h))||void 0===l?void 0:l.items.map(function(e){return e.id}))&&void 0!==s?s:[];(f=this.followedTopics)._deleteByTopicIds.apply(f,[h].concat(at(p)))}(n=this.topics).delete.apply(n,i)}},{key:"deleteRoomsBySpaceId",value:function(e){this.deleteRoom.apply(this,at(this.list.findBy("spaceId",e).items.map(function(e){return e.id})))}},{key:"handleSpaceMemberUpdated",value:function(e){var t,r=it(this.list.findBy("spaceId",e.spaceId).items);try{for(r.s();!(t=r.n()).done;){var n=t.value,o=this.members.get(n.id);if(o&&o.has(e.userId)){var i=o.get(e.userId),a=e.member;a.user=i.spaceMember.user,o.set(ot(ot({},i),{},{spaceMember:a}))}}}catch(e){r.e(e)}finally{r.f()}}},{key:"handleSpaceMemberLeft",value:function(e){var t=this;this.list.findBy("spaceId",e.spaceId).items.forEach(function(r){var n;return null===(n=t.members.get(r.id))||void 0===n?void 0:n.delete(e.userId)})}},{key:"handleRoomMemberUpdated",value:function(e){var t,r;if(this.members.has(e.roomId)){var n=this.members.get(e.roomId),o=n.get(e.userId),i=e.member,a=null!==(t=null===(r=o.spaceMember)||void 0===r?void 0:r.user)&&void 0!==t?t:o.user;i.spaceMember?i.spaceMember.user=a:i.user=a,n.set(i)}}},{key:"handleSpaceDeleted",value:function(e){this.deleteRoomsBySpaceId(e.id)}},{key:"handleTopicDeleted",value:function(e){var t;this.topics.get(e.location.roomId).delete(e.location.topicId);var r=this.list.get(e.location.roomId);(null===(t=r.defaultTopic)||void 0===t?void 0:t.id)===e.location.topicId&&this.list.set(ot(ot({},r),{},{defaultTopic:null}))}},{key:"handleNewTopic",value:function(e){this.addJoinedRoomTopics(e.roomId,e.topic)}},{key:"addJoinedRoomTopics",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];var o;this.topics.has(e)?(o=this.topics.get(e)).set.apply(o,r):this.topics.set([e,new G("id",r)])}},{key:"handleRoomJoined",value:function(e){this.addJoinedRooms(e.room)}},{key:"handleRoomUpdated",value:function(e){this.list.has(e.room.id)&&this.list.set(e.room)}},{key:"handleRoomDeleted",value:function(e){this.deleteRoom(e.id)}},{key:"handleTopicUpdated",value:function(e){var t,r=this.list.get(e.location.roomId);if(null!==(t=this.topics.get(e.location.roomId))&&void 0!==t&&t.has(e.topic.id)&&this.topics.get(e.location.roomId).set(e.topic),r.defaultTopic.id===e.topic.id){var n=ot({},r);n.defaultTopic=e.topic,this.list.set(n)}}},{key:"addJoinedRooms",value:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];for(var o=0,i=r;o<i.length;o++){var a=i[o];a.defaultTopic&&this.addJoinedRoomTopics(a.id,a.defaultTopic),"Pm"===a.type&&a.recipients&&(this.handleRoomMembers({id:a.id,members:a.recipients.map(function(e){return{user:e,spaceMember:null,roles:null,customColor:null,customNick:null,extras:""}})}),this.membersPromises.register(Promise.resolve(),a.id))}(e=this.list).set.apply(e,r)}},{key:"handleRoomLeft",value:function(e){this.deleteRoom(e.id)}},{key:"handleRoomMemberJoined",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).set(e.member)}},{key:"handleRoomMemberLeft",value:function(e){this.members.has(e.roomId)&&this.members.get(e.roomId).delete(e.userId)}},{key:"handleRoomMembers",value:function(e){this.members.has(e.id)||this.members.set([e.id,new G(function(e){var t,r;return null!==(t=null===(r=e.user)||void 0===r?void 0:r.id)&&void 0!==t?t:e.spaceMember.user.id},e.members)])}},{key:"handleSession",value:function(e){this.list.deleteAll(),this.topics.deleteAll(),this.topicsPromises.forgetAll(),this.members.deleteAll(),this.membersPromises.forgetAll(),this.addJoinedRooms.apply(this,at(e.state.rooms)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){var t;this.members.items.forEach(function(t){var r=t.get(e.user.id);if(r){var n=ot({},r);r.user?n.user=e.user:n.spaceMember.user=e.user,t.set(n)}});var r=[];this.list.items.forEach(function(t){var n;null!==(n=t.recipients)&&void 0!==n&&n.some(function(t){return t.id===e.user.id})&&(t.recipients=t.recipients.map(function(t){return t.id===e.user.id?e.user:t}),r.push(ot({},t)))}),(t=this.list).set.apply(t,r)}},{key:"handleNewMessage",value:function(e){var t,r=this.topics.get(e.message.location.roomId),n=null==r?void 0:r.get(e.message.location.topicId);if(n){var o=ot(ot({},n),{},{messageCount:n.messageCount+1,lastMessage:e.message});r.set(o);var i=this.list.get(e.message.location.roomId);(null===(t=i.defaultTopic)||void 0===t?void 0:t.id)===e.message.location.topicId&&this.list.set(ot(ot({},i),{},{defaultTopic:o}))}}},{key:"handleMessagesRedacted",value:(n=ht(st().m(function e(t){var r,n,o,i,a;return st().w(function(e){for(;;)switch(e.n){case 0:if(r=this.topics.get(t.location.roomId),!(n=null==r?void 0:r.get(t.location.topicId))){e.n=4;break}if(!((o=Math.max(n.messageCount-t.ids.length,0))>0)){e.n=2;break}return e.n=1,this.messages._resolveLastMessage(t.location);case 1:a=e.v,e.n=3;break;case 2:a=null;case 3:i=a,r.set(ot(ot({},n),{},{messageCount:o,lastMessage:i}));case 4:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})}],t&&pt(e.prototype,t),r&&pt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a}();function vt(e){var t,r;return null!==(t=e.user)&&void 0!==t?t:null===(r=e.spaceMember)||void 0===r?void 0:r.user}function bt(e){return bt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},bt(e)}function gt(e){return function(e){if(Array.isArray(e))return wt(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return wt(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wt(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wt(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function kt(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function St(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?kt(Object(r),!0).forEach(function(t){Et(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):kt(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Ot(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return jt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(jt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,jt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,jt(f,"constructor",s),jt(s,"constructor",u),u.displayName="GeneratorFunction",jt(s,o,"GeneratorFunction"),jt(f),jt(f,o,"Generator"),jt(f,n,function(){return this}),jt(f,"toString",function(){return"[object Generator]"}),(Ot=function(){return{w:i,m:h}})()}function jt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}jt=function(e,t,r,n){function i(t,r){jt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},jt(e,t,r,n)}function Tt(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Pt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Tt(i,n,o,a,c,"next",e)}function c(e){Tt(i,n,o,a,c,"throw",e)}a(void 0)})}}function It(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Rt(n.key),n)}}function Et(e,t,r){return(t=Rt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Rt(e){var t=function(e,t){if("object"!=bt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=bt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==bt(t)?t:t+""}var _t=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Et(this,"list",new G("id")),Et(this,"roles",new L),Et(this,"rooms",new L),Et(this,"roomIdToSpaceId",new L),Et(this,"members",new L),Et(this,"deferredSession",new H),Et(this,"roomsPromises",new $),Et(this,"membersPromises",new $),this.tracker=t,this.tracker.client.on("NewRoom",function(e){return r.handleNewRoom(e)}),this.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),this.tracker.client.on("RoomUpdated",function(e){return r.handleRoomUpdated(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceUpdated",function(e){return r.handleSpaceUpdated(e)}),this.tracker.client.on("SpaceJoined",function(e){return r.handleSpaceJoined(e)}),this.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("SpaceMemberJoined",function(e){return r.handleSpaceMemberJoined(e)}),this.tracker.client.on("SpaceMemberLeft",function(e){return r.handleSpaceMemberLeft(e)}),this.tracker.client.on("SpaceMembers",function(e){return r.handleSpaceMembers(e)}),this.tracker.client.on("SpaceRooms",function(e){return r.handleSpaceRooms(e)}),this.tracker.client.on("RoomSummaryUpdated",function(e){return r.handleRoomSummaryUpdated(e)}),this.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),this.tracker.client.on("UserUpdated",function(e){return r.handleUserUpdated(e)}),this.tracker.client.on("NewRole",function(e){return r.handleNewRole(e)}),this.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),this.tracker.client.on("RoleUpdated",function(e){return r.handleRoleUpdated(e)}),this.tracker.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"get",value:function(){var e=Pt(Ot().m(function e(){return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.list)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"getRoles",value:(u=Pt(Ot().m(function e(t){return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this.roles.get(t))}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"getRooms",value:(c=Pt(Ot().m(function e(t){var r=this;return Ot().w(function(e){for(;;)switch(e.n){case 0:return this.roomsPromises.notExist(t)&&this.roomsPromises.registerByFunction(Pt(Ot().m(function e(){var n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceRooms",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceRooms(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.roomsPromises.get(t);case 1:return e.a(2,this.rooms.get(t))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getMembers",value:(a=Pt(Ot().m(function e(t){var r=this;return Ot().w(function(e){for(;;)switch(e.n){case 0:return this.membersPromises.notExist(t)&&this.membersPromises.registerByFunction(Pt(Ot().m(function e(){var n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,r.tracker.client.send("GetSpaceMembers",{id:t});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:r.handleSpaceMembers(n.data);case 3:return e.a(2)}},e)})),t),e.n=1,this.membersPromises.get(t);case 1:return e.a(2,this.members.get(t))}},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getMe",value:(i=Pt(Ot().m(function e(t){var r,n;return Ot().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.getMe();case 1:if(r=e.v.id,this.list.has(t)){e.n=2;break}return e.a(2,void 0);case 2:return e.n=3,this.getMembers(t);case 3:return n=e.v,e.a(2,null==n?void 0:n.items.find(function(e){return e.user.id===r}))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"handleNewRole",value:function(e){var t=this.roles.get(e.spaceId);t.set(e.role),this.list.get(e.spaceId).roles=t.items}},{key:"handleNewRoom",value:function(e){var t;null===(t=this.rooms.get(e.spaceId))||void 0===t||t.set(e.summary),this.roomIdToSpaceId.set([e.summary.id,e.spaceId])}},{key:"handleRoomUpdated",value:function(e){if(e.room.spaceId&&this.rooms.has(e.room.spaceId)){var t=this.rooms.get(e.room.spaceId);t.set(St(St({},t.get(e.room.id)),{},{name:e.room.name,description:e.room.description}))}}},{key:"handleRoomDeleted",value:(o=Pt(Ot().m(function e(t){var r,n,o,i;return Ot().w(function(e){for(;;)switch(e.n){case 0:if(n=this.roomIdToSpaceId.get(t.id),this.roomIdToSpaceId.delete(t.id),n){e.n=1;break}return e.a(2);case 1:o=this.list.get(n),i=!1,null===(r=this.rooms.get(n))||void 0===r||r.delete(t.id),o.systemRoom===t.id&&(o.systemRoom=null,i=!0),o.defaultRooms.includes(t.id)&&(o.defaultRooms=o.defaultRooms.filter(function(e){return e!==t.id}),i=!0),i&&this.list.set(o);case 2:return e.a(2)}},e,this)})),function(e){return o.apply(this,arguments)})},{key:"handleRoleDeleted",value:function(e){var t=this.roles.get(e.spaceId);t.delete(e.id),this.list.get(e.spaceId).roles=t.items}},{key:"handleSpaceUpdated",value:function(e){this.list.set(e.space)}},{key:"handleSpaceDeleted",value:function(e){var t,r,n,o=null!==(t=null===(r=this.rooms.get(e.id))||void 0===r?void 0:r.items.map(function(e){return e.id}))&&void 0!==t?t:[];(n=this.roomIdToSpaceId).delete.apply(n,gt(o)),this.roles.delete(e.id),this.members.delete(e.id),this.membersPromises.forget(e.id),this.rooms.delete(e.id),this.roomsPromises.forget(e.id),this.list.delete(e.id)}},{key:"handleSpaceJoined",value:function(e){this.addJoinedSpaces(e.space)}},{key:"addJoinedSpaces",value:function(){for(var e,t,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];(e=this.roles).set.apply(e,gt(n.map(function(e){return[e.id,new G("id",e.roles)]}))),(t=this.list).set.apply(t,n)}},{key:"handleSpaceMemberJoined",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).set(e.member)}},{key:"handleSpaceMemberLeft",value:function(e){this.members.has(e.spaceId)&&this.members.get(e.spaceId).delete(e.userId)}},{key:"handleSpaceMembers",value:function(e){this.members.has(e.id)||this.members.set([e.id,new G(function(e){return null==e?void 0:e.user.id},e.members)])}},{key:"handleSpaceRooms",value:function(e){var t=this;this.rooms.has(e.id)||(this.rooms.set([e.id,new G("id",e.summaries)]),e.summaries.forEach(function(r){return t.roomIdToSpaceId.set([r.id,e.id])}))}},{key:"handleRoomSummaryUpdated",value:(n=Pt(Ot().m(function e(t){var r,n,o,i,a;return Ot().w(function(e){for(;;)switch(e.n){case 0:if(r=this.roomIdToSpaceId.get(t.summary.id),n=this.roomsPromises.get(r),!r||!n){e.n=2;break}return e.n=1,n;case 1:o=this.rooms.get(r),i=o.get(t.summary.id),a=i?St(St({},i),t.summary):t.summary,o.set(a);case 2:return e.a(2)}},e,this)})),function(e){return n.apply(this,arguments)})},{key:"handleSpaceMemberUpdated",value:function(e){if(this.members.has(e.spaceId)){var t=this.members.get(e.spaceId),r=t.get(e.userId);t.set(St(St({},e.member),{},{user:r.user}))}}},{key:"handleRoleUpdated",value:function(e){var t,r=this.roles.get(e.spaceId),n=r.get(e.role.id),o=e.role,i=[o];n.priority!==o.priority&&i.push.apply(i,gt(function(e,t,r){var n=r.priority-t.priority>0,o=!n,i=[];return e.forEach(function(e){e.id!==r.id&&(n&&t.priority<=e.priority&&(e.priority--,i.push(e)),o&&r.priority<=e.priority&&(e.priority++,i.push(e)))}),i}(r.items,n,o))),(t=this.roles.get(e.spaceId)).set.apply(t,i)}},{key:"handleSession",value:function(e){this.list.deleteAll(),this.roles.deleteAll(),this.rooms.deleteAll(),this.roomsPromises.forgetAll(),this.members.deleteAll(),this.membersPromises.forgetAll(),this.roomIdToSpaceId.deleteAll(),this.addJoinedSpaces.apply(this,gt(e.state.spaces)),this.deferredSession.resolve()}},{key:"handleUserUpdated",value:function(e){this.members.items.forEach(function(t){var r=t.get(e.user.id);r&&t.set(St(St({},r),{},{user:e.user}))})}}],t&&It(e.prototype,t),r&&It(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o,i,a,c,u}();function At(e){return At="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},At(e)}function Mt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,xt(n.key),n)}}function Ft(e,t,r){return t&&Mt(e.prototype,t),r&&Mt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Lt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ct(e,t,r){return(t=xt(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function xt(e){var t=function(e,t){if("object"!=At(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=At(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==At(t)?t:t+""}var Gt=function(e){return e[e.Global=0]="Global",e[e.Space=1]="Space",e[e.Room=2]="Room",e[e.Topic=3]="Topic",e}({}),Dt=Ft(function e(){Lt(this,e),Ct(this,"value",void 0),Ct(this,"maxLayer",void 0)}),Ut=function(){return Ft(function e(){Lt(this,e)},null,[{key:"getNames",value:function(){return Object.keys(this.list)}},{key:"getByName",value:function(e){return this.list[e]}},{key:"canBeDefinedOnLayer",value:function(e,t){if(!this.getByName(e))throw new Error("Invalid permission name: ".concat(e));return t<=this.getByName(e).maxLayer}}])}();function Nt(e){return Nt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Nt(e)}function Bt(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=Ht(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function Wt(e){return function(e){if(Array.isArray(e))return $t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||Ht(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Jt(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);u=!0);}catch(e){s=!0,o=e}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(e,t)||Ht(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ht(e,t){if(e){if("string"==typeof e)return $t(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$t(e,t):void 0}}function $t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Qt(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Vt(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Vt(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Vt(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Vt(f,"constructor",s),Vt(s,"constructor",u),u.displayName="GeneratorFunction",Vt(s,o,"GeneratorFunction"),Vt(f),Vt(f,o,"Generator"),Vt(f,n,function(){return this}),Vt(f,"toString",function(){return"[object Generator]"}),(Qt=function(){return{w:i,m:h}})()}function Vt(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Vt=function(e,t,r,n){function i(t,r){Vt(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Vt(e,t,r,n)}function zt(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function qt(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){zt(i,n,o,a,c,"next",e)}function c(e){zt(i,n,o,a,c,"throw",e)}a(void 0)})}}function Kt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,rr(n.key),n)}}function Yt(e,t,r){return t=Zt(t),function(e,t){if(t&&("object"==Nt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Xt()?Reflect.construct(t,r||[],Zt(e).constructor):t.apply(e,r))}function Xt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Xt=function(){return!!e})()}function Zt(e){return Zt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Zt(e)}function er(e,t){return er=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},er(e,t)}function tr(e,t,r){return(t=rr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function rr(e){var t=function(e,t){if("object"!=Nt(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Nt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Nt(t)?t:t+""}Ct(Ut,"list",{Root:{value:1,maxLayer:Gt.Room},CreateSpaces:{value:2,maxLayer:Gt.Global},ManageSpace:{value:4,maxLayer:Gt.Space},ManageRoles:{value:8,maxLayer:Gt.Space},CreateTopics:{value:32,maxLayer:Gt.Room},ManageTopic:{value:64,maxLayer:Gt.Topic},ManageMemberProfiles:{value:128,maxLayer:Gt.Space},ManageMemberRoles:{value:256,maxLayer:Gt.Room},CreateMessages:{value:512,maxLayer:Gt.Topic},ManagePermissions:{value:1024,maxLayer:Gt.Topic},CreateRooms:{value:2048,maxLayer:Gt.Space},ManageRoom:{value:4096,maxLayer:Gt.Room},CreateEmoticons:{value:8192,maxLayer:Gt.Space},ManageEmoticons:{value:16384,maxLayer:Gt.Space},ManageBans:{value:32768,maxLayer:Gt.Room},Kick:{value:65536,maxLayer:Gt.Room},ChangeOwnNick:{value:1<<17,maxLayer:Gt.Space},ChangeOwnColor:{value:1<<18,maxLayer:Gt.Room},RedactMessages:{value:1<<19,maxLayer:Gt.Topic}});var nr=function(e,t){return[e.spaceId,e.roomId,e.topicId,null==t?void 0:t.type,null==t?void 0:t.userId,null==t?void 0:t.roleId].filter(Boolean).join("/")},or=function(e){return nr(e.location,e.target)},ir=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),tr(r=Yt(this,t),"overwrites",new L),tr(r,"overwritesPromises",new $),r.tracker=e,r.tracker.client.on("PermissionOverwrites",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("PermissionOverwritesUpdated",function(e){return r.handlePermissionOverwrites(e)}),r.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("SpaceLeft",function(e){return r.handleSpaceDeleted(e)}),r.tracker.client.on("RoomDeleted",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("RoomLeft",function(e){return r.handleRoomDeleted(e)}),r.tracker.client.on("TopicDeleted",function(e){return r.handleTopicDeleted(e)}),r.tracker.client.on("RoleDeleted",function(e){return r.handleRoleDeleted(e)}),r.tracker.client.on("SpaceMemberUpdated",function(e){return r.handleSpaceMemberUpdated(e)}),r.tracker.client.on("RoomMemberUpdated",function(e){return r.handleRoomMemberUpdated(e)}),r.tracker.client.on("Session",function(e){return r.handleSession(e)}),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&er(e,t)}(t,e),r=t,n=[{key:"getOverwrites",value:(f=qt(Qt().m(function e(t,r){var n,o=this;return Qt().w(function(e){for(;;)switch(e.n){case 0:return this.validateLocation(t),n=nr(t,r),this.overwritesPromises.notExist(n)&&this.overwritesPromises.registerByFunction(qt(Qt().m(function e(){var n;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,o.tracker.client.send("GetPermissionOverwrites",{location:t,target:r});case 1:if(!(n=e.v).error){e.n=2;break}throw n.error;case 2:o.handlePermissionOverwrites(n.data);case 3:return e.a(2)}},e)})),n),e.n=1,this.overwritesPromises.get(n);case 1:return e.a(2,this.overwrites.get(n))}},e,this)})),function(e,t){return f.apply(this,arguments)})},{key:"check",value:(l=qt(Qt().m(function e(t,r){var n,o;return Qt().w(function(e){for(;;)switch(e.n){case 0:if(t.length){e.n=1;break}throw new Error("Permission names array cannot be empty");case 1:return e.n=2,this.calculatePermissions(r);case 2:return n=e.v,o=[],t.forEach(function(e){~n&Ut.getByName(e).value&&o.push(e)}),e.a(2,{ok:0===o.length,hasAll:0===o.length,hasAny:o.length<t.length,missing:o})}},e,this)})),function(e,t){return l.apply(this,arguments)})},{key:"calculatePermissions",value:(s=qt(Qt().m(function e(t){var r,n,o,i,a,c,u,s,l,f,h,p,d,y,m,v,b,g,w,k,S,O,j,T,P;return Qt().w(function(e){for(;;)switch(e.n){case 0:if(!t.roomId){e.n=2;break}return e.n=1,this.tracker.rooms.get();case 1:v=e.v.get(t.roomId),e.n=3;break;case 2:v=null;case 3:return c=v,t={spaceId:null!==(r=t.spaceId)&&void 0!==r?r:null==c?void 0:c.spaceId,roomId:t.roomId,topicId:t.topicId},this.validateLocation(t),e.n=4,this.tracker.getMe();case 4:return u=e.v.id,e.n=5,this.fetchMembersOrFail(t);case 5:if(s=e.v,l=Jt(s,2),f=l[0],h=l[1],p=[].concat(Wt(null!==(n=null==f?void 0:f.roles)&&void 0!==n?n:[]),Wt(null!==(o=null==h?void 0:h.roles)&&void 0!==o?o:[])),d=[this.getOverwrites({},{type:"User",userId:u}).then(function(e){return e.overwrites})],!(b=t.spaceId)){e.n=9;break}return e.n=6,this.tracker.spaces.get();case 6:if(k=i=e.v,!(w=null!==k)){e.n=7;break}w=void 0!==i;case 7:if(!(g=w)){e.n=8;break}g=i.has(t.spaceId);case 8:b=g;case 9:if(!b){e.n=10;break}y={spaceId:t.spaceId},d.push(this.collectRoleOverwrites(y,p)),d.push(this.getOverwrites(y,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 10:if(c&&(m={spaceId:t.spaceId,roomId:t.roomId},p.length&&d.push(this.collectRoleOverwrites(m,p)),d.push(this.getOverwrites(m,{type:"User",userId:u}).then(function(e){return e.overwrites}))),!(S=t.topicId)){e.n=14;break}return e.n=11,this.tracker.rooms.getTopics(t.roomId);case 11:if(T=a=e.v,!(j=null!==T)){e.n=12;break}j=void 0!==a;case 12:if(!(O=j)){e.n=13;break}O=a.has(t.topicId);case 13:S=O;case 14:if(!S){e.n=15;break}p.length&&d.push(this.collectRoleOverwrites(t,p)),d.push(this.getOverwrites(t,{type:"User",userId:u}).then(function(e){return e.overwrites}));case 15:return P=this,e.n=16,Promise.all(d);case 16:return e.a(2,P.resolveOverwritesHierarchy.call(P,e.v))}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"handlePermissionOverwrites",value:function(e){this.overwrites.set([or(e),e]),this.emit("change")}},{key:"handleSpaceDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr({spaceId:e.id}));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleRoomDeleted",value:(u=qt(Qt().m(function e(t){var r,n,o;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.tracker.rooms.get();case 1:(r=e.v.get(t.id))&&(o=this.deleteOverwritesByIdPrefix(nr({spaceId:r.spaceId,roomId:r.id})),(n=this.overwritesPromises).forget.apply(n,Wt(o)));case 2:return e.a(2)}},e,this)})),function(e){return u.apply(this,arguments)})},{key:"handleTopicDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr(e.location));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleRoleDeleted",value:function(e){var t,r=this.deleteOverwritesByIdPrefix(nr({spaceId:e.spaceId},{type:"Role",roleId:e.id}));(t=this.overwritesPromises).forget.apply(t,Wt(r))}},{key:"handleSpaceMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"handleRoomMemberUpdated",value:function(e){var t;e.userId===(null===(t=this.tracker.me)||void 0===t?void 0:t.id)&&this.emit("change")}},{key:"deleteOverwritesByIdPrefix",value:function(e){var t=this,r=[];return this.overwrites.items.forEach(function(n){var o=or(n);o.startsWith(e)&&(r.push(o),t.overwrites.delete(o))}),r}},{key:"collectRoleOverwrites",value:(c=qt(Qt().m(function e(t,r){var n,o=this;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all(r.map(function(e){return o.getOverwrites(t,{type:"Role",roleId:e})}));case 1:return n=e.v,e.a(2,this.resolveOverwritesFromRolesByOrder(t.spaceId,n))}},e,this)})),function(e,t){return c.apply(this,arguments)})},{key:"resolveOverwritesFromRolesByOrder",value:(a=qt(Qt().m(function e(t,r){var n,o,i,a,c;return Qt().w(function(e){for(;;)switch(e.n){case 0:return n=0,o=0,e.n=1,this.tracker.spaces.getRoles(t);case 1:return i=e.v,a=r.sort(function(e,t){return i.get(e.target.roleId).priority-i.get(t.target.roleId).priority}),c=r.reduce(function(e,t){var r,n,o,i;return Math.max(e,null!==(r=null===(n=t.overwrites.allow)||void 0===n?void 0:n.toString(2).length)&&void 0!==r?r:0,null!==(o=null===(i=t.overwrites.deny)||void 0===i?void 0:i.toString(2).length)&&void 0!==o?o:0)},0),a.forEach(function(e){for(var t,r,i,a,u=e.overwrites,s=null!==(t=null===(r=u.deny)||void 0===r?void 0:r.toString(2).split("").reverse().join(""))&&void 0!==t?t:"",l=null!==(i=null===(a=u.allow)||void 0===a?void 0:a.toString(2).split("").reverse().join(""))&&void 0!==i?i:"",f=0;f<c;f++){var h,p,d=parseInt(null!==(h=s[f])&&void 0!==h?h:"0"),y=parseInt(null!==(p=l[f])&&void 0!==p?p:"0");d&&(o|=1<<f),y&&(n|=1<<f)}}),e.a(2,{allow:n,deny:o})}},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"resolveOverwritesHierarchy",value:function(e){var t,r=0,n=Bt(e);try{for(n.s();!(t=n.n()).done;){var o=t.value;if(o.allow&Ut.getByName("Root").value)return this.getRootAccessValue();r=r&~o.deny|o.allow}}catch(e){n.e(e)}finally{n.f()}return r}},{key:"getRootAccessValue",value:function(){var e,t=0,r=Bt(Ut.getNames());try{for(r.s();!(e=r.n()).done;){var n=e.value;t|=Ut.getByName(n).value}}catch(e){r.e(e)}finally{r.f()}return t}},{key:"fetchMembersOrFail",value:(i=qt(Qt().m(function e(t){var r,n,o,i;return Qt().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,Promise.all([t.spaceId?this.tracker.spaces.getMe(t.spaceId):null,t.roomId?this.tracker.rooms.getMe(t.roomId):null]);case 1:if(r=e.v,n=t.spaceId&&!r[0],o=t.roomId&&!r[1],!n&&!o){e.n=2;break}throw i=n?"space (".concat(t.spaceId,")"):"room (".concat(t.roomId,")"),new Error("Attempting to calculate permissions for a ".concat(i," that the user does not belong to"));case 2:return e.a(2,r)}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"validateLocation",value:function(e){if(e.topicId&&!e.roomId)throw new Error("Corrupted arguments hierarchy")}},{key:"handleSession",value:function(e){this.overwrites.deleteAll(),this.overwritesPromises.forgetAll()}}],n&&Kt(r.prototype,n),o&&Kt(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c,u,s,l,f}(a);function ar(e){return ar="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ar(e)}function cr(e){return function(e){if(Array.isArray(e))return ur(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return ur(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ur(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ur(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function sr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return lr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(lr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,lr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,lr(f,"constructor",s),lr(s,"constructor",u),u.displayName="GeneratorFunction",lr(s,o,"GeneratorFunction"),lr(f),lr(f,o,"Generator"),lr(f,n,function(){return this}),lr(f,"toString",function(){return"[object Generator]"}),(sr=function(){return{w:i,m:h}})()}function lr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}lr=function(e,t,r,n){function i(t,r){lr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},lr(e,t,r,n)}function fr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function hr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){fr(i,n,o,a,c,"next",e)}function c(e){fr(i,n,o,a,c,"throw",e)}a(void 0)})}}function pr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,yr(n.key),n)}}function dr(e,t,r){return(t=yr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function yr(e){var t=function(e,t){if("object"!=ar(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=ar(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==ar(t)?t:t+""}var mr="global",vr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),dr(this,"list",new L),dr(this,"emoticonsPromises",new $),this.tracker=t,this.tracker.client.on("Emoticons",function(e){return r.handleEmoticons(e)}),this.tracker.client.on("NewEmoticon",function(e){return r.handleNewEmoticon(e)}),this.tracker.client.on("EmoticonDeleted",function(e){return r.handleEmoticonDeleted(e)}),this.tracker.client.on("SpaceDeleted",function(e){return r.handleSpaceDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=hr(sr().m(function e(t){var r,n=this;return sr().w(function(e){for(;;)switch(e.n){case 0:return r=null!=t?t:mr,this.emoticonsPromises.notExist(r)&&this.emoticonsPromises.registerByFunction(hr(sr().m(function e(){var r;return sr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,n.tracker.client.send("GetEmoticons",{spaceId:t});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:n.handleEmoticons(r.data);case 3:return e.a(2)}},e)})),r),e.n=1,this.emoticonsPromises.get(r);case 1:return e.a(2,this.list.get(r))}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"handleEmoticons",value:function(e){var t,r=null!==(t=e.location.spaceId)&&void 0!==t?t:mr;this.list.has(r)||this.list.set([r,new G("id")]);var n=this.list.get(r);n.set.apply(n,cr(e.emoticons))}},{key:"handleNewEmoticon",value:function(e){var t,r=this.list.get(null!==(t=e.emoticon.spaceId)&&void 0!==t?t:mr);null==r||r.set(e.emoticon)}},{key:"handleEmoticonDeleted",value:function(e){var t,r=this.list.get(null!==(t=e.spaceId)&&void 0!==t?t:mr);null==r||r.delete(e.emoticonId)}},{key:"handleSpaceDeleted",value:function(e){this.list.delete(e.id)}},{key:"handleSession",value:function(){this.list.deleteAll(),this.emoticonsPromises.forgetAll()}}],t&&pr(e.prototype,t),r&&pr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r}();function br(e){return br="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},br(e)}function gr(e){return function(e){if(Array.isArray(e))return wr(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return wr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wr(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function wr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function kr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Sr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Sr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Sr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Sr(f,"constructor",s),Sr(s,"constructor",u),u.displayName="GeneratorFunction",Sr(s,o,"GeneratorFunction"),Sr(f),Sr(f,o,"Generator"),Sr(f,n,function(){return this}),Sr(f,"toString",function(){return"[object Generator]"}),(kr=function(){return{w:i,m:h}})()}function Sr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Sr=function(e,t,r,n){function i(t,r){Sr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Sr(e,t,r,n)}function Or(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Pr(n.key),n)}}function Tr(e,t,r){return(t=Pr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Pr(e){var t=function(e,t){if("object"!=br(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=br(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==br(t)?t:t+""}var Ir=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Tr(this,"onlineStatus",new a),Tr(this,"users",new G("id")),this.tracker=t,t.client.on("UserUpdated",function(e){return r.handleUsers([e.user])}),t.client.on("RoomMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMemberJoined",function(e){return r.handleMembers([e.member])}),t.client.on("SpaceMembers",function(e){return r.handleMembers(e.members)}),t.client.on("RoomMembers",function(e){return r.handleMembers(e.members)}),t.client.on("Messages",function(e){return r.handleUsers(e.messages.map(function(e){return e.author.user}))}),t.client.on("NewMessage",function(e){return r.handleUsers([e.message.author.user])}),t.client.on("Session",function(e){return r.handleSession(e)})},t=[{key:"getAvailable",value:(n=kr().m(function e(){return kr().w(function(e){for(;;)if(0===e.n)return e.a(2,this.users)},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Or(i,r,o,a,c,"next",e)}function c(e){Or(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleMembers",value:function(e){this.handleUsers(e.map(vt))}},{key:"handleSession",value:function(e){this.users.deleteAll(),this.handleUsers([e.user])}},{key:"handleUsers",value:function(e){var t,r=this;e.forEach(function(e){var t=r.users.get(e.id);t&&t.online!==e.online&&r.onlineStatus.emit("change",e)}),(t=this.users).set.apply(t,gr(e))}}],t&&jr(e.prototype,t),r&&jr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Er(e){return Er="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Er(e)}function Rr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return _r(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(_r(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,_r(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,_r(f,"constructor",s),_r(s,"constructor",u),u.displayName="GeneratorFunction",_r(s,o,"GeneratorFunction"),_r(f),_r(f,o,"Generator"),_r(f,n,function(){return this}),_r(f,"toString",function(){return"[object Generator]"}),(Rr=function(){return{w:i,m:h}})()}function _r(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}_r=function(e,t,r,n){function i(t,r){_r(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},_r(e,t,r,n)}function Ar(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Mr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Ar(i,n,o,a,c,"next",e)}function c(e){Ar(i,n,o,a,c,"throw",e)}a(void 0)})}}function Fr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Cr(n.key),n)}}function Lr(e,t,r){return(t=Cr(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Cr(e){var t=function(e,t){if("object"!=Er(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Er(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Er(t)?t:t+""}var xr=function(e,t){return"".concat(e,"-").concat(t)},Gr=function(e){return xr(e.refUser.id,e.type)},Dr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Lr(this,"relationships",new G(Gr)),Lr(this,"promises",new $),this.tracker=t,this.tracker.client.on("Relationships",function(e){return r.handleRelationships(e)}),this.tracker.client.on("NewRelationship",function(e){return r.handleNewRelationship(e)}),this.tracker.client.on("RelationshipDeleted",function(e){return r.handleRelationshipDeleted(e)}),this.tracker.client.on("Session",function(){return r.handleSession()})},t=[{key:"get",value:function(){var e=Mr(Rr().m(function e(){var t=this;return Rr().w(function(e){for(;;)switch(e.n){case 0:return this.promises.notExist("all")&&this.promises.registerByFunction(Mr(Rr().m(function e(){var r;return Rr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,t.tracker.client.send("GetRelationships",{});case 1:if(!(r=e.v).error){e.n=2;break}throw r.error;case 2:return e.a(2)}},e)})),"all"),e.n=1,this.promises.get("all");case 1:return e.a(2,this.relationships)}},e,this)}));return function(){return e.apply(this,arguments)}}()},{key:"exists",value:(n=Mr(Rr().m(function e(t,r){return Rr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.get();case 1:return e.a(2,this.relationships.has(xr(t,r)))}},e,this)})),function(e,t){return n.apply(this,arguments)})},{key:"handleRelationships",value:function(e){var t=this;this.relationships.deleteAll(),e.relationships.forEach(function(e){t.relationships.set(e)})}},{key:"handleNewRelationship",value:function(e){this.promises.has("all")&&this.relationships.set(e.relationship)}},{key:"handleRelationshipDeleted",value:function(e){this.promises.has("all")&&this.relationships.delete(Gr(e.relationship))}},{key:"handleSession",value:function(){this.promises.forgetAll(),this.relationships.deleteAll()}}],t&&Fr(e.prototype,t),r&&Fr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n}();function Ur(e){return Ur="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Ur(e)}function Nr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Br(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Br(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Br(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Br(f,"constructor",s),Br(s,"constructor",u),u.displayName="GeneratorFunction",Br(s,o,"GeneratorFunction"),Br(f),Br(f,o,"Generator"),Br(f,n,function(){return this}),Br(f,"toString",function(){return"[object Generator]"}),(Nr=function(){return{w:i,m:h}})()}function Br(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Br=function(e,t,r,n){function i(t,r){Br(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Br(e,t,r,n)}function Wr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Jr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,$r(n.key),n)}}function Hr(e,t,r){return(t=$r(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function $r(e){var t=function(e,t){if("object"!=Ur(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Ur(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Ur(t)?t:t+""}var Qr=function(){return e=function e(t){var r=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Hr(this,"client",void 0),Hr(this,"permissions",void 0),Hr(this,"rooms",void 0),Hr(this,"spaces",void 0),Hr(this,"emoticons",void 0),Hr(this,"users",void 0),Hr(this,"relationships",void 0),Hr(this,"_me",null),Hr(this,"deferredSession",new H),this.client=t,this.client.on("Session",function(e){return r.handleSession(e)}),this.permissions=new ir(this),this.rooms=new mt(this),this.spaces=new _t(this),this.emoticons=new vr(this),this.users=new Ir(this),this.relationships=new Dr(this)},t=[{key:"me",get:function(){return this._me}},{key:"getMe",value:(n=Nr().m(function e(){return Nr().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.deferredSession.promise;case 1:return e.a(2,this._me)}},e,this)}),o=function(){var e=this,t=arguments;return new Promise(function(r,o){var i=n.apply(e,t);function a(e){Wr(i,r,o,a,c,"next",e)}function c(e){Wr(i,r,o,a,c,"throw",e)}a(void 0)})},function(){return o.apply(this,arguments)})},{key:"handleSession",value:function(e){this._me=e.user,this.deferredSession.resolve()}}],t&&Jr(e.prototype,t),r&&Jr(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Vr(e){return Vr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Vr(e)}function zr(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return qr(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(qr(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,qr(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,qr(f,"constructor",s),qr(s,"constructor",u),u.displayName="GeneratorFunction",qr(s,o,"GeneratorFunction"),qr(f),qr(f,o,"Generator"),qr(f,n,function(){return this}),qr(f,"toString",function(){return"[object Generator]"}),(zr=function(){return{w:i,m:h}})()}function qr(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}qr=function(e,t,r,n){function i(t,r){qr(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},qr(e,t,r,n)}function Kr(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Yr(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Kr(i,n,o,a,c,"next",e)}function c(e){Kr(i,n,o,a,c,"throw",e)}a(void 0)})}}function Xr(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,on(n.key),n)}}function Zr(e,t,r){return t=tn(t),function(e,t){if(t&&("object"==Vr(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,en()?Reflect.construct(t,r||[],tn(e).constructor):t.apply(e,r))}function en(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(en=function(){return!!e})()}function tn(e){return tn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},tn(e)}function rn(e,t){return rn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},rn(e,t)}function nn(e,t,r){return(t=on(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function on(e){var t=function(e,t){if("object"!=Vr(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Vr(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Vr(t)?t:t+""}var an=function(e){return e.connect="connect",e.disconnect="disconnect",e.message="message",e.error="error",e}(an||{}),cn=function(e){function t(e){var r,n,o,i,a,c,u,s,l;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),nn(l=Zr(this,t),"Event",an),nn(l,"state",void 0),nn(l,"ws",null),nn(l,"sendQueue",[]),nn(l,"connectingTimeoutId",void 0),nn(l,"authenticated",void 0),nn(l,"authenticatedResolvers",void 0),nn(l,"pingMonitorInterval",void 0),nn(l,"inFlightPingTimeout",void 0),nn(l,"lastReceivedMessageAt",void 0),l.options=e,(null===(r=l.options.stateTracking)||void 0===r||r)&&(l.state=new Qr(l)),null!==(n=e.ping)&&void 0!==n||(e.ping={}),null!==(i=(o=e.ping).enabled)&&void 0!==i||(o.enabled=!0),null!==(c=(a=e.ping).noActivityTimeoutMs)&&void 0!==c||(a.noActivityTimeoutMs=15e3),null!==(s=(u=e.ping).pongBackTimeoutMs)&&void 0!==s||(u.pongBackTimeoutMs=5e3),l}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&rn(e,t)}(t,e),r=t,n=[{key:"connect",value:(a=Yr(zr().m(function e(){var t,r,n,o=this;return zr().w(function(e){for(;;)switch(e.n){case 0:if(!this.isOpenWsState()&&!this.isConnectingWsState()){e.n=1;break}return e.a(2);case 1:return(n=new URLSearchParams(null!==(t=this.options.queryParams)&&void 0!==t?t:{})).set("token",this.options.token),this.ws=new WebSocket("".concat(this.options.url,"?").concat(n)),this.ws.onclose=function(e){return o.onClose(e)},this.ws.onmessage=function(e){return o.onMessage(e)},this.connectingTimeoutId=setTimeout(function(){return o.triggerConnectionTimeout()},null!==(r=this.options.connectingTimeoutMs)&&void 0!==r?r:1e4),this.authenticated=!1,e.a(2,new Promise(function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return o.authenticatedResolvers=t}))}},e,this)})),function(){return a.apply(this,arguments)})},{key:"disconnect",value:function(){var e;this.sendQueue=[],null===(e=this.ws)||void 0===e||e.close(1e3),this.ws=null}},{key:"send",value:(i=Yr(zr().m(function e(t,r){var n,o;return zr().w(function(e){for(;;)switch(e.n){case 0:if(n=this.createEnvelope(t,r),o=this.createPromiseFromCommandEnvelope(n),!(this.isConnectingWsState()||!this.authenticated&&this.isOpenWsState())){e.n=1;break}return this.sendQueue.push(n),e.a(2,o);case 1:return this.sendEnvelope(n),e.a(2,o)}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"isReady",get:function(){return this.isOpenWsState()&&this.authenticated}},{key:"sendEnvelope",value:function(e){var t,r;this.isReady?this.ws.send(JSON.stringify(e)):this.handleEnvelopeSendError(e,new Error("Cannot send - client is not ready (state=".concat(null!==(t=null===(r=this.ws)||void 0===r?void 0:r.readyState)&&void 0!==t?t:"[no connection]","; authenticated=").concat(this.authenticated,")")))}},{key:"onMessage",value:function(e){this.lastReceivedMessageAt=Date.now();var t=JSON.parse(e.data);if(this.handleIncomingEnvelope(t),this.emit(t.type,t.data),this.emit(this.Event.message,t),!this.authenticated){var r="Bye"!==t.type;this.authenticated=r,r?(this.startConnectionMonitor(),this.authenticatedResolvers[0](),this.emit(this.Event.connect),this.sendFromQueue()):this.authenticatedResolvers[1](t.data)}}},{key:"onClose",value:function(e){this.stopConnectionMonitor(),clearTimeout(this.connectingTimeoutId);var t=1e3!==e.code;t&&this.connect(),this.emit(this.Event.disconnect,t)}},{key:"sendFromQueue",value:function(){var e=this,t=0,r=function(){var r,o=e.sendQueue[n];setTimeout(function(){return e.sendEnvelope(o)},t),t+=null!==(r=e.options.awaitQueueSendDelayMs)&&void 0!==r?r:500};for(var n in this.sendQueue)r();this.sendQueue=[],clearTimeout(this.connectingTimeoutId)}},{key:"triggerConnectionTimeout",value:function(){this.disconnect(),this.emit(this.Event.error,new Error("Connection timeout"))}},{key:"isConnectingWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.CONNECTING}},{key:"isOpenWsState",value:function(){return this.ws&&this.ws.readyState===this.ws.OPEN}},{key:"startConnectionMonitor",value:function(){var e=this;this.options.ping.enabled&&(this.lastReceivedMessageAt=Date.now(),this.pingMonitorInterval=setInterval(Yr(zr().m(function t(){return zr().w(function(t){for(;;)switch(t.n){case 0:if(e.isReady&&!e.inFlightPingTimeout){t.n=1;break}return t.a(2);case 1:if(!(Date.now()-e.lastReceivedMessageAt<e.options.ping.noActivityTimeoutMs)){t.n=2;break}return t.a(2);case 2:e.inFlightPingTimeout=setTimeout(function(){e.inFlightPingTimeout=void 0,e.ws.close(3e3)},e.options.ping.pongBackTimeoutMs),e.send("Ping",{}).then(function(){clearTimeout(e.inFlightPingTimeout),e.inFlightPingTimeout=void 0});case 3:return t.a(2)}},t)})),1e3))}},{key:"stopConnectionMonitor",value:function(){this.inFlightPingTimeout&&(clearTimeout(this.inFlightPingTimeout),this.inFlightPingTimeout=void 0),this.pingMonitorInterval&&(clearInterval(this.pingMonitorInterval),this.pingMonitorInterval=void 0)}}],n&&Xr(r.prototype,n),o&&Xr(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function un(e){return un="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},un(e)}function sn(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return ln(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(ln(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,ln(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,ln(f,"constructor",s),ln(s,"constructor",u),u.displayName="GeneratorFunction",ln(s,o,"GeneratorFunction"),ln(f),ln(f,o,"Generator"),ln(f,n,function(){return this}),ln(f,"toString",function(){return"[object Generator]"}),(sn=function(){return{w:i,m:h}})()}function ln(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}ln=function(e,t,r,n){function i(t,r){ln(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},ln(e,t,r,n)}function fn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function hn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){fn(i,n,o,a,c,"next",e)}function c(e){fn(i,n,o,a,c,"throw",e)}a(void 0)})}}function pn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,gn(n.key),n)}}function dn(e,t,r){return t=mn(t),function(e,t){if(t&&("object"==un(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,yn()?Reflect.construct(t,r||[],mn(e).constructor):t.apply(e,r))}function yn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(yn=function(){return!!e})()}function mn(e){return mn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},mn(e)}function vn(e,t){return vn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},vn(e,t)}function bn(e,t,r){return(t=gn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function gn(e){var t=function(e,t){if("object"!=un(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=un(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==un(t)?t:t+""}var wn=function(e){return e.message="message",e.error="error",e.destroy="destroy",e}(wn||{}),kn=function(e){function t(e){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),bn(r=dn(this,t),"Event",wn),bn(r,"sendStack",void 0),r.options=e,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&vn(e,t)}(t,e),r=t,n=[{key:"send",value:(a=hn(sn().m(function e(t,r){var n;return sn().w(function(e){for(;;)if(0===e.n)return n=this.createEnvelope(t,r),this.sendStack.push({data:n,attempts:0,lastTimeoutId:null}),this.makeApiCall(this.sendStack.length-1),e.a(2,this.createPromiseFromCommandEnvelope(n))},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"destroy",value:function(){var e=this;this.sendStack.forEach(function(t){t.lastTimeoutId&&clearTimeout(t.lastTimeoutId),e.awaitingResponse.delete(t.data.ref)}),this.sendStack=[],this.emit(this.Event.destroy,!1)}},{key:"onMessage",value:(i=hn(sn().m(function e(t,r){var n;return sn().w(function(e){for(;;)switch(e.n){case 0:return this.sendStack.splice(t,1),e.n=1,r.json();case 1:n=e.v,this.handleIncomingEnvelope(n),this.emit(n.type,n.data),this.emit(this.Event.message,n);case 2:return e.a(2)}},e,this)})),function(e,t){return i.apply(this,arguments)})},{key:"onError",value:function(e,t){var r,n,o=this;if(this.sendStack[e].attempts>=(null!==(r=this.options.attemptsToSend)&&void 0!==r?r:10))return this.sendStack.splice(e,1),void this.handleEnvelopeSendError(this.sendStack[e].data,new Error("Cannot send ".concat(t,"; aborting after reaching the maximum connection errors")));this.sendStack[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;this.sendStack[e].attempts++;var n=JSON.stringify(this.sendStack[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:{}),a="".concat(this.options.url).concat(i?"?"+i:"");fetch(a,{headers:o,body:n,method:"POST"}).then(function(t){return r.onMessage(e,t)}).catch(function(){return r.onError(e,n)})}}],n&&pn(r.prototype,n),o&&pn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(y);function Sn(e){return Sn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Sn(e)}function On(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return jn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(jn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,jn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,jn(f,"constructor",s),jn(s,"constructor",u),u.displayName="GeneratorFunction",jn(s,o,"GeneratorFunction"),jn(f),jn(f,o,"Generator"),jn(f,n,function(){return this}),jn(f,"toString",function(){return"[object Generator]"}),(On=function(){return{w:i,m:h}})()}function jn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}jn=function(e,t,r,n){function i(t,r){jn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},jn(e,t,r,n)}function Tn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Pn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Tn(Object(r),!0).forEach(function(t){In(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Tn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function In(e,t,r){return(t=An(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function En(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Rn(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){En(i,n,o,a,c,"next",e)}function c(e){En(i,n,o,a,c,"throw",e)}a(void 0)})}}function _n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,An(n.key),n)}}function An(e){var t=function(e,t){if("object"!=Sn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Sn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Sn(t)?t:t+""}var Mn=function(){return e=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=t},t=[{key:"send",value:(o=Rn(On().m(function e(t,r){var n,o,i,a,c,u,s=arguments;return On().w(function(e){for(;;)switch(e.n){case 0:return n=s.length>2&&void 0!==s[2]?s[2]:void 0,o=s.length>3&&void 0!==s[3]?s[3]:{},i=this.getUrl(r),a=void 0,n&&(["GET","DELETE"].includes(t)?i+="?"+new URLSearchParams(n).toString():a=JSON.stringify(n)),c=Pn(Pn({"Content-Type":"application/json",Accept:"application/json"},o),this.getAuthHeaders()),e.n=1,fetch(i,{method:t,body:a,headers:c});case 1:return u=e.v,e.a(2,this.convertFetchResponse(u))}},e,this)})),function(e,t){return o.apply(this,arguments)})},{key:"getAuthHeaders",value:function(){var e={};return this.options.token&&(e.Authorization="Bearer ".concat(this.options.token)),e}},{key:"getUrl",value:function(e){var t;return this.removeEndingSlash(null!==(t=this.options.url)&&void 0!==t?t:this.defaultUrl)+"/"+this.removeStartingSlash(e)}},{key:"convertFetchResponse",value:(n=Rn(On().m(function e(t){var r,n,o,i,a;return On().w(function(e){for(;;)switch(e.n){case 0:if(n=t.ok,o=t.status,null===(r=t.headers.get("content-type"))||void 0===r||!r.includes("json")){e.n=2;break}return e.n=1,t.json();case 1:i=e.v,e.n=4;break;case 2:return e.n=3,t.text();case 3:i=e.v;case 4:return a=i,e.a(2,{ok:n,status:o,data:a})}},e)})),function(e){return n.apply(this,arguments)})},{key:"removeStartingSlash",value:function(e){return e.replace(/^\/+/,"")}},{key:"removeEndingSlash",value:function(e){return e.replace(/\/+$/,"")}}],t&&_n(e.prototype,t),r&&_n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,t,r,n,o}();function Fn(e){return Fn="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Fn(e)}function Ln(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var u=n&&n.prototype instanceof c?n:c,s=Object.create(u.prototype);return Cn(s,"_invoke",function(r,n,o){var i,c,u,s=0,l=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return i=t,c=0,u=e,h.n=r,a}};function p(r,n){for(c=r,u=n,t=0;!f&&s&&!o&&t<l.length;t++){var o,i=l[t],p=h.p,d=i[2];r>3?(o=d===n)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(c=0,h.v=n,h.n=i[1]):p<d&&(o=r<3||i[0]>n||n>d)&&(i[4]=r,i[5]=n,h.n=d,c=0))}if(o||r>1)return a;throw f=!0,n}return function(o,l,d){if(s>1)throw TypeError("Generator is already running");for(f&&1===l&&p(l,d),c=l,u=d;(t=c<2?e:u)||!f;){i||(c?c<3?(c>1&&(h.n=-1),p(c,u)):h.n=u:h.v=u);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(f=h.n<0)?u:r.call(n,h))!==a)break}catch(t){i=e,c=1,u=t}finally{s=1}}return{value:t,done:f}}}(r,o,i),!0),s}var a={};function c(){}function u(){}function s(){}t=Object.getPrototypeOf;var l=[][n]?t(t([][n]())):(Cn(t={},n,function(){return this}),t),f=s.prototype=c.prototype=Object.create(l);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,Cn(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return u.prototype=s,Cn(f,"constructor",s),Cn(s,"constructor",u),u.displayName="GeneratorFunction",Cn(s,o,"GeneratorFunction"),Cn(f),Cn(f,o,"Generator"),Cn(f,n,function(){return this}),Cn(f,"toString",function(){return"[object Generator]"}),(Ln=function(){return{w:i,m:h}})()}function Cn(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}Cn=function(e,t,r,n){function i(t,r){Cn(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},Cn(e,t,r,n)}function xn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Gn(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?xn(Object(r),!0).forEach(function(t){$n(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):xn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Dn(e,t,r,n,o,i,a){try{var c=e[i](a),u=c.value}catch(e){return void r(e)}c.done?t(u):Promise.resolve(u).then(n,o)}function Un(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){Dn(i,n,o,a,c,"next",e)}function c(e){Dn(i,n,o,a,c,"throw",e)}a(void 0)})}}function Nn(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,Qn(n.key),n)}}function Bn(e,t,r){return t=Jn(t),function(e,t){if(t&&("object"==Fn(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Wn()?Reflect.construct(t,r||[],Jn(e).constructor):t.apply(e,r))}function Wn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Wn=function(){return!!e})()}function Jn(e){return Jn=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Jn(e)}function Hn(e,t){return Hn=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Hn(e,t)}function $n(e,t,r){return(t=Qn(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Qn(e){var t=function(e,t){if("object"!=Fn(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=Fn(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==Fn(t)?t:t+""}var Vn=function(e){function t(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return $n(e=Bn(this,t,[].concat(n)),"defaultUrl","https://files.devana.pl"),e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Hn(e,t)}(t,e),r=t,n=[{key:"uploadFile",value:(c=Un(Ln().m(function e(t){var r,n,o,i;return Ln().w(function(e){for(;;)switch(e.n){case 0:return n=encodeURIComponent(null!==(r=t.name)&&void 0!==r?r:""),o=Gn(Gn({},this.getAuthHeaders()),{},{Accept:"application/json","Content-Disposition":'attachment; filename="'.concat(n,'"'),"Content-Length":t.size}),e.n=1,fetch(this.getUrl("files"),{method:"POST",body:t,headers:o});case 1:return i=e.v,e.a(2,this.convertFetchResponse(i))}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"getFileMeta",value:(a=Un(Ln().m(function e(t){return Ln().w(function(e){for(;;)if(0===e.n)return e.a(2,this.send("GET","files/"+t))},e,this)})),function(e){return a.apply(this,arguments)})},{key:"getFileMetaBulk",value:(i=Un(Ln().m(function e(t){var r;return Ln().w(function(e){for(;;)if(0===e.n)return r=new URLSearchParams,t.forEach(function(e){return r.append("id[]",e)}),e.a(2,this.send("GET","files?"+r))},e,this)})),function(e){return i.apply(this,arguments)})}],n&&Nn(r.prototype,n),o&&Nn(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a,c}(Mn);return t})());
2
2
  //# sourceMappingURL=index.umd.js.map