tweb/public/687.e9f93733bf343790b37d.ch...

2 lines
7.3 KiB
JavaScript

"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;e<s.length;++e){const t=+s[e],n=+i[e];if(t>n)return 1;if(t<n)return-1}return 0}var m=s(8479),S=s(9750),v=s(946);const P=h.Z.version,b=h.Z.build,Z={allDialogsLoaded:{},pinnedOrders:{},contactsList:[],updates:{},filters:{},maxSeenMsgId:0,stateCreatedTime:Date.now(),recentEmoji:[],topPeersCache:{},recentSearch:[],version:P,build:b,authState:{_:g.IS_MOBILE?"authStateSignIn":"authStateSignQr"},hiddenPinnedMessages:{},settings:{messagesTextSize:16,distanceUnit:"kilometers",sendShortcut:"enter",animationsEnabled:!0,autoDownload:{photo:{contacts:!0,private:!0,groups:!0,channels:!0},video:{contacts:!0,private:!0,groups:!0,channels:!0},file:{contacts:!0,private:!0,groups:!0,channels:!0}},autoDownloadNew:{_:"autoDownloadSettings",file_size_max:3145728,pFlags:{video_preload_large:!0,audio_preload_next:!0},photo_size_max:1048576,video_size_max:15728640,video_upload_maxbitrate:100},autoPlay:{gifs:!0,videos:!0},stickers:{suggest:!0,loop:!0},emoji:{suggest:!0,big:!0},themes:[{name:"day",background:{blur:!1,slug:"pattern",color:"#dbddbb,#6ba587,#d5d88d,#88b884",highlightningColor:"hsla(86.4, 43.846153%, 45.117647%, .4)",intensity:50,id:"1"}},{name:"night",background:{blur:!1,slug:"pattern",color:"#fec496,#dd6cb9,#962fbf,#4f5bd5",highlightningColor:"hsla(299.142857, 44.166666%, 37.470588%, .4)",intensity:-50,id:"-1"}}],theme:"system",notifications:{sound:!1},timeFormat:(new Date).toLocaleString().match(/\s(AM|PM)/)?"h12":"h23"},keepSigned:!0,chatContextMenuHintWasShown:!1,stateId:(0,p.d)(32),notifySettings:{}},y=Object.keys(Z),_=["contactsList","stateCreatedTime","maxSeenMsgId","filters","topPeers"];class w extends n.Z{constructor(){super(),this.log=(0,r.kg)("STATE"),this.neededPeers=new Map,this.singlePeerMap=new Map,this.storages={users:new l.Z(c.Z,"users"),chats:new l.Z(c.Z,"chats"),dialogs:new l.Z(c.Z,"dialogs")},this.storagesResults={},this.storage=o.Z,this.loadSavedState(),a.default.addEventListener("user_auth",(()=>{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;e<t;++e){const t=y[e],n=s[e];void 0!==n?i[t]=n:this.pushToState(t,(0,m.Z)(Z[t]))}s.splice(0,y.length);let n=s.shift();const r=s.shift(),l=s.shift();if(!n&&l){n=l;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.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<i;++e)this.storagesResults[t[e]]=s[e];if(s.splice(0,t.length),i.stateId!==r){if(void 0!==r){const e=new Map([["authState",void 0],["stateId",void 0]]);e.forEach(((t,s)=>{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<g&&(d.ZP&&this.log("will refresh state",i.stateCreatedTime,g),(e=>{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