tweb/public/27.afe309283a478f17a54d.chunk.js
morethanwords 9f65dd79ec 1.0.0
2021-12-11 21:22:24 +04:00

2 lines
5.7 KiB
JavaScript

(this.webpackJsonp=this.webpackJsonp||[]).push([[27],{17:function(e,t,s){"use strict";s.r(t),s.d(t,"STATE_INIT",(function(){return P})),s.d(t,"AppStateManager",(function(){return w}));var a=s(45),i=s(54),n=s(15),o=s(80),r=s(43),h=s(32),d=s(8),l=s(29),g=s(99),c=s(0),u=s(120),p=s(67),f=s(65);var S=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{h(a.next(e))}catch(e){n(e)}}function r(e){try{h(a.throw(e))}catch(e){n(e)}}function h(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}h((a=a.apply(e,t||[])).next())}))};const m=d.a.versionFull,b=d.a.build,P={allDialogsLoaded:{},pinnedOrders:{},contactsList:[],updates:{},filters:{},maxSeenMsgId:0,stateCreatedTime:Date.now(),recentEmoji:[],topPeersCache:{},recentSearch:[],version:m,build:b,authState:{_:c.IS_MOBILE?"authStateSignIn":"authStateSignQr"},hiddenPinnedMessages:{},settings:{messagesTextSize:16,sendShortcut:"enter",animationsEnabled:!0,autoDownload:{contacts:!0,private:!0,groups:!0,channels:!0},autoPlay:{gifs:!0,videos:!0},stickers:{suggest:!0,loop:!0},emoji:{suggest:!0,big:!0},themes:[{name:"day",background:{type:"image",blur:!1,slug:"ByxGo2lrMFAIAAAAmkJxZabh8eM",highlightningColor:"hsla(85.5319, 36.9171%, 40.402%, 0.4)"}},{name:"night",background:{type:"color",blur:!1,color:"#0f0f0f",highlightningColor:"hsla(0, 0%, 3.82353%, 0.4)"}}],theme:"system",notifications:{sound:!1},timeFormat:(new Date).toLocaleString().match(/\s(AM|PM)/)?"h12":"h23"},keepSigned:!0,chatContextMenuHintWasShown:!1,stateId:Object(f.a)(32)},v=Object.keys(P),y=["contactsList","stateCreatedTime","maxSeenMsgId","filters","topPeers"];class w extends i.a{constructor(){super(),this.log=Object(r.b)("STATE"),this.neededPeers=new Map,this.singlePeerMap=new Map,this.storages={users:new g.a(u.a,"users"),chats:new g.a(u.a,"chats"),dialogs:new g.a(u.a,"dialogs")},this.storagesResults={},this.storage=o.a,this.loadSavedState()}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=v.map(e=>o.a.get(e)).concat(p.a.get("user_auth"),p.a.get("state_id")).concat(o.a.get("user_auth")).concat(s);Promise.all(a).then(s=>S(this,void 0,void 0,(function*(){let a=this.state={};for(let e=0,t=v.length;e<t;++e){const t=v[e],i=s[e];void 0!==i?a[t]=i:this.pushToState(t,Object(h.a)(P[t]))}s.splice(0,v.length);let i=s.shift();const r=s.shift(),g=s.shift();if(!i&&g){i=g;const e=["dc","server_time_offset","xt_instance"];for(let t=1;t<=5;++t)e.push(`dc${t}_server_salt`),e.push(`dc${t}_auth_key`);const t=yield Promise.all(e.map(e=>o.a.get(e)));e.push("user_auth"),t.push("number"==typeof i||"string"==typeof i?{dcID:t[0]||d.a.baseDcId,date:Date.now()/1e3|0,id:i.toPeerId(!1)}:i);let s={};e.forEach((e,a)=>{s[e]=t[a]}),yield p.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<a;++e)this.storagesResults[t[e]]=s[e];if(s.splice(0,t.length),a.stateId!==r){if(void 0!==r){const e=new Map([["authState",void 0],["stateId",void 0]]);e.forEach((t,s)=>{e.set(s,Object(h.a)(a[s]))}),a=this.state=Object(h.a)(P),e.forEach((e,t)=>{a[t]=e});for(const e in this.storagesResults)this.storagesResults[e].length=0;this.storage.set(a)}yield p.a.set({state_id:a.stateId})}const c=Date.now();if(a.stateCreatedTime+864e5<c){l.b&&this.log("will refresh state",a.stateCreatedTime,c);(e=>{e.forEach(e=>{this.pushToState(e,Object(h.a)(P[e]));const t=this.storagesResults[e];t&&t.length&&(t.length=0)})})(y)}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(h.a)(P.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))}if(Object(h.k)(P,a,e=>{this.pushToState(e,a[e])}),a.version!==m){if(-1===function(e,t){e=e.split(" ",1)[0],t=t.split(" ",1)[0];const s=e.split("."),a=t.split(".");for(let e=0;e<s.length;++e){const t=+s[e],i=+a[e];if(t>i)return 1;if(t<i)return-1}return 0}(a.version,"0.8.7")){this.state.allDialogsLoaded=Object(h.a)(P.allDialogsLoaded),this.state.filters=Object(h.a)(P.filters);const e=this.storagesResults.dialogs;(null==e?void 0:e.length)&&(e.length=0)}this.pushToState("version",this.newVersion=m),this.pushToState("build",b)}n.default.settings=a.settings,l.b&&this.log("state res",a,Object(h.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){Object(h.j)(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.b,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=P;const T=new w;l.a.appStateManager=T;t.default=T}}]);
//# sourceMappingURL=27.afe309283a478f17a54d.chunk.js.map