tweb/public/1.43cdd2169cba82f053e3.chunk.js
2021-04-16 05:00:58 +04:00

1 line
11 KiB
JavaScript

(this.webpackJsonp=this.webpackJsonp||[]).push([[1],{14:function(e,t,r){"use strict";r.r(t),r.d(t,"STATE_INIT",(function(){return d})),r.d(t,"AppStateManager",(function(){return m}));var n=r(45),o=r(9),s=r(64),a=r(26),i=r(15),c=r(41),u=r(2),h=r(10);const l=u.a.version,d={dialogs:[],allDialogsLoaded:{},chats:{},users:{},messages:[],contactsList:[],updates:{},filters:{},maxSeenMsgId:0,stateCreatedTime:Date.now(),recentEmoji:[],topPeers:[],recentSearch:[],version:l,authState:{_:"authStateSignIn"},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},background:{type:"image",blur:!1,slug:"ByxGo2lrMFAIAAAAmkJxZabh8eM"},notifications:{sound:!1},nightTheme:!1},drafts:{}},f=Object.keys(d),g=["dialogs","allDialogsLoaded","messages","contactsList","stateCreatedTime","updates","maxSeenMsgId","filters","topPeers"];class m extends n.a{constructor(){super(),this.log=Object(a.b)("STATE"),this.tempId=0,this.loadSavedState()}loadSavedState(){return this.loaded?this.loaded:this.loaded=new Promise(e=>{Promise.all(f.concat("user_auth").map(e=>s.a.get(e))).then(t=>{var r;let n={};f.forEach((e,r)=>{const o=t[r];n[e]=void 0!==o?o:Object(i.a)(d[e])});const s=Date.now();if(n&&n.stateCreatedTime+864e5<s){h.b&&this.log("will refresh state",n.stateCreatedTime,s),g.forEach(e=>{n[e]=Object(i.a)(d[e])});const e={},t={};(null===(r=n.recentSearch)||void 0===r?void 0:r.length)&&n.recentSearch.forEach(r=>{r<0?t[r]=n.chats[r]:e[r]=n.users[r]}),n.users=e,n.chats=t}Object(i.k)(d,n),this.state=n,this.state.version=l,o.default.settings=this.state.settings,h.b&&this.log("state res",n,Object(i.a)(n));const a=t[t.length-1];a&&(this.state.authState={_:"authStateSignedIn"},o.default.broadcast("user_auth","number"!=typeof a?a.id:a)),e(this.state)}).catch(e).finally(()=>{setInterval(()=>{this.tempId++,this.saveState()},1e4)})})}getState(){return void 0===this.state?this.loadSavedState():Promise.resolve(this.state)}saveState(){if(void 0===this.state||this.savePromise)return;const e=this.tempId;this.savePromise=Object(c.c)().then(()=>Promise.all(this.dispatchEvent("save",this.state)).then(()=>Object(c.c)()).then(()=>s.a.set(this.state)).then(()=>{this.savePromise=null,this.tempId!==e&&this.saveState()}))}setByKey(e,t){Object(i.j)(this.state,e,t),o.default.broadcast("settings_updated",{key:e,value:t})}pushToState(e,t){this.state[e]=t}setPeer(e,t){const r=e>0?this.state.users:this.state.chats;r.hasOwnProperty(e)||(r[e]=t)}resetState(){for(let e in this.state)this.state[e]=!1;s.a.set(this.state).then(()=>{location.reload()})}}m.STATE_INIT=d;const v=new m;h.a.appStateManager=v,t.default=v},15:function(e,t,r){"use strict";function n(e){if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e)){return e.map(e=>n(e))}let t=new e.constructor;for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t}function o(e,t){const r=Object.keys,n=typeof e;return e&&t&&"object"===n&&n===typeof t?r(e).length===r(t).length&&r(e).every(r=>o(e[r],t[r])):e===t}function s(e,t){const r={writable:!0,configurable:!0},n={};t.forEach(t=>{void 0===e[t]&&(n[t]=r)}),Object.defineProperties(e,n)}function a(e,t="asc"){if(!e)return[];const r=Object.keys(e).map(e=>+e);return"asc"===t?r.sort((e,t)=>e-t):r.sort((e,t)=>t-e)}function i(e,t){if(!e)return t;for(var r in e)t.hasOwnProperty(r)||"$"===r.charAt(0)||delete e[r];for(var r in t)e[r]=t[r];return e}function c(e,t,r){"byteLength"in r[e]&&(r[e]=[...r[e]]),t&&t[e]!==r[e]&&(t[e].length=r[e].length,r[e].forEach((r,n)=>{t[e][n]=r}),r[e]=t[e])}function u(e){return"object"==typeof e&&null!==e}function h(e,t){const r=t.split(".");let n=e;return r.forEach(e=>{n=n[e]}),n}function l(e,t,r){const n=t.split(".");h(e,n.slice(0,-1).join("."))[n.pop()]=r}function d(e,t){for(const r in e)typeof t[r]!=typeof e[r]?t[r]=n(e[r]):u(e[r])&&d(e[r],t[r])}function f(e,t){if(t)for(let r in t)void 0!==t[r]&&(e[r]=t[r])}r.d(t,"a",(function(){return n})),r.d(t,"b",(function(){return o})),r.d(t,"c",(function(){return s})),r.d(t,"e",(function(){return a})),r.d(t,"i",(function(){return i})),r.d(t,"h",(function(){return c})),r.d(t,"f",(function(){return u})),r.d(t,"d",(function(){return h})),r.d(t,"j",(function(){return l})),r.d(t,"k",(function(){return d})),r.d(t,"g",(function(){return f}))},26:function(e,t,r){"use strict";r.d(t,"a",(function(){return n})),r.d(t,"b",(function(){return i}));var n,o=r(10);!function(e){e[e.log=1]="log",e[e.warn=2]="warn",e[e.error=4]="error",e[e.debug=8]="debug"}(n||(n={}));const s=Date.now();function a(){return"["+((Date.now()-s)/1e3).toFixed(3)+"]"}function i(e,t=n.log|n.warn|n.error){function r(...r){return t&n.log&&console.log(a(),e,...r)}return o.b||(t=n.error),r.warn=function(...r){return t&n.warn&&console.warn(a(),e,...r)},r.info=function(...r){return t&n.log&&console.info(a(),e,...r)},r.error=function(...r){return t&n.error&&console.error(a(),e,...r)},r.trace=function(...r){return t&n.log&&console.trace(a(),e,...r)},r.debug=function(...r){return t&n.debug&&console.debug(a(),e,...r)},r.setPrefix=function(t){e="["+t+"]:"},r.setPrefix(e),r}},41:function(e,t,r){"use strict";r.d(t,"b",(function(){return l})),r.d(t,"c",(function(){return d}));var n=r(30),o=r(19),s=r(9),a=r(10);let i=!1,c=Promise.resolve(),u=0;const h=console.log.bind(console.log,"[HEAVY-ANIMATION]:"),l=(e,t)=>{i||(c=Object(n.a)(),s.default.broadcast("event-heavy-animation-start"),i=!0,a.b&&h("start")),++u,a.b&&h("attach promise, length:",u,t);const r=[void 0!==t?Object(o.d)(t):void 0,e.finally(()=>{})].filter(Boolean),l=performance.now();return Promise.race(r).then(()=>{--u,a.b&&h("promise end, length:",u,performance.now()-l),u||(i=!1,u=0,s.default.broadcast("event-heavy-animation-end"),c.resolve(),a.b&&h("end"))}),c},d=()=>c;t.a=(e,t,r)=>{i&&e();const n=r?r.add.bind(r,s.default):s.default.addEventListener.bind(s.default),o=r?r.removeManual.bind(r,s.default):s.default.removeEventListener.bind(s.default);return n("event-heavy-animation-start",e),n("event-heavy-animation-end",t),()=>{o("event-heavy-animation-end",t),o("event-heavy-animation-start",e)}}},64:function(e,t,r){"use strict";var n=r(10);const o=new(r(97).a)({storeName:"session"});n.a.appStorage=o,t.a=o},68:function(e,t,r){"use strict";r.d(t,"b",(function(){return n})),r.d(t,"a",(function(){return o}));const n=e=>new Promise(t=>{const r=new FileReader;r.addEventListener("loadend",e=>{t(e.srcElement.result)}),r.readAsText(e)});function o(e,t=""){let r;const n=function(e){if(-1===["image/jpeg","image/png","image/gif","image/webp","image/bmp","video/mp4","video/webm","video/quicktime","audio/ogg","audio/mpeg","audio/mp4","application/json"].indexOf(e))return"application/octet-stream";return e}(t);try{r=new Blob(e,{type:n})}catch(t){let o=new BlobBuilder;e.forEach(e=>{o.append(e)}),r=o.getBlob(n)}return r}},97:function(e,t,r){"use strict";r.d(t,"a",(function(){return u}));var n={name:"tweb"+(r(48).a.test?"_test":""),version:5,stores:[{name:"session"},{name:"stickerSets"}]},o=r(68),s=r(15),a=r(26);class i{constructor(e){this.storageIsAvailable=!0,this.log=Object(a.b)("IDB"),this.name=n.name,this.version=n.version,this.stores=n.stores,Object(s.g)(this,e),this.openDatabase(!0)}isAvailable(){return this.storageIsAvailable}openDatabase(e=!1){if(this.openDbPromise&&!e)return this.openDbPromise;try{var t=indexedDB.open(this.name,this.version);if(!t)throw new Error}catch(e){return this.log.error("error opening db",e.message),this.storageIsAvailable=!1,Promise.reject(e)}let r=!1;return setTimeout(()=>{r||t.onerror({type:"IDB_CREATE_TIMEOUT"})},3e3),this.openDbPromise=new Promise((e,n)=>{t.onsuccess=o=>{r=!0;const s=t.result;let a=!1;this.log("Opened"),s.onerror=e=>{this.storageIsAvailable=!1,this.log.error("Error creating/accessing IndexedDB database",e),n(e)},s.onclose=e=>{this.log.error("closed:",e),!a&&this.openDatabase()},s.onabort=e=>{this.log.error("abort:",e);const t=e.target;this.openDatabase(a=!0),t.onerror&&t.onerror(e),s.close()},s.onversionchange=e=>{this.log.error("onversionchange, lol?")},e(s)},t.onerror=e=>{r=!0,this.storageIsAvailable=!1,this.log.error("Error creating/accessing IndexedDB database",e),n(e)},t.onupgradeneeded=e=>{r=!0,this.log.warn("performing idb upgrade from",e.oldVersion,"to",e.newVersion);var t=e.target.result;this.stores.forEach(e=>{t.objectStoreNames.contains(e.name)||((e,t)=>{var r;const n=e.createObjectStore(t.name);if(null===(r=t.indexes)||void 0===r?void 0:r.length)for(const e of t.indexes)n.createIndex(e.indexName,e.keyPath,e.objectParameters)})(t,e)})}})}delete(e){return this.openDatabase().then(t=>{try{var r=t.transaction([this.storeName],"readwrite").objectStore(this.storeName).delete(e)}catch(e){return Promise.reject(e)}return new Promise((t,n)=>{const o=setTimeout(()=>{this.log.error("delete: request not finished!",e,r),t()},3e3);r.onsuccess=e=>{t(),clearTimeout(o)},r.onerror=e=>{n(e),clearTimeout(o)}})})}deleteAll(){return this.openDatabase().then(e=>{try{const r=e.transaction([this.storeName],"readwrite");var t=r.objectStore(this.storeName).clear()}catch(e){return Promise.reject(e)}return new Promise((e,r)=>{const n=setTimeout(()=>{this.log.error("deleteAll: request not finished",t)},3e3);t.onsuccess=t=>{e(),clearTimeout(n)},t.onerror=e=>{r(e),clearTimeout(n)}})})}save(e,t){return this.openDatabase().then(r=>{const n=n=>{this.log.error("save: transaction error:",e,t,r,n,n&&n.name),n&&"InvalidStateError"!==n.name||setTimeout(()=>{this.save(e,t)},2e3)};try{const s=r.transaction([this.storeName],"readwrite");s.onerror=e=>{n(s.error)};var o=s.objectStore(this.storeName).put(t,e)}catch(e){return n(e),Promise.reject(e)}return new Promise((t,r)=>{const n=setTimeout(()=>{this.log.error("save: request not finished",e,o)},1e4);o.onsuccess=e=>{t(),clearTimeout(n)},o.onerror=e=>{r(e),clearTimeout(n)}})})}saveFile(e,t){return t instanceof Blob||(t=Object(o.a)([t])),this.save(e,t)}get(e){return this.openDatabase().then(t=>{try{const n=t.transaction([this.storeName],"readonly");var r=n.objectStore(this.storeName).get(e)}catch(t){this.log.error("get error:",t,e,r,r.error)}return new Promise((t,n)=>{const o=setTimeout(()=>{this.log.error("get request not finished!",e,r),n()},3e3);r.onsuccess=function(e){const s=r.result;void 0===s?n("NO_ENTRY_FOUND"):t(s),clearTimeout(o)},r.onerror=()=>{clearTimeout(o),n()}})})}}var c=function(e,t,r,n){return new(r||(r=Promise))((function(o,s){function a(e){try{c(n.next(e))}catch(e){s(e)}}function i(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,i)}c((n=n.apply(e,t||[])).next())}))};class u{constructor(e){this.cache={},this.useStorage=!0,this.storage=new i(e)}getCache(){return this.cache}getFromCache(e){return this.cache[e]}setToCache(e,t){return this.cache[e]=t}get(e){return c(this,void 0,void 0,(function*(){if(this.cache.hasOwnProperty(e))return this.getFromCache(e);if(this.useStorage){let t;try{t=yield this.storage.get(e)}catch(r){"NO_ENTRY_FOUND"!==r&&(this.useStorage=!1,console.error("[AS]: get error:",r,e,t))}return this.cache[e]=t}throw"something went wrong"}))}set(e,t=!1){return c(this,void 0,void 0,(function*(){for(const r in e)if(e.hasOwnProperty(r)){const n=e[r];if(this.setToCache(r,n),this.useStorage&&!t)try{yield this.storage.save(r,n)}catch(e){console.error("[AS]: set error:",e,r)}}}))}remove(e,t=!1){return c(this,void 0,void 0,(function*(){if(t||delete this.cache[e],this.useStorage)try{yield this.storage.delete(e)}catch(e){this.useStorage=!1,console.error("[AS]: remove error:",e)}}))}clear(){return this.storage.deleteAll()}}}}]);