"use strict";(this.webpackChunktweb=this.webpackChunktweb||[]).push([[687],{9750:(e,t,s)=>{function i(e,t){const s=t.split(".");let i=e;return s.forEach((e=>{e&&(i=i[e])})),i}s.d(t,{Z:()=>i})},946:(e,t,s)=>{s.d(t,{Z:()=>a});var i=s(8479),n=s(5880);function a(e,t,s,o){for(const r in e)typeof t[r]!=typeof e[r]?(t[r]=(0,i.Z)(e[r]),s&&s(o||r)):(0,n.Z)(e[r])&&a(e[r],t[r],s,o||r)}},4687:(e,t,s)=>{s.r(t),s.d(t,{AppStateManager:()=>w,STATE_INIT:()=>Z,default:()=>k});var i=s(1507),n=s(3241),a=s(3512),o=s(7922),r=s(5003),h=s(4159),d=s(410),l=s(6947),g=s(4762),c=s(3127),u=s(7487),p=s(144);function f(e,t){e=e.split(" ",1)[0],t=t.split(" ",1)[0];const s=e.split("."),i=t.split(".");for(let e=0;en)return 1;if(t{this.requestPeerSingle(a.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())),i=y.map((e=>o.Z.get(e))).concat(u.Z.get("user_auth"),u.Z.get("state_id")).concat(o.Z.get("user_auth")).concat(s);Promise.all(i).then((s=>{return i=this,n=void 0,l=function*(){let i=this.state={};for(let e=0,t=y.length;eo.Z.get(e))));e.push("user_auth"),t.push("number"==typeof n||"string"==typeof n?{dcID:t[0]||h.Z.baseDcId,date:Date.now()/1e3|0,id:n.toPeerId(!1)}:n);let s={};e.forEach(((e,i)=>{s[e]=t[i]})),yield u.Z.set(s)}n&&(i.authState={_:"authStateSignedIn"},a.default.dispatchEvent("user_auth","number"==typeof n||"string"==typeof n?{dcID:0,date:Date.now()/1e3|0,id:n.toPeerId(!1)}:n));for(let e=0,i=t.length;e{e.set(s,(0,m.Z)(i[s]))})),i=this.state=(0,m.Z)(Z),e.forEach(((e,t)=>{i[t]=e}));for(const e in this.storagesResults)this.storagesResults[e].length=0;this.storage.set(i)}yield u.Z.set({state_id:i.stateId})}const g=Date.now();if(i.stateCreatedTime+864e5{e.forEach((e=>{this.pushToState(e,(0,m.Z)(Z[e]));const t=this.storagesResults[e];t&&t.length&&(t.length=0)}))})(_)),!i.settings.hasOwnProperty("theme")&&i.settings.hasOwnProperty("nightTheme")&&(i.settings.theme=i.settings.nightTheme?"night":"day",this.pushToState("settings",i.settings)),!i.settings.hasOwnProperty("themes")&&i.settings.background){i.settings.themes=(0,m.Z)(Z.settings.themes);const e=i.settings.themes.find((e=>e.name===i.settings.theme));e&&(e.background=i.settings.background,this.pushToState("settings",i.settings))}const c=i.settings.autoDownload;if(void 0!==(null==c?void 0:c.private)){const e=["contacts","private","groups","channels"];["photo","video","file"].forEach((t=>{const s=c[t]={};e.forEach((e=>{s[e]=c[e]}))})),e.forEach((e=>{delete c[e]})),this.pushToState("settings",i.settings)}if((0,v.Z)(Z,i,(e=>{this.pushToState(e,i[e])})),i.version!==P||i.build!==b){if(-1===f(i.version,"0.8.7")){this.state.allDialogsLoaded=(0,m.Z)(Z.allDialogsLoaded),this.state.filters=(0,m.Z)(Z.filters);const e=this.storagesResults.dialogs;(null==e?void 0:e.length)&&(e.length=0)}if(-1===f(i.version,"1.3.0")){let e=!1;i.settings.themes.forEach(((t,s,i)=>{if("day"===t.name&&"ByxGo2lrMFAIAAAAmkJxZabh8eM"===t.background.slug&&"image"===t.background.type||"night"===t.name&&"#0f0f0f"===t.background.color&&"color"===t.background.type){const n=Z.settings.themes.find((e=>e.name===t.name));n&&(i[s]=(0,m.Z)(n),e=!0)}})),e&&this.pushToState("settings",i.settings)}0!==f(i.version,P)&&(this.newVersion=P),this.pushToState("version",P),this.pushToState("build",b)}a.default.settings=i.settings,d.ZP&&this.log("state res",i,(0,m.Z)(i)),console.timeEnd("load state"),e(i)},new((r=void 0)||(r=Promise))((function(e,t){function s(e){try{o(l.next(e))}catch(e){t(e)}}function a(e){try{o(l.throw(e))}catch(e){t(e)}}function o(t){var i;t.done?e(t.value):(i=t.value,i instanceof r?i:new r((function(e){e(i)}))).then(s,a)}o((l=l.apply(i,n||[])).next())}));var i,n,r,l})).catch(e)}))),this.loaded}getState(){return void 0===this.state?this.loadSavedState():Promise.resolve(this.state)}setByKey(e,t){!function(e,t,s){const i=t.split(".");(0,S.Z)(e,i.slice(0,-1).join("."))[i.pop()]=s}(this.state,e,t),a.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 i=this.neededPeers.get(e);i&&i.has(t)||(i||(i=new Set,this.neededPeers.set(e,i)),i.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(i.NM,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)}}w.STATE_INIT=Z;const T=new w;d.GO.appStateManager=T;const k=T}}]); //# sourceMappingURL=687.e9f93733bf343790b37d.chunk.js.map