(this.webpackJsonp=this.webpackJsonp||[]).push([[24],{113:function(e,t,s){"use strict";function a(e,t){const s=t.split(".");let a=e;return s.forEach(e=>{e&&(a=a[e])}),a}s.d(t,"a",(function(){return a}))},139:function(e,t,s){"use strict";s.d(t,"a",(function(){return n}));var a=s(53),i=s(84);function n(e,t,s,o){for(const r in e)typeof t[r]!=typeof e[r]?(t[r]=Object(a.a)(e[r]),s&&s(o||r)):Object(i.a)(e[r])&&n(e[r],t[r],s,o||r)}},17:function(e,t,s){"use strict";s.r(t),s.d(t,"STATE_INIT",(function(){return _})),s.d(t,"AppStateManager",(function(){return k}));var a=s(43),i=s(50),n=s(15),o=s(89),r=s(41),h=s(7),d=s(30),l=s(103),c=s(0),u=s(138),g=s(74),p=s(66);function f(e,t){e=e.split(" ",1)[0],t=t.split(" ",1)[0];const s=e.split("."),a=t.split(".");for(let e=0;ei)return 1;if(t{this.requestPeerSingle(n.default.myId,"self")})}loadSavedState(){return this.loaded||(console.time("load state"),this.loaded=new Promise(e=>{const t=Object.keys(this.storages),s=t.map(e=>this.storages[e].getAll()),a=w.map(e=>o.a.get(e)).concat(g.a.get("user_auth"),g.a.get("state_id")).concat(o.a.get("user_auth")).concat(s);Promise.all(a).then(s=>v(this,void 0,void 0,(function*(){let a=this.state={};for(let e=0,t=w.length;eo.a.get(e)));e.push("user_auth"),t.push("number"==typeof i||"string"==typeof i?{dcID:t[0]||h.a.baseDcId,date:Date.now()/1e3|0,id:i.toPeerId(!1)}:i);let s={};e.forEach((e,a)=>{s[e]=t[a]}),yield g.a.set(s)}i&&(a.authState={_:"authStateSignedIn"},n.default.dispatchEvent("user_auth","number"==typeof i||"string"==typeof i?{dcID:0,date:Date.now()/1e3|0,id:i.toPeerId(!1)}:i));for(let e=0,a=t.length;e{e.set(s,Object(m.a)(a[s]))}),a=this.state=Object(m.a)(_),e.forEach((e,t)=>{a[t]=e});for(const e in this.storagesResults)this.storagesResults[e].length=0;this.storage.set(a)}yield g.a.set({state_id:a.stateId})}const c=Date.now();if(a.stateCreatedTime+864e5{e.forEach(e=>{this.pushToState(e,Object(m.a)(_[e]));const t=this.storagesResults[e];t&&t.length&&(t.length=0)})})(T)}if(!a.settings.hasOwnProperty("theme")&&a.settings.hasOwnProperty("nightTheme")&&(a.settings.theme=a.settings.nightTheme?"night":"day",this.pushToState("settings",a.settings)),!a.settings.hasOwnProperty("themes")&&a.settings.background){a.settings.themes=Object(m.a)(_.settings.themes);const e=a.settings.themes.find(e=>e.name===a.settings.theme);e&&(e.background=a.settings.background,this.pushToState("settings",a.settings))}const u=a.settings.autoDownload;if(void 0!==(null==u?void 0:u.private)){const e=["contacts","private","groups","channels"];["photo","video","file"].forEach(t=>{const s=u[t]={};e.forEach(e=>{s[e]=u[e]})}),e.forEach(e=>{delete u[e]}),this.pushToState("settings",a.settings)}if(Object(S.a)(_,a,e=>{this.pushToState(e,a[e])}),a.version!==y||a.build!==P){if(-1===f(a.version,"0.8.7")){this.state.allDialogsLoaded=Object(m.a)(_.allDialogsLoaded),this.state.filters=Object(m.a)(_.filters);const e=this.storagesResults.dialogs;(null==e?void 0:e.length)&&(e.length=0)}if(-1===f(a.version,"1.3.0")){let e=!1;a.settings.themes.forEach((t,s,a)=>{if("day"===t.name&&"ByxGo2lrMFAIAAAAmkJxZabh8eM"===t.background.slug&&"image"===t.background.type||"night"===t.name&&"#0f0f0f"===t.background.color&&"color"===t.background.type){const i=_.settings.themes.find(e=>e.name===t.name);i&&(a[s]=Object(m.a)(i),e=!0)}}),e&&this.pushToState("settings",a.settings)}0!==f(a.version,y)&&(this.newVersion=y),this.pushToState("version",y),this.pushToState("build",P)}n.default.settings=a.settings,d.b&&this.log("state res",a,Object(m.a)(a)),console.timeEnd("load state"),e(a)}))).catch(e)})),this.loaded}getState(){return void 0===this.state?this.loadSavedState():Promise.resolve(this.state)}setByKey(e,t){!function(e,t,s){const a=t.split(".");Object(b.a)(e,a.slice(0,-1).join("."))[a.pop()]=s}(this.state,e,t),n.default.dispatchEvent("settings_updated",{key:e,value:t});const s=e.split(".")[0];this.pushToState(s,this.state[s])}pushToState(e,t,s=!0){s&&(this.state[e]=t),this.setKeyValueToStorage(e,t)}setKeyValueToStorage(e,t=this.state[e]){this.storage.set({[e]:t})}requestPeer(e,t,s){let a=this.neededPeers.get(e);a&&a.has(t)||(a||(a=new Set,this.neededPeers.set(e,a)),a.add(t),this.dispatchEvent("peerNeeded",e),void 0!==s&&this.keepPeerSingle(e,t))}requestPeerSingle(e,t,s=e){return this.requestPeer(e,t+"_"+s,1)}releaseSinglePeer(e,t){return this.keepPeerSingle(a.c,t+"_"+e)}isPeerNeeded(e){return this.neededPeers.has(e)}keepPeerSingle(e,t){const s=this.singlePeerMap.get(t);if(s&&s!==e&&this.neededPeers.has(s)){const e=this.neededPeers.get(s);e.delete(t),e.size||(this.neededPeers.delete(s),this.dispatchEvent("peerUnneeded",s))}e?this.singlePeerMap.set(t,e):this.singlePeerMap.delete(t)}}k.STATE_INIT=_;const O=new k;d.a.appStateManager=O;t.default=O}}]); //# sourceMappingURL=24.4b9f00474f1f2b0d38ce.chunk.js.map