tweb/public/2.1e035baa608111b048ce.chunk.js
Eduard Kuzmenko 60a603b5de Build
2021-04-26 18:34:31 +04:00

2 lines
227 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(this.webpackJsonp=this.webpackJsonp||[]).push([[2],[,,,,,,,,function(e,t,s){"use strict";s.r(t),s.d(t,"langPack",(function(){return c})),s.d(t,"I18n",(function(){return h})),s.d(t,"i18n",(function(){return u})),s.d(t,"i18n_",(function(){return g})),s.d(t,"_i18n",(function(){return p})),s.d(t,"join",(function(){return m}));var a=s(10),i=s(15),n=s(33),o=s(13),r=s(64),d=s(2),l=s(9);const c={messageActionChatCreate:"ActionCreateGroup",messageActionChatEditTitle:"ActionChangedTitle",messageActionChatEditPhoto:"ActionChangedPhoto",messageActionChatEditVideo:"ActionChangedVideo",messageActionChatDeletePhoto:"ActionRemovedPhoto",messageActionChatReturn:"ActionAddUserSelf",messageActionChatReturnYou:"ActionAddUserSelfYou",messageActionChatJoined:"ActionAddUserSelfMega",messageActionChatJoinedYou:"ChannelMegaJoined",messageActionChatAddUser:"ActionAddUser",messageActionChatAddUsers:"ActionAddUser",messageActionChatLeave:"ActionLeftUser",messageActionChatDeleteUser:"ActionKickUser",messageActionChatJoinedByLink:"ActionInviteUser",messageActionPinMessage:"ActionPinnedNoText",messageActionContactSignUp:"Chat.Service.PeerJoinedTelegram",messageActionChannelCreate:"ActionCreateChannel",messageActionChannelEditTitle:"Chat.Service.Channel.UpdatedTitle",messageActionChannelEditPhoto:"Chat.Service.Channel.UpdatedPhoto",messageActionChannelEditVideo:"Chat.Service.Channel.UpdatedVideo",messageActionChannelDeletePhoto:"Chat.Service.Channel.RemovedPhoto",messageActionHistoryClear:"HistoryCleared",messageActionChannelMigrateFrom:"ActionMigrateFromGroup","messageActionPhoneCall.in_ok":"ChatList.Service.Call.incoming","messageActionPhoneCall.out_ok":"ChatList.Service.Call.outgoing","messageActionPhoneCall.in_missed":"ChatList.Service.Call.Missed","messageActionPhoneCall.out_missed":"ChatList.Service.Call.Cancelled",messageActionBotAllowed:"Chat.Service.BotPermissionAllowed"};var h;!function(e){let t,c;function h(){const t=d.a.langPackCode;return e.lastRequestedLangCode=t,Promise.all([s.e(5).then(s.bind(null,96)),s.e(6).then(s.bind(null,97))]).then(([e,s])=>{const a=[];g(e.default,a),g(s.default,a);return m({_:"langPackDifference",from_version:0,lang_code:t,strings:a,version:0,local:!0})})}function u(t){return e.requestedServerLanguage=!0,Promise.all([o.a.invokeApiCacheable("langpack.getLangPack",{lang_code:t,lang_pack:d.a.langPack}),o.a.invokeApiCacheable("langpack.getLangPack",{lang_code:t,lang_pack:"android"}),s.e(5).then(s.bind(null,96)),s.e(6).then(s.bind(null,97)),e.polyfillPromise])}function g(e,t=[]){for(const s in e){const a=e[s];"string"==typeof a?t.push({_:"langPackString",key:s,value:a}):t.push(Object.assign({_:"langPackStringPluralized",key:s},a))}return t}function p(t){return e.lastRequestedLangCode=t,u(t).then(([e,t,s,a,i])=>{let n=[];[s,a].forEach(e=>{g(e.default,n)}),n=n.concat(e.strings);for(const e of t.strings)n.push(e);return e.strings=n,m(e)})}function m(e){return e.appVersion=d.a.langPackVersion,r.a.set({langPack:e}).then(()=>(f(e),e))}function f(s){if(s.lang_code!==e.lastRequestedLangCode)return;t=new Intl.PluralRules(s.lang_code),e.strings.clear();for(const t of s.strings)e.strings.set(t.key,t);l.default.broadcast("language_change");Array.from(document.querySelectorAll(".i18n")).forEach(t=>{const s=e.weakMap.get(t);s&&s.update()})}function _(e,t,s={i:0}){let a=[];let i=0;return e.replace(/(\*\*)(.+?)\1|(\n)|un\d|%\d\$.|%./g,(e,n,o,r,d,l)=>{if(a.push(l.slice(i,d)),n)switch(n){case"**":{const e=document.createElement("b");e.append(..._(o,t,s)),a.push(e);break}}else r?a.push(document.createElement("br")):t&&a.push(t[s.i++]);return i=d+e.length,""}),i!==e.length&&a.push(e.slice(i)),a}function v(s,a=!1,i){const n=e.strings.get(s);let o;if(n)if("langPackStringPluralized"===n._&&(null==i?void 0:i.length)){let e=i[0];"string"==typeof e&&(e=+e.replace(/\D/g,""));o=n[t.select(e)+"_value"]||n.other_value}else o="langPackString"===n._?n.value:s;else o=s;if(a){if(null==i?void 0:i.length){const e=/un\d|%\d\$.|%./g;let t=0;o=o.replace(e,(e,s,a)=>""+i[t++])}return o}return _(o,i)}e.strings=new Map,e.requestedServerLanguage=!1,e.getCacheLangPack=function(){return c||(c=Promise.all([r.a.get("langPack"),e.polyfillPromise]).then(([t])=>t?(a.b,e.lastRequestedLangCode||(e.lastRequestedLangCode=t.lang_code),f(t),t):h()).finally(()=>{c=void 0}))},e.loadLocalLangPack=h,e.loadLangPack=u,e.getStrings=function(e,t){return o.a.invokeApi("langpack.getStrings",{lang_pack:d.a.langPack,lang_code:e,keys:t})},e.formatLocalStrings=g,e.getLangPack=p,e.saveLangPack=m,e.polyfillPromise="undefined"!=typeof Intl&&void 0!==Intl.PluralRules?Promise.resolve():s.e(21).then(s.bind(null,102)).then(e=>{window.Intl=Object.assign("undefined"!=typeof Intl?Intl:{},e.default)}),e.applyLangPack=f,e.superFormatter=_,e.format=v,e.weakMap=new WeakMap;class X{constructor(t){this.property="innerHTML",this.element=t.element||document.createElement("span"),this.element.classList.add("i18n"),this.update(t),e.weakMap.set(this.element,this)}}class b extends X{update(e){if(Object(i.g)(this,e),"innerHTML"===this.property)this.element.textContent="",this.element.append(...v(this.key,!1,this.args));else{const e=this.element[this.property],t=v(this.key,!0,this.args);void 0===e?this.element.dataset[this.property]=t:this.element[this.property]=t}}}e.IntlElement=b;e.IntlDateElement=class extends X{update(t){Object(i.g)(this,t);const s=new Intl.DateTimeFormat(e.lastRequestedLangCode+"-u-hc-h23",this.options);this.element[this.property]=Object(n.a)(s.format(this.date))}},e.i18n=function(e,t){return new b({key:e,args:t}).element},e.i18n_=function(e){return new b(e).element},e._i18n=function(e,t,s,a){return new b({element:e,key:t,args:s,property:a}).element}}(h||(h={})),t.default=h;const u=h.i18n,g=h.i18n_,p=h._i18n;function m(e,t=!0){const s=e.slice(0,1);for(let a=1;a<e.length;++a){const i=e.length-1===a&&t?"WordDelimiterLast":"WordDelimiter";s.push(u(i)),s.push(e[a])}return s}a.a.I18n=h},,,,,function(e,t,s){"use strict";var a=s(99),i=s.n(a),n=s(15),o=s(60);var r=s(26),d=s(9),l=s(81),c=s(70),h=s(38),u=s(10),g=s(50),p=s(46);class m extends p.a{constructor(e,t,s){super(),this.dcId=e,this.url=t,this.debug=g.a.debug&&!1,this.handleOpen=()=>{this.log("opened"),this.debug&&this.log.debug("sending init packet"),this.dispatchEvent("open")},this.handleError=e=>{this.log.error("handleError",e),this.close()},this.handleClose=()=>{this.log("closed"),this.removeListeners(),this.dispatchEvent("close")},this.handleMessage=e=>{this.debug&&this.log.debug("<-","handleMessage",e.data.byteLength),this.dispatchEvent("message",e.data)},this.send=e=>{this.debug&&this.log.debug("-> body length to send:",e.length),this.ws.send(e)};let a=r.a.error|r.a.log;return this.debug&&(a|=r.a.debug),this.log=Object(r.b)("WS-"+e+s,a),this.log("constructor"),this.connect(),this}removeListeners(){this.ws&&(this.ws.removeEventListener("open",this.handleOpen),this.ws.removeEventListener("close",this.handleClose),this.ws.removeEventListener("error",this.handleError),this.ws.removeEventListener("message",this.handleMessage),this.ws=void 0)}connect(){this.ws=new WebSocket(this.url,"binary"),this.ws.binaryType="arraybuffer",this.ws.addEventListener("open",this.handleOpen),this.ws.addEventListener("close",this.handleClose),this.ws.addEventListener("error",this.handleError),this.ws.addEventListener("message",this.handleMessage)}close(){if(this.ws){this.log.error("close execution");try{this.ws.close()}catch(e){}this.handleClose()}}}const f=new class extends class{sha1Hash(e){return this.performTaskWorker("sha1-hash",e)}sha256Hash(e){return this.performTaskWorker("sha256-hash",e)}pbkdf2(e,t,s){return this.performTaskWorker("pbkdf2",e,t,s)}aesEncrypt(e,t,s){return this.performTaskWorker("aes-encrypt",Object(o.f)(e),Object(o.f)(t),Object(o.f)(s))}aesDecrypt(e,t,s){return this.performTaskWorker("aes-decrypt",e,t,s).then(e=>Object(o.f)(e))}rsaEncrypt(e,t){return this.performTaskWorker("rsa-encrypt",e,t)}factorize(e){return this.performTaskWorker("factorize",[...e])}modPow(e,t,s){return this.performTaskWorker("mod-pow",e,t,s)}gzipUncompress(e,t){return this.performTaskWorker("gzipUncompress",e,t)}computeSRP(e,t,s=!1){return this.performTaskWorker("computeSRP",e,t,s)}}{constructor(){super(),this.afterMessageIdTemp=0,this.taskId=0,this.awaiting={},this.pending=[],this.updatesProcessor=null,this.log=Object(r.b)("API-PROXY"),this.hashes={},this.apiPromisesSingle={},this.apiPromisesCacheable={},this.isSWRegistered=!0,this.debug=u.b,this.sockets=new Map,this.onWorkerMessage=e=>{const t=e.data;if(Object(n.f)(t))if(t.update)this.updatesProcessor&&this.updatesProcessor(t.update);else if(t.progress)d.default.broadcast("download_progress",t.progress);else if("reload"===t.type)location.reload();else if("connectionStatusChange"===t.type)d.default.broadcast("connection_status_change",t.payload);else if("convertWebp"===t.type)l.a.postMessage(t);else if("requestFilePart"===t.type){const e=t;if(e.error){const s=a=>{if("FILE_REFERENCE_EXPIRED"===(null==a?void 0:a.type)){const t=e.originalPayload[1].file_reference;c.a.refreshReference(t).then(()=>{e.originalPayload[1].file_reference=c.a.getReferenceByLink(t);const s={type:e.type,id:e.id,payload:e.originalPayload};this.postMessage(s)}).catch(s)}else navigator.serviceWorker.controller.postMessage(t)};s(e.error)}else navigator.serviceWorker.controller.postMessage(t)}else if("socketProxy"===t.type){const e=t.payload,s=e.id;if("send"===e.type){this.sockets.get(s).send(e.payload)}else if("close"===e.type){this.sockets.get(s).close()}else if("setup"===e.type){const t=new m(e.payload.dcId,e.payload.url,e.payload.logSuffix),a=()=>{this.postMessage({type:"socketProxy",payload:{type:"open",id:s}})},i=()=>{this.postMessage({type:"socketProxy",payload:{type:"close",id:s}}),t.removeEventListener("open",a),t.removeEventListener("close",i),t.removeEventListener("message",n),this.sockets.delete(s)},n=e=>{this.postMessage({type:"socketProxy",payload:{type:"message",id:s,payload:e}})};t.addEventListener("open",a),t.addEventListener("close",i),t.addEventListener("message",n),this.sockets.set(s,t)}}else(t.hasOwnProperty("result")||t.hasOwnProperty("error"))&&this.finalizeTask(t.taskId,t.result,t.error)},this.log("constructor"),this.registerServiceWorker(),this.registerWorker()}isServiceWorkerOnline(){return this.isSWRegistered}registerServiceWorker(){if(!("serviceWorker"in navigator))return;const e=navigator.serviceWorker;e.register("./sw.js",{scope:"./"}).then(e=>{this.log("SW registered",e),this.isSWRegistered=!0;(e.installing||e.waiting||e.active).addEventListener("statechange",e=>{this.log("SW statechange",e)})},e=>{this.isSWRegistered=!1,this.log.error("SW registration failed!",e),h.a.onServiceWorkerFail()}),e.addEventListener("controllerchange",()=>{this.log.warn("controllerchange"),this.releasePending(),e.controller.addEventListener("error",e=>{this.log.error("controller error:",e)})}),e.addEventListener("message",e=>{const t=e.data;Object(n.f)(t)&&this.postMessage(t)}),e.addEventListener("messageerror",e=>{this.log.error("SW messageerror:",e)})}onWorkerFirstMessage(e){if(!this.worker){this.worker=e,this.log("set webWorker"),this.postMessage=this.worker.postMessage.bind(this.worker);const t=l.a.isWebpSupported();this.log("WebP supported:",t),this.postMessage({type:"webpSupport",payload:t}),this.releasePending()}}registerWorker(){const e=new i.a;e.addEventListener("message",this.onWorkerFirstMessage.bind(this,e),{once:!0}),e.addEventListener("message",this.onWorkerMessage),e.addEventListener("error",e=>{this.log.error("WORKER ERROR",e)})}finalizeTask(e,t,s){const a=this.awaiting[e];void 0!==a&&(this.debug&&this.log.debug("done",a.taskName,t,s),s?a.reject(s):a.resolve(t),delete this.awaiting[e])}performTaskWorker(e,...t){return this.debug&&this.log.debug("start",e,t),new Promise((s,a)=>{this.awaiting[this.taskId]={resolve:s,reject:a,taskName:e};const i={task:e,taskId:this.taskId,args:t};this.pending.push(i),this.releasePending(),this.taskId++})}releasePending(){this.postMessage&&(this.debug&&this.log.debug("releasing tasks, length:",this.pending.length),this.pending.forEach(e=>{this.postMessage(e)}),this.debug&&this.log.debug("released tasks"),this.pending.length=0)}setUpdatesProcessor(e){this.updatesProcessor=e}invokeApi(e,t={},s={}){return this.performTaskWorker("invokeApi",e,t,s)}invokeApiAfter(e,t={},s={}){let a=s;return a.prepareTempMessageId=""+ ++this.afterMessageIdTemp,a=Object.assign({},s),s.messageId=a.prepareTempMessageId,this.invokeApi(e,t,a)}invokeApiHashable(e,t={},s={}){const a=JSON.stringify(t);let i;return this.hashes[e]&&(i=this.hashes[e][a],i&&(t.hash=i.hash)),this.invokeApi(e,t,s).then(t=>{if(t._.includes("NotModified"))return this.debug&&this.log.warn("NotModified saved!",e,a),i.result;if(t.hash){const s=t.hash;this.hashes[e]||(this.hashes[e]={}),this.hashes[e][a]={hash:s,result:t}}return t})}invokeApiSingle(e,t={},s={}){const a=e+"-"+JSON.stringify(t);return this.apiPromisesSingle[a]?this.apiPromisesSingle[a]:this.apiPromisesSingle[a]=this.invokeApi(e,t,s).finally(()=>{delete this.apiPromisesSingle[a]})}invokeApiCacheable(e,t={},s={}){var a;const i=null!==(a=this.apiPromisesCacheable[e])&&void 0!==a?a:this.apiPromisesCacheable[e]={},n=JSON.stringify(t),o=i[n];if(o&&(!s.override||!o.fulfilled))return o.promise;let r;s.override&&(o&&o.timeout&&(clearTimeout(o.timeout),delete o.timeout),delete s.override),s.cacheSeconds&&(r=window.setTimeout(()=>{delete i[n]},1e3*s.cacheSeconds),delete s.cacheSeconds);const d=this.invokeApi(e,t,s);return i[n]={timestamp:Date.now(),fulfilled:!1,timeout:r,promise:d,params:t},d}clearCache(e,t){const s=this.apiPromisesCacheable[e];if(s)for(const e in s){const a=s[e];t(a.params)&&(a.timeout&&clearTimeout(a.timeout),delete s[e])}}setBaseDcId(e){return this.performTaskWorker("setBaseDcId",e)}setQueueId(e){return this.performTaskWorker("setQueueId",e)}setUserAuth(e){return d.default.broadcast("user_auth",e),this.performTaskWorker("setUserAuth",e)}getNetworker(e,t){return this.performTaskWorker("getNetworker",e,t)}logOut(){return this.performTaskWorker("logOut")}cancelDownload(e){return this.performTaskWorker("cancelDownload",e)}downloadFile(e){return this.performTaskWorker("downloadFile",e)}uploadFile(e){return this.performTaskWorker("uploadFile",e)}toggleStorage(e){return this.performTaskWorker("toggleStorage",e)}};u.a.apiManagerProxy=f;t.a=f},,,,,function(e,t,s){"use strict";var a=s(20),i=s(10),n=s(31),o=s(15),r=s(8),d=s(13),l=s(84),c=s(63),h=s(11),u=s(9),g=s(71),p=s(51),m=s(25),f=s(24),_=s(14),v=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};const X=new class{constructor(){this.users={},this.usernames={},this.contactsIndex=g.a.createIndex(),this.contactsList=new Set,this.updatedContactsList=!1,this.updateUsersStatuses=()=>{const e=Object(n.g)(!0);for(const t in this.users){const s=this.users[t];s.status&&"userStatusOnline"===s.status._&&s.status.expires<e&&(s.status={_:"userStatusOffline",was_online:s.status.expires},u.default.broadcast("user_update",s.id))}},setInterval(this.updateUsersStatuses,6e4),u.default.on("state_synchronized",this.updateUsersStatuses),u.default.addMultipleEventsListeners({updateUserStatus:e=>{const t=e.user_id,s=this.users[t];s&&(s.status=e.status,s.status&&("expires"in s.status&&(s.status.expires-=c.a.serverTimeOffset),"was_online"in s.status&&(s.status.was_online-=c.a.serverTimeOffset)),u.default.broadcast("user_update",t))},updateUserPhoto:e=>{const t=e.user_id,s=this.users[t];s?(this.forceUserOnline(t),"userProfilePhotoEmpty"===e.photo._?delete s.photo:s.photo=Object(o.i)(s.photo,e.photo),u.default.broadcast("user_update",t),u.default.broadcast("avatar_update",t)):console.warn("No user by id:",t)},updateUserName:e=>{const t=e.user_id,s=this.users[t];s&&(this.forceUserOnline(t),this.saveApiUser(Object.assign({},s,{first_name:e.first_name,last_name:e.last_name,username:e.username}),!0))}}),u.default.on("language_change",e=>{const t=this.getSelf().id;g.a.indexObject(t,this.getUserSearchText(t),this.contactsIndex)}),_.default.getState().then(e=>{this.users=e.users;const t=e.contactsList;t&&Array.isArray(t)&&(t.forEach(e=>{this.pushContact(e)}),this.contactsList.size&&(this.contactsFillPromise=Promise.resolve(this.contactsList))),_.default.addEventListener("save",()=>v(this,void 0,void 0,(function*(){const e=[...this.contactsList];for(const t of e)_.default.setPeer(t,this.getUser(t));_.default.pushToState("contactsList",e)})))})}fillContacts(){if(this.contactsFillPromise&&this.updatedContactsList)return this.contactsFillPromise;this.updatedContactsList=!0;const e=d.a.invokeApi("contacts.getContacts").then(t=>("contacts.contacts"===t._&&(this.saveApiUsers(t.users),t.contacts.forEach(e=>{this.pushContact(e.user_id)})),this.contactsFillPromise=e,this.contactsList));return this.contactsFillPromise||(this.contactsFillPromise=e)}resolveUsername(e){return"@"===e[0]&&(e=e.slice(1)),e=e.toLowerCase(),this.usernames[e]?Promise.resolve(this.users[this.usernames[e]]):d.a.invokeApi("contacts.resolveUsername",{username:e}).then(e=>(this.saveApiUsers(e.users),m.a.saveApiChats(e.chats),f.a.getPeer(f.a.getPeerId(e.peer))))}pushContact(e){this.contactsList.add(e),g.a.indexObject(e,this.getUserSearchText(e),this.contactsIndex)}getUserSearchText(e){const t=this.users[e];if(!t)return"";return[t.first_name,t.last_name,t.phone,t.username,t.pFlags.self?r.default.format("SavedMessages",!0):"",t.pFlags.self?"Saved Messages":""].filter(Boolean).join(" ")}getContacts(e,t=!1){return this.fillContacts().then(s=>{let a=[...s];if(e){const t=g.a.search(e,this.contactsIndex);a=[...a].filter(e=>!!t[e])}return a.sort((e,t)=>{const s=(this.users[e]||{}).sortName||"",a=(this.users[t]||{}).sortName||"";return s.localeCompare(a)}),t&&this.testSelfSearch(e)&&(a.findAndSplice(e=>e===u.default.myId),a.unshift(u.default.myId)),a})}toggleBlock(e,t){return d.a.invokeApi(t?"contacts.block":"contacts.unblock",{id:f.a.getInputPeerById(e)}).then(s=>(s&&p.a.processUpdateMessage({_:"updateShort",update:{_:"updatePeerBlocked",peer_id:f.a.getOutputPeer(e),blocked:t}}),s))}testSelfSearch(e){const t=this.getSelf(),s=g.a.createIndex();return g.a.indexObject(t.id,this.getUserSearchText(t.id),s),!!g.a.search(e,s)[t.id]}saveApiUsers(e){e.forEach(e=>this.saveApiUser(e))}saveApiUser(e,t){if("userEmpty"===e._)return;const s=e.id,a=this.users[s];if(a&&!t)return;if(void 0===e.pFlags&&(e.pFlags={}),e.pFlags.min&&void 0!==a)return;const i=e.first_name+" "+(e.last_name||"");if(e.username){const t=g.a.cleanUsername(e.username);this.usernames[t]=s}e.sortName=e.pFlags.deleted?"":g.a.cleanSearchText(i,!1),e.initials=h.a.getAbbreviation(i),e.status&&(e.status.expires&&(e.status.expires-=c.a.serverTimeOffset),e.status.was_online&&(e.status.was_online-=c.a.serverTimeOffset));let n=!1;void 0===a?this.users[s]=e:(e.first_name===a.first_name&&e.last_name===a.last_name&&e.username===a.username||(n=!0),Object(o.i)(a,e),u.default.broadcast("user_update",s)),n&&u.default.broadcast("peer_title_edit",e.id)}formatUserPhone(e){return"+"+Object(a.c)(e).formatted}getUserStatusForSort(e){if("number"==typeof e&&(e=this.getUser(e).status),e){const t="userStatusOnline"===e._?e.expires:"userStatusOffline"===e._?e.was_online:0;if(t)return t;switch(e._){case"userStatusRecently":return 3;case"userStatusLastWeek":return 2;case"userStatusLastMonth":return 1}}return 0}getUser(e){return Object(o.f)(e)?e:this.users[e]||{id:e,pFlags:{deleted:!0},access_hash:""}}getSelf(){return this.getUser(u.default.myId)}getUserStatusString(e){var t;let s,a;switch(e){case l.a:s="Peer.RepliesNotifications";break;case 777e3:s="Peer.ServiceNotifications";break;default:{if(this.isBot(e)){s="Presence.bot";break}const i=this.getUser(e);if(!i){s="";break}if(i.pFlags.support){s="Presence.Support";break}switch(null===(t=i.status)||void 0===t?void 0:t._){case"userStatusRecently":s="Peer.Status.recently";break;case"userStatusLastWeek":s="Peer.Status.lastWeek";break;case"userStatusLastMonth":s="Peer.Status.lastMonth";break;case"userStatusOffline":{const e=i.status.was_online,t=Date.now()/1e3;if(t-e<60)s="Peer.Status.justNow";else if(t-e<3600){s="Peer.Status.minAgo";a=[(t-e)/60|0]}else if(t-e<86400){s="LastSeen.HoursAgo";a=[(t-e)/3600|0]}else{s="Peer.Status.LastSeenAt";const t=new Date(1e3*e);a=[("0"+t.getDate()).slice(-2)+"."+("0"+(t.getMonth()+1)).slice(-2),("0"+t.getHours()).slice(-2)+":"+("0"+t.getMinutes()).slice(-2)]}break}case"userStatusOnline":s="Peer.Status.online";break;default:s="Peer.Status.longTimeAgo"}break}}return Object(r.i18n)(s,a)}isBot(e){return this.users[e]&&this.users[e].pFlags.bot}isContact(e){return this.contactsList.has(e)}isRegularUser(e){const t=this.users[e];return t&&!this.isBot(e)&&!t.pFlags.deleted&&!t.pFlags.support}isNonContactUser(e){return this.isRegularUser(e)&&!this.isContact(e)&&e!==u.default.myId}hasUser(e,t){var s=this.users[e];return Object(o.f)(s)&&(t||!s.pFlags.min)}canSendToUser(e){const t=this.getUser(e);return!t.pFlags.deleted&&"replies"!==t.username}getUserPhoto(e){const t=this.getUser(e);return t&&t.photo||{_:"userProfilePhotoEmpty"}}getUserString(e){const t=this.getUser(e);return"u"+e+(t.access_hash?"_"+t.access_hash:"")}getUserInput(e){const t=this.getUser(e);return t.pFlags&&t.pFlags.self?{_:"inputUserSelf"}:{_:"inputUser",user_id:e,access_hash:t.access_hash}}forceUserOnline(e,t){if(this.isBot(e))return;const s=Object(n.g)(!0);if(t){if(s-t>=60)return}else if(p.a.updatesState.syncLoading)return;const a=this.getUser(e);a&&a.status&&"userStatusOnline"!==a.status._&&"userStatusEmpty"!==a.status._&&!a.pFlags.support&&!a.pFlags.deleted&&(a.status={_:"userStatusOnline",expires:s+60},u.default.broadcast("user_update",e))}getTopPeers(){return this.getTopPeersPromise?this.getTopPeersPromise:this.getTopPeersPromise=_.default.getState().then(e=>{var t;return(null===(t=null==e?void 0:e.topPeers)||void 0===t?void 0:t.length)?e.topPeers:d.a.invokeApi("contacts.getTopPeers",{correspondents:!0,offset:0,limit:15,hash:0}).then(e=>{let t=[];return"contacts.topPeers"===e._&&(this.saveApiUsers(e.users),m.a.saveApiChats(e.chats),e.categories.length&&(t=e.categories[0].peers.map(e=>{const t=f.a.getPeerId(e.peer);return _.default.setPeer(t,this.getUser(t)),t}))),_.default.pushToState("topPeers",t),t})})}getBlocked(e=0,t=0){return d.a.invokeApi("contacts.getBlocked",{offset:e,limit:t}).then(e=>{this.saveApiUsers(e.users),m.a.saveApiChats(e.chats);return{count:"contacts.blocked"===e._?e.users.length+e.chats.length:e.count,peerIds:e.users.map(e=>e.id).concat(e.chats.map(e=>-e.id))}})}searchContacts(e,t=20){return d.a.invokeApi("contacts.search",{q:e,limit:t}).then(e=>{this.saveApiUsers(e.users),m.a.saveApiChats(e.chats);return{my_results:[...new Set(e.my_results.map(e=>f.a.getPeerId(e)))],results:e.results.map(e=>f.a.getPeerId(e))}})}onContactUpdated(e,t){t!==this.isContact(e)&&(t?(this.contactsList.add(e),g.a.indexObject(e,this.getUserSearchText(e),this.contactsIndex)):this.contactsList.delete(e),u.default.broadcast("contacts_update",e))}updateUsername(e){return d.a.invokeApi("account.updateUsername",{username:e}).then(e=>{this.saveApiUser(e)})}setUserStatus(e,t){if(this.isBot(e))return;const s=this.users[e];if(s){const a=t?{_:"userStatusOffline",was_online:Object(n.g)(!0)}:{_:"userStatusOnline",expires:Object(n.g)(!0)+500};s.status=a,u.default.broadcast("user_update",e)}}addContact(e,t,s,a,i){return d.a.invokeApi("contacts.addContact",{id:this.getUserInput(e),first_name:t,last_name:s,phone:a,add_phone_privacy_exception:i}).then(t=>{p.a.processUpdateMessage(t),this.onContactUpdated(e,!0)})}deleteContacts(e){return d.a.invokeApi("contacts.deleteContacts",{id:e.map(e=>this.getUserInput(e))}).then(t=>{p.a.processUpdateMessage(t),e.forEach(e=>{this.onContactUpdated(e,!1)})})}};i.a.appUsersManager=X,t.a=X},,function(e,t,s){"use strict";s.d(t,"f",(function(){return c})),s.d(t,"g",(function(){return h})),s.d(t,"c",(function(){return g})),s.d(t,"b",(function(){return f})),s.d(t,"d",(function(){return b})),s.d(t,"e",(function(){return y})),s.d(t,"a",(function(){return C}));var a=s(10),i=s(83),n=s(7),o=s(23),r=s(22),d=s(1),l=s(44);function c(e,t=!1){const s='\n <svg xmlns="http://www.w3.org/2000/svg" class="preloader-circular" viewBox="25 25 50 50">\n <circle class="preloader-path" cx="50" cy="50" r="20" fill="none" stroke-miterlimit="10"/>\n </svg>';if(t){const t=document.createElement("div");return t.classList.add("preloader"),t.innerHTML=s,e&&e.appendChild(t),t}return e.insertAdjacentHTML("beforeend",s),e.lastElementChild}function h(e,t="check"){return e.classList.remove("tgico-"+t),e.disabled=!0,c(e),()=>{e.innerHTML="",e.classList.add("tgico-"+t),e.removeAttribute("disabled")}}let u;function g(e){let t=(e=e.replace(/\D/g,"")).slice(0,6);u||(u=i.b.slice().sort((e,t)=>t.phoneCode.length-e.phoneCode.length));let s=u.find(e=>e.phoneCode.split(" and ").find(e=>0===t.indexOf(e.replace(/\D/g,""))));return s?(s=i.a[s.phoneCode]||s,(s.pattern||s.phoneCode).split("").forEach((t,s)=>{" "===t&&" "!==e[s]&&e.length>s&&(e=e.slice(0,s)+" "+e.slice(s))}),{formatted:e,country:s}):{formatted:e,country:s}}a.a.putPreloader=c;let p=e=>{let t=_.getBoundingClientRect(),{clientX:s,clientY:a}=e,i=s>=t.right?s-t.right:t.left-s,n=a>=t.bottom?a-t.bottom:t.top-a;(i>=100||n>=100)&&f()};const m=e=>{f()},f=()=>{_&&(_.classList.remove("active"),_.parentElement.classList.remove("menu-open"),X&&X.remove(),_=null),v&&(v(),v=null),r.isTouchSupported||(window.removeEventListener("mousemove",p),window.removeEventListener("contextmenu",m)),document.removeEventListener(n.a,m),d.isMobileSafari||l.a.removeByType("menu")};window.addEventListener("resize",()=>{_&&f()});let _=null,v=null,X=null;function b(e,t){f(),d.isMobileSafari||l.a.pushItem({type:"menu",onPop:e=>{f()}}),_=e,_.classList.add("active"),_.parentElement.classList.add("menu-open"),X||(X=document.createElement("div"),X.classList.add("btn-menu-overlay"),X.addEventListener(n.a,e=>{Object(n.f)(e),m()})),_.parentElement.insertBefore(X,_),v=t,r.isTouchSupported||(window.addEventListener("mousemove",p),window.addEventListener("contextmenu",m,{once:!0})),document.addEventListener(n.a,m)}function y({pageX:e,pageY:t},s,a){let{scrollWidth:i,scrollHeight:n}=s;const r=document.body.getBoundingClientRect(),d=r.width,l=r.height;a=o.b.isMobile?"right":"left";let c="top";const h={x:{left:e,right:e-i},intermediateX:"right"===a?8:d-i-8,y:{top:t,bottom:t-n},intermediateY:t<l/2?8:l-n-8},u={left:h.x.left+i+8<=d,right:h.x.right>=8},g={top:h.y.top+n+8<=l,bottom:h.y.bottom-8>=8};{let e;e=u[a]?h.x[a]:(a="center",h.intermediateX),s.style.left=e+"px"}{let e;e=g[c]?h.y[c]:(c="center",h.intermediateY),s.style.top=e+"px"}s.className=s.className.replace(/(top|center|bottom)-(left|center|right)/g,""),s.classList.add(("center"===c?c:"bottom")+"-"+("center"===a?a:"left"===a?"right":"left"))}function C(e,t,s){const a=s?s.add.bind(s,e):e.addEventListener.bind(e),i=s?s.removeManual.bind(s,e):e.removeEventListener.bind(e);if(d.isApple&&r.isTouchSupported){let s;const o={capture:!0},r=()=>{clearTimeout(s),i("touchmove",r,o),i("touchend",r,o),i("touchcancel",r,o)};a("touchstart",i=>{i.touches.length>1?r():(a("touchmove",r,o),a("touchend",r,o),a("touchcancel",r,o),s=window.setTimeout(()=>{t(i.touches[0]),r(),_&&e.addEventListener("touchend",n.f,{once:!0})},400))})}else a("contextmenu",r.isTouchSupported?s=>{t(s),_&&e.addEventListener("touchend",n.f,{once:!0})}:t)}},function(e,t,s){"use strict";var a=s(54),i=s(61),n=s(30),o=s(31),r=s(65),d=s(15),l=s(42),c=s(33),h=s(8),u=s(26),g=s(13),p=s(70),m=s(63),f=s(11),_=s(9),v=s(71),X=s(47);class b{constructor(e,t,s,a){this.appMessagesManager=e,this.appChatsManager=t,this.appPeersManager=s,this.serverTimeManager=a,this.dialogs={},this.byFolders={},this.dialogsIndex=v.a.createIndex(),this.reset()}reset(){this.allDialogsLoaded={},this.dialogsOffsetDate={},this.pinnedOrders={0:[],1:[]},this.dialogsNum=0}getOffsetDate(e){return this.dialogsOffsetDate[e]||0}getFolder(e){var t,s;if(e<=1)return null!==(t=this.byFolders[e])&&void 0!==t?t:this.byFolders[e]=[];const a=[],i=this.appMessagesManager.filtersStorage.filters[e];for(const e in this.dialogs){const t=this.dialogs[e];if(this.appMessagesManager.filtersStorage.testDialogForFilter(t,i)){let e;const n=i.pinned_peers.indexOf(t.peerId);e=-1!==n?this.generateDialogIndex(this.generateDialogPinnedDateByIndex(i.pinned_peers.length-1-n)):(null===(s=t.pFlags)||void 0===s?void 0:s.pinned)?this.generateIndexForDialog(t,!0):t.index,a.push({dialog:t,index:e})}}return a.sort((e,t)=>t.index-e.index),a.map(e=>e.dialog)}getDialog(e,t){const s=[];if(void 0===t){const e=this.byFolders;for(const t in e)s.push(e[t])}else s.push(this.getFolder(t));for(let t of s){const s=t.findIndex(t=>t.peerId===e);if(-1!==s)return[t[s],s]}return[]}generateDialogIndex(e){return void 0===e&&(e=Object(o.g)(!0)+this.serverTimeManager.serverTimeOffset),65536*e+(65535&++this.dialogsNum)}generateIndexForDialog(e,t=!1,s){const a=this.appPeersManager.isChannel(e.peerId)?-e.peerId:0;let i=0;if(e.pFlags.pinned&&!t)i=this.generateDialogPinnedDate(e);else{if(s||(s=this.appMessagesManager.getMessageByPeer(e.peerId,e.top_message)),i=s.date||i,a){const e=this.appChatsManager.getChat(a);(!i||e.date&&e.date>i)&&(i=e.date)}e.draft&&"draftMessage"===e.draft._&&e.draft.date>i&&(i=e.draft.date)}i||(i=Date.now()/1e3);const n=this.generateDialogIndex(i);if(t)return n;e.index=n}generateDialogPinnedDateByIndex(e){return 2147418112+(65535&e)}generateDialogPinnedDate(e){const t=this.pinnedOrders[e.folder_id],s=t.indexOf(e.peerId),a=-1===s?t.push(e.peerId)-1:s;return this.generateDialogPinnedDateByIndex(a)}pushDialog(e,t){const s=this.getFolder(e.folder_id),a=s.findIndex(t=>t.peerId===e.peerId);if(-1!==a&&s.splice(a,1),this.dialogs[e.peerId]=e,t&&!e.pFlags.pinned&&(!this.dialogsOffsetDate[e.folder_id]||t<this.dialogsOffsetDate[e.folder_id])){if(-1!==a)return!1;this.dialogsOffsetDate[e.folder_id]=t}Object(X.d)(s,e,"index",a)}dropDialog(e){const t=this.getDialog(e);return t[0]&&(this.byFolders[t[0].folder_id].splice(t[1],1),delete this.dialogs[e],v.a.indexObject(e,"",this.dialogsIndex)),t}}var y=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};class C{constructor(e,t,s,a,i,n){this.appMessagesManager=e,this.appPeersManager=t,this.appUsersManager=s,this.appNotificationsManager=a,this.apiUpdatesManager=i,this.rootScope=n,this.filters={},this.orderIndex=1,this.onUpdateDialogFilter=e=>{e.filter?this.saveDialogFilter(e.filter):this.filters[e.id]&&(this.rootScope.broadcast("filter_delete",this.filters[e.id]),delete this.filters[e.id])},this.onUpdateDialogFilterOrder=e=>{this.orderIndex=1,e.order.forEach((e,t)=>{const s=this.filters[e];delete s.orderIndex,this.setOrderIndex(s)}),this.rootScope.broadcast("filter_order",e.order)},n.addMultipleEventsListeners({updateDialogFilter:this.onUpdateDialogFilter,updateDialogFilters:e=>{const t=Object(d.a)(this.filters);this.getDialogFilters(!0).then(e=>{for(const s in t){const t=+s;e.find(e=>e.id===t)||this.onUpdateDialogFilter({_:"updateDialogFilter",id:t})}this.onUpdateDialogFilterOrder({_:"updateDialogFilterOrder",order:e.map(e=>e.id)})})},updateDialogFilterOrder:this.onUpdateDialogFilterOrder})}testDialogForFilter(e,t){for(const s of t.exclude_peers)if(s===e.peerId)return!1;for(const s of t.include_peers)if(s===e.peerId)return!0;const s=t.pFlags;if(s.exclude_archived&&1===e.folder_id)return!1;if(s.exclude_read&&!e.unread_count)return!1;if(s.exclude_muted){if(this.appNotificationsManager.isPeerLocalMuted(e.peerId))return!1}const a=e.peerId;if(a<0){if(s.broadcasts&&this.appPeersManager.isBroadcast(a))return!0;if(s.groups&&this.appPeersManager.isAnyGroup(a))return!0}else{if(this.appPeersManager.isBot(a))return!!s.bots;if(s.non_contacts&&!this.appUsersManager.isContact(a))return!0;if(s.contacts&&this.appUsersManager.isContact(a))return!0}return!1}toggleDialogPin(e,t){const s=this.filters[t];return s.pinned_peers.findAndSplice(t=>t===e)||s.pinned_peers.unshift(e),this.updateDialogFilter(s)}createDialogFilter(e){let t=Math.max(1,...Object.keys(this.filters).map(e=>+e));return(e=Object(d.a)(e)).id=t+1,this.updateDialogFilter(e)}updateDialogFilter(e,t=!1){const s=t?0:1;return g.a.invokeApi("messages.updateDialogFilter",{flags:s,id:e.id,filter:t?void 0:this.getOutputDialogFilter(e)}).then(s=>(s&&this.onUpdateDialogFilter({_:"updateDialogFilter",id:e.id,filter:t?void 0:e}),s))}getOutputDialogFilter(e){const t=Object(d.a)(e);return["pinned_peers","exclude_peers","include_peers"].forEach(e=>{t[e]=t[e].map(e=>this.appPeersManager.getInputPeerById(e))}),Object(X.c)(t.include_peers,(e,s)=>{t.pinned_peers.includes(e)&&t.include_peers.splice(s,1)}),t}getDialogFilters(e=!1){return y(this,void 0,void 0,(function*(){const t=Object.keys(this.filters);if(t.length&&!e)return t.map(e=>this.filters[e]).sort((e,t)=>e.orderIndex-t.orderIndex);const s=yield g.a.invokeApi("messages.getDialogFilters");for(const t of s)this.saveDialogFilter(t,e);return s}))}saveDialogFilter(e,t=!0){["pinned_peers","exclude_peers","include_peers"].forEach(t=>{e[t]=e[t].map(e=>this.appPeersManager.getPeerId(e))}),Object(X.c)(e.include_peers,(t,s)=>{e.pinned_peers.includes(t)&&e.include_peers.splice(s,1)}),e.include_peers=e.pinned_peers.concat(e.include_peers),this.filters[e.id]?Object.assign(this.filters[e.id],e):this.filters[e.id]=e,this.setOrderIndex(e),t&&this.rootScope.broadcast("filter_update",e)}setOrderIndex(e){e.hasOwnProperty("orderIndex")?e.orderIndex>=this.orderIndex&&(this.orderIndex=e.orderIndex+1):e.orderIndex=this.orderIndex++}}var P=s(51),M=s(25),I=s(38),w=s(53),S=s(24),k=s(35),A=s(73),D=s(14),F=s(18),T=s(93),j=s(87),x=s(91),E=s(72),U=s(34),O=s(10),L=s(94),R=s(58),B=s(41),N=s(7),H=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};class W{constructor(){this.messagesStorageByPeerId={},this.groupedMessagesStorage={},this.scheduledMessagesStorage={},this.historiesStorage={},this.threadsStorage={},this.searchesStorage={},this.pinnedMessages={},this.threadsServiceMessagesIdsStorage={},this.threadsToReplies={},this.pendingByRandomId={},this.pendingByMessageId={},this.pendingAfterMsgs={},this.pendingTopMsgs={},this.sendFilePromise=Promise.resolve(),this.tempNum=0,this.tempFinalizeCallbacks={},this.sendSmthLazyLoadQueue=new a.a(1),this.needSingleMessages={},this.fetchSingleMessagesPromise=null,this.maxSeenId=0,this.migratedFromTo={},this.migratedToFrom={},this.newMessagesHandlePromise=0,this.newMessagesToHandle={},this.newDialogsHandlePromise=0,this.newDialogsToHandle={},this.newUpdatesAfterReloadToHandle={},this.notificationsHandlePromise=0,this.notificationsToHandle={},this.reloadConversationsPeers=[],this.cachedResults={query:"",count:0,dialogs:[],folderId:0},this.log=Object(u.b)("MESSAGES",u.a.error|u.a.debug|u.a.log|u.a.warn),this.groupedTempId=0,this.saveState=()=>{const e=[],t=[],s=[];for(const e in this.dialogsStorage.byFolders){const t=this.dialogsStorage.getFolder(+e);for(let e of t)s.push([e])}return Object(x.a)({items:s,process:s=>{const a=this.getHistoryStorage(s.peerId),i=[].concat(a.history.slice);let n=0;for(const t of i){const a=this.getMessageByPeer(s.peerId,t);if(!a.pFlags.is_outgoing){e.push(a),a.fromId!==s.peerId&&D.default.setPeer(a.fromId,S.a.getPeer(a.fromId));break}a.pFlags&&a.pFlags.unread&&++n}if(n&&s.unread_count&&(s.unread_count-=n),s.peerId<0&&s.pts){const e=P.a.channelStates[-s.peerId].pts;s.pts=e}s.unread_count=Math.max(0,s.unread_count),t.push(s),D.default.setPeer(s.peerId,S.a.getPeer(s.peerId))},context:this}).then(()=>{D.default.pushToState("dialogs",t),D.default.pushToState("messages",e),D.default.pushToState("filters",this.filtersStorage.filters),D.default.pushToState("allDialogsLoaded",this.dialogsStorage.allDialogsLoaded),D.default.pushToState("maxSeenMsgId",this.maxSeenId)})},this.handleNewMessages=()=>{clearTimeout(this.newMessagesHandlePromise),this.newMessagesHandlePromise=0,_.default.broadcast("history_multiappend",this.newMessagesToHandle),this.newMessagesToHandle={}},this.handleNewDialogs=()=>{clearTimeout(this.newDialogsHandlePromise),this.newDialogsHandlePromise=0;let e=0;for(const t in this.newDialogsToHandle){const s=this.newDialogsToHandle[t];"reload"in s?(this.reloadConversation(+t),delete this.newDialogsToHandle[t]):(this.dialogsStorage.pushDialog(s),S.a.isChannel(+t)||(e=Math.max(e,s.top_message||0)))}0!==e&&this.incrementMaxSeenId(e),_.default.broadcast("dialogs_multiupdate",this.newDialogsToHandle),this.newDialogsToHandle={}},this.handleNotifications=()=>{window.clearTimeout(this.notificationsHandlePromise),this.notificationsHandlePromise=0;for(const e in this.notificationsToHandle){const t=+e;if(_.default.peerId===t&&!_.default.idle.isIDLE)continue;const s=this.notificationsToHandle[t];Promise.all([R.a.getNotifyPeerTypeSettings(),R.a.getNotifySettings(S.a.getInputNotifyPeerById(t,!0))]).then(([e,a])=>{const i=s.topMessage;!R.a.isPeerLocalMuted(t,!0)&&i.pFlags.unread&&i.pFlags.unread&&this.notifyAboutMessage(i,{fwdCount:s.fwdCount,peerTypeNotifySettings:a})})}this.notificationsToHandle={}},this.onUpdateMessageId=e=>{const t=e.random_id,s=this.pendingByRandomId[t];if(s){const{peerId:a,tempId:i,threadId:n,storage:o}=s,r=this.generateMessageId(e.id);this.getMessageFromStorage(o,r).deleted?this.pendingByMessageId[r]=t:([this.getHistoryStorage(a),n?this.getHistoryStorage(a,n):void 0].filter(Boolean).forEach(e=>{e.history.delete(i)}),this.finalizePendingMessageCallbacks(o,i,r))}},this.onUpdateNewMessage=e=>{var t;const s=e.message,a=this.getMessagePeer(s),i=this.getMessagesStorage(a),n=this.getDialogByPeerId(a),o="updateNewDiscussionMessage"===e._;this.saveMessages([s],{storage:{}});const r=this.getThreadKey(s),d=r?+r.split("_")[1]:void 0;if(d&&!o&&this.threadsStorage[a]&&this.threadsStorage[a][d]){const e={_:"updateNewDiscussionMessage",message:s};this.onUpdateNewMessage(e)}if(!n.length&&!o){let s=!0;if(a<0){const e=M.a.getChat(-a);("channelForbidden"===e._||"chatForbidden"===e._||e.pFlags.left||e.pFlags.kicked||e.pFlags.deactivated)&&(s=!1)}if(s){if((null!==(t=this.newUpdatesAfterReloadToHandle[a])&&void 0!==t?t:this.newUpdatesAfterReloadToHandle[a]=new Set).has(e))return void this.log.error("here we go again",a);this.newDialogsToHandle[a]={reload:!0},this.scheduleHandleNewDialogs(),this.newUpdatesAfterReloadToHandle[a].add(e)}return}this.saveMessages([s],{storage:i});const l=this.checkPendingMessage(s),c=this.getHistoryStorage(a,o?d:void 0);if(o||this.updateMessageRepliesIfNeeded(s),c.history.findSlice(s.mid))return!1;const h=c.history.slice,u=h[0];if(h.unshift(s.mid),s.mid<u&&h.sort((e,t)=>t-e),null!==c.count&&c.count++,this.mergeReplyKeyboard(c,s)&&_.default.broadcast("history_reply_markup",{peerId:a}),s.fromId>0&&!s.pFlags.out&&s.from_id&&F.a.forceUserOnline(s.fromId,s.date),l||(void 0===this.newMessagesToHandle[a]&&(this.newMessagesToHandle[a]=new Set),this.newMessagesToHandle[a].add(s.mid),this.newMessagesHandlePromise||(this.newMessagesHandlePromise=window.setTimeout(this.handleNewMessages,0))),o)return;const g=n[0],p=!s.pFlags.out&&s.pFlags.unread;if(g&&(this.setDialogTopMessage(s,g),p&&g.unread_count++),p){const e=s.peerId;let t=this.notificationsToHandle[e];void 0===t&&(t=this.notificationsToHandle[e]={fwdCount:0,fromId:0}),t.fromId!==s.fromId&&(t.fromId=s.fromId,t.fwdCount=0),s.fwd_from&&t.fwdCount++,t.topMessage=s,this.notificationsHandlePromise||(this.notificationsHandlePromise=window.setTimeout(this.handleNotifications,0))}},this.onUpdateDialogUnreadMark=e=>{const t=S.a.getPeerId(e.peer.peer),s=this.getDialogByPeerId(t);if(s.length){const t=s[0];e.pFlags.unread?t.pFlags.unread_mark=!0:delete t.pFlags.unread_mark,_.default.broadcast("dialogs_multiupdate",{peerId:t})}else this.newDialogsToHandle[t]={reload:!0},this.scheduleHandleNewDialogs()},this.onUpdateFolderPeers=e=>{const t=e.folder_peers;this.scheduleHandleNewDialogs(),t.forEach(e=>{var t;const{folder_id:s,peer:a}=e,i=S.a.getPeerId(a),n=this.dialogsStorage.dropDialog(i);if(n.length){const e=n[0];this.newDialogsToHandle[i]=e,(null===(t=e.pFlags)||void 0===t?void 0:t.pinned)&&(delete e.pFlags.pinned,this.dialogsStorage.pinnedOrders[s].findAndSplice(t=>t===e.peerId)),e.folder_id=s,this.dialogsStorage.generateIndexForDialog(e),this.dialogsStorage.pushDialog(e)}else this.newDialogsToHandle[i]={reload:!0}})},this.onUpdateDialogPinned=e=>{var t;const s=null!==(t=e.folder_id)&&void 0!==t?t:0,a=S.a.getPeerId(e.peer.peer),i=this.getDialogByPeerId(a);if(this.scheduleHandleNewDialogs(),i.length){const t=i[0];this.newDialogsToHandle[a]=t,e.pFlags.pinned?t.pFlags.pinned=!0:(delete t.pFlags.pinned,this.dialogsStorage.pinnedOrders[s].findAndSplice(e=>e===t.peerId)),this.dialogsStorage.generateIndexForDialog(t)}else this.newDialogsToHandle[a]={reload:!0}},this.onUpdatePinnedDialogs=e=>{var t;const s=null!==(t=e.folder_id)&&void 0!==t?t:0,a=e=>{this.dialogsStorage.pinnedOrders[s].length=0;let t=!1;e.reverse(),e.forEach(e=>{i[e]=!0;const s=this.getDialogByPeerId(e);if(!s.length)return this.newDialogsToHandle[e]={reload:!0},void(t=!0);const a=s[0];a.pFlags.pinned=!0,this.dialogsStorage.generateIndexForDialog(a),this.newDialogsToHandle[e]=a,t=!0}),this.dialogsStorage.getFolder(s).forEach(e=>{const s=e.peerId;e.pFlags.pinned&&!i[s]&&(this.newDialogsToHandle[s]={reload:!0},t=!0)}),t&&this.scheduleHandleNewDialogs()},i={};e.order?a(e.order.map(e=>S.a.getPeerId(e.peer))):g.a.invokeApi("messages.getPinnedDialogs",{folder_id:s}).then(e=>{this.applyConversations(e),a(e.dialogs.map(e=>e.peerId))})},this.onUpdateEditMessage=e=>{const t=e.message,s=this.getMessagePeer(t),a=this.generateMessageId(t.id),i=this.getMessagesStorage(s);if(void 0===i[a])return;const n=this.getMessageFromStorage(i,a);this.saveMessages([t],{storage:i});const o=this.getMessageFromStorage(i,a);this.handleEditedMessage(n,o);const r=this.getDialogByPeerId(s)[0],d=r&&r.top_message===a;if(t.clear_history)d&&_.default.broadcast("dialog_flush",{peerId:s});else if(_.default.broadcast("message_edit",{storage:i,peerId:s,mid:a}),d||t.grouped_id){const e={};e[s]=r,_.default.broadcast("dialogs_multiupdate",e)}},this.onUpdateReadHistory=e=>{const t=e.channel_id,s=this.generateMessageId(e.max_id||e.read_max_id),a=this.generateMessageId(e.top_msg_id),i=t?-t:S.a.getPeerId(e.peer),n="updateReadHistoryOutbox"===e._||"updateReadChannelOutbox"===e._||"updateReadChannelDiscussionOutbox"===e._||void 0,o=this.getMessagesStorage(i),r=Object(d.e)(o,"desc"),l=this.getDialogByPeerId(i)[0],c=e.still_unread_count;let h=0,u=!1;const g=this.getHistoryStorage(i,a);if(i>0&&n&&F.a.forceUserOnline(i),a){const e=this.threadsToReplies[i+"_"+a];if(e){const[t,s]=e.split("_").map(e=>+e);this.updateMessage(t,s,"replies_updated")}}for(let e=0,t=r.length;e<t;e++){const t=r[e];if(t>s)continue;const i=o[t];if(i.pFlags.out===n){if(!i.pFlags.unread)break;if(a){const e=i.reply_to;if(!e||(e.reply_to_top_id||e.reply_to_msg_id)!==a)continue}i.pFlags.unread&&(delete i.pFlags.unread,u||(u=!0),i.pFlags.out||a||void 0!==c||(h=--l.unread_count),R.a.cancel("msg"+t))}}if(n?g.readOutboxMaxId=s:g.readMaxId=s,!a&&l&&(n?l.read_outbox_max_id=s:l.read_inbox_max_id=s,n||(h<0||!this.getReadMaxIdIfUnread(i)?l.unread_count=0:h&&l.top_message>s&&(l.unread_count=h)),_.default.broadcast("dialog_unread",{peerId:i})),u&&_.default.broadcast("messages_read"),!a&&t){const e=i+"_";for(const t in this.threadsToReplies)if(0===t.indexOf(e)){const[e,s]=this.threadsToReplies[t].split("_").map(e=>+e);_.default.broadcast("replies_updated",this.getMessageByPeer(e,s))}}},this.onUpdateReadMessagesContents=e=>{const t=e.channel_id,s=e.messages.map(e=>this.generateMessageId(e)),a=t?-t:this.getMessageById(s[0]).peerId;for(const e of s){const t=this.getMessageByPeer(a,e);t.deleted||delete t.pFlags.media_unread}_.default.broadcast("messages_media_read",{peerId:a,mids:s})},this.onUpdateChannelAvailableMessages=e=>{const t=e.channel_id,s=[],a=-t,i=this.getHistoryStorage(a).history.slice;i.length&&i.forEach(t=>{(!e.available_min_id||t<=e.available_min_id)&&s.push(t)}),e.messages=s,this.onUpdateDeleteMessages(e)},this.onUpdateDeleteMessages=e=>{const t=e.channel_id,s=e.messages.map(e=>this.generateMessageId(e)),a=t?-t:this.getMessageById(s[0]).peerId;if(!a)return;g.a.clearCache("messages.getSearchCounters",e=>S.a.getPeerId(e.peer)===a);const i=new Set;for(const e of s){const t=this.getMessageByPeer(a,e),s=this.getThreadKey(t);s&&this.threadsStorage[a]&&this.threadsStorage[a][+s.split("_")[1]]&&i.add(s)}const n=this.handleDeletedMessages(a,this.getMessagesStorage(a),s),o=Array.from(i).map(e=>{const t=e.split("_");return this.getHistoryStorage(+t[0],+t[1])});[this.getHistoryStorage(a)].concat(o).forEach(e=>{for(const t in n.msgs)e.history.delete(+t);n.count&&null!==e.count&&e.count>0&&(e.count-=n.count,e.count<0&&(e.count=0))}),_.default.broadcast("history_delete",{peerId:a,msgs:n.msgs});const r=this.getDialogByPeerId(a)[0];r&&(n.unread&&(r.unread_count-=n.unread,_.default.broadcast("dialog_unread",{peerId:a})),n.msgs[r.top_message]&&this.reloadConversation(a))},this.onUpdateChannel=e=>{const t=e.channel_id,s=-t,a=M.a.getChat(t),i="channel"===a._&&!a.pFlags.left&&!a.pFlags.kicked,n=this.getDialogByPeerId(s),o=n.length>0;("channel"===a._&&(a.username||!a.pFlags.left&&!a.pFlags.kicked))!==(void 0!==this.historiesStorage[s])&&(delete this.historiesStorage[s],_.default.broadcast("history_forbidden",s)),o!==i&&(i?this.reloadConversation(-t):n[0]&&(this.dialogsStorage.dropDialog(s),_.default.broadcast("dialog_drop",{peerId:s,dialog:n[0]})))},this.onUpdateChannelReload=e=>{const t=e.channel_id,s=-t;this.dialogsStorage.dropDialog(s),delete this.historiesStorage[s],this.reloadConversation(-t).then(()=>{_.default.broadcast("history_reload",s)})},this.onUpdateChannelMessageViews=e=>{const t=e.views,s=this.generateMessageId(e.id),a=this.getMessageByPeer(-e.channel_id,s);!a.deleted&&a.views&&a.views<t&&(a.views=t,_.default.broadcast("message_views",{mid:s,views:t}))},this.onUpdateServiceNotification=e=>{const t=this.generateTempMessageId(777e3),s={_:"message",id:t,from_id:S.a.getOutputPeer(777e3),peer_id:S.a.getOutputPeer(777e3),pFlags:{unread:!0},date:(e.inbox_date||Object(o.g)(!0))+m.a.serverTimeOffset,message:e.message,media:e.media,entities:e.entities};F.a.hasUser(777e3)||F.a.saveApiUsers([{_:"user",id:777e3,pFlags:{verified:!0},access_hash:0,first_name:"Telegram",phone:"42777"}]),this.saveMessages([s],{isOutgoing:!0}),e.inbox_date&&(this.pendingTopMsgs[777e3]=t,this.onUpdateNewMessage({_:"updateNewMessage",message:s}))},this.onUpdatePinnedMessages=e=>{const t="updatePinnedChannelMessages"===e._?e.channel_id:void 0,s=t?-t:S.a.getPeerId(e.peer),a=e.messages.map(e=>this.generateMessageId(e)),i=this.getMessagesStorage(s),n=a.filter(e=>!i[e]);(n.length?Promise.all(n.map(e=>this.wrapSingleMessage(s,e))):Promise.resolve()).finally(()=>{var t;const n=null===(t=e.pFlags)||void 0===t?void 0:t.pinned;if(n)for(const e of a){i[e].pFlags.pinned=!0}else for(const e of a){delete i[e].pFlags.pinned}delete this.pinnedMessages[s],D.default.getState().then(e=>{delete e.hiddenPinnedMessages[s],_.default.broadcast("peer_pinned_messages",{peerId:s,mids:a,pinned:n})})})},this.onUpdateNotifySettings=e=>{const{peer:t,notify_settings:s}=e;if("notifyPeer"===t._){const e=S.a.getPeerId(t.peer),a=this.getDialogByPeerId(e)[0];a&&(a.notify_settings=s,_.default.broadcast("dialog_notify_settings",a))}},this.onUpdateNewScheduledMessage=e=>{const t=e.message,s=this.getMessagePeer(t),a=this.scheduledMessagesStorage[s];if(a){const e=this.generateMessageId(t.id),i=this.getMessageFromStorage(a,e);this.saveMessages([t],{storage:a,isScheduled:!0});const n=this.getMessageFromStorage(a,e);if(i.deleted){this.checkPendingMessage(t)||_.default.broadcast("scheduled_new",{peerId:s,mid:t.mid})}else this.handleEditedMessage(i,n),_.default.broadcast("message_edit",{storage:a,peerId:s,mid:t.mid})}},this.onUpdateDeleteScheduledMessages=e=>{const t=S.a.getPeerId(e.peer),s=this.scheduledMessagesStorage[t];if(s){const a=e.messages.map(e=>this.generateMessageId(e));this.handleDeletedMessages(t,s,a),_.default.broadcast("scheduled_delete",{peerId:t,mids:a})}},this.dialogsStorage=new b(this,M.a,S.a,m.a),this.filtersStorage=new C(this,S.a,F.a,R.a,P.a,_.default),_.default.addMultipleEventsListeners({updateMessageID:this.onUpdateMessageId,updateNewDiscussionMessage:this.onUpdateNewMessage,updateNewMessage:this.onUpdateNewMessage,updateNewChannelMessage:this.onUpdateNewMessage,updateDialogUnreadMark:this.onUpdateDialogUnreadMark,updateFolderPeers:this.onUpdateFolderPeers,updateDialogPinned:this.onUpdateDialogPinned,updatePinnedDialogs:this.onUpdatePinnedDialogs,updateEditMessage:this.onUpdateEditMessage,updateEditChannelMessage:this.onUpdateEditMessage,updateReadChannelDiscussionInbox:this.onUpdateReadHistory,updateReadChannelDiscussionOutbox:this.onUpdateReadHistory,updateReadHistoryInbox:this.onUpdateReadHistory,updateReadHistoryOutbox:this.onUpdateReadHistory,updateReadChannelInbox:this.onUpdateReadHistory,updateReadChannelOutbox:this.onUpdateReadHistory,updateChannelReadMessagesContents:this.onUpdateReadMessagesContents,updateReadMessagesContents:this.onUpdateReadMessagesContents,updateChannelAvailableMessages:this.onUpdateChannelAvailableMessages,updateDeleteMessages:this.onUpdateDeleteMessages,updateDeleteChannelMessages:this.onUpdateDeleteMessages,updateChannel:this.onUpdateChannel,updateChannelReload:this.onUpdateChannelReload,updateChannelMessageViews:this.onUpdateChannelMessageViews,updateServiceNotification:this.onUpdateServiceNotification,updatePinnedMessages:this.onUpdatePinnedMessages,updatePinnedChannelMessages:this.onUpdatePinnedMessages,updateNotifySettings:this.onUpdateNotifySettings,updateNewScheduledMessage:this.onUpdateNewScheduledMessage,updateDeleteScheduledMessages:this.onUpdateDeleteScheduledMessages}),_.default.on("notify_peer_type_settings",({key:e,settings:t})=>{this.getConversationsAll().then(t=>{let s;s="notifyUsers"===e?e=>e.peerId>0:"notifyBroadcasts"===e?e=>M.a.isBroadcast(-e.peerId):e=>S.a.isAnyGroup(e.peerId),t.filter(s).forEach(e=>{_.default.broadcast("dialog_notify_settings",e)})})}),_.default.on("language_change",e=>{const t=F.a.getSelf().id;if(this.getDialogByPeerId(t)[0]){const e=S.a.getPeerSearchText(t);v.a.indexObject(t,e,this.dialogsStorage.dialogsIndex)}}),_.default.on("webpage_updated",e=>{const t=e;t.msgs.forEach(e=>{const s=this.getMessageById(e);if(!s)return;s.media={_:"messageMediaWebPage",webpage:T.a.getWebPage(t.id)};const a=this.getMessagePeer(s),i=this.getMessagesStorage(a);_.default.broadcast("message_edit",{storage:i,peerId:a,mid:e})})}),_.default.on("draft_updated",e=>{const{peerId:t,threadId:s,draft:a}=e;if(s)return;const i=this.getDialogByPeerId(t)[0];i&&!s?(i.draft=a,this.dialogsStorage.generateIndexForDialog(i),this.dialogsStorage.pushDialog(i),_.default.broadcast("dialog_draft",{peerId:t,draft:a,index:i.index})):this.reloadConversation(t)}),D.default.getState().then(e=>{e.maxSeenMsgId&&(this.maxSeenId=e.maxSeenMsgId);const t=e.messages;if(t&&this.saveMessages(t),e.dialogs&&Object.keys(e.dialogs).length||(e.allDialogsLoaded={}),e.allDialogsLoaded&&(this.dialogsStorage.allDialogsLoaded=e.allDialogsLoaded),e.filters)for(const t in e.filters)this.filtersStorage.saveDialogFilter(e.filters[t],!1);e.dialogs&&Object(X.c)(e.dialogs,e=>{e.top_message=this.getServerMessageId(e.top_message),this.saveConversation(e);this.getMessageByPeer(e.peerId,e.top_message).deleted&&this.reloadConversation(e.peerId)}),D.default.addEventListener("save",this.saveState)}),R.a.start()}getInputEntities(e){var t=Object(d.a)(e);return t.forEach(e=>{"messageEntityMentionName"===e._&&(e._="inputMessageEntityMentionName",e.user_id=F.a.getUserInput(e.user_id))}),t}invokeAfterMessageIsSent(e,t,s){var a,i;const o=null!==(a=this.tempFinalizeCallbacks[e])&&void 0!==a?a:this.tempFinalizeCallbacks[e]={},r=null!==(i=o[t])&&void 0!==i?i:o[t]={deferred:Object(n.a)()};return r.callback=s,r.deferred}editMessage(e,t,s={}){const{mid:a,peerId:i}=e;if(e.pFlags.is_outgoing)return this.invokeAfterMessageIsSent(a,"edit",e=>this.editMessage(e,t,s));let n=s.entities||[];t&&(t=f.a.parseMarkdown(t,n));const o=s.scheduleDate||(e.pFlags.is_scheduled?e.date:void 0);return g.a.invokeApi("messages.editMessage",{peer:S.a.getInputPeerById(i),id:e.id,message:t,media:s.newMedia,entities:n.length?this.getInputEntities(n):void 0,no_webpage:s.noWebPage,schedule_date:o}).then(e=>{P.a.processUpdateMessage(e)},e=>{if(this.log.error("editMessage error:",e),!e||"MESSAGE_NOT_MODIFIED"!==e.type)return e&&"MESSAGE_EMPTY"===e.type&&(e.handled=!0),Promise.reject(e);e.handled=!0})}sendText(e,t,s={}){if("string"!=typeof t||!t.length)return;s.threadId&&!s.replyToMsgId&&(s.replyToMsgId=s.threadId);if(t.length>4096){const a=Object(c.h)(t,4096);t=a[0],a.length>1&&delete s.webPage;for(let t=1;t<a.length;++t)setTimeout(()=>{this.sendText(e,a[t],s)},t)}e=S.a.getPeerMigratedTo(e)||e;let a=s.entities||[];s.viaBotId||(t=f.a.parseMarkdown(t,a));let i=this.getInputEntities(a);i.length||(i=void 0);const n=this.generateOutgoingMessage(e,s);n.entities=a,n.message=t;const o=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0,r=S.a.isChannel(e);s.webPage&&(n.media={_:"messageMediaWebPage",webpage:s.webPage});const d=e=>{e?n.error=!0:delete n.error,_.default.broadcast("messages_pending")};n.send=()=>{d(!1);const a={};let l;this.pendingAfterMsgs[e]&&(a.afterMessageId=this.pendingAfterMsgs[e].messageId),l=s.viaBotId?g.a.invokeApiAfter("messages.sendInlineBotResult",{peer:S.a.getInputPeerById(e),random_id:n.random_id,reply_to_msg_id:o||void 0,query_id:s.queryId,id:s.resultId,clear_draft:s.clearDraft},a):g.a.invokeApiAfter("messages.sendMessage",{no_webpage:s.noWebPage,peer:S.a.getInputPeerById(e),message:t,random_id:n.random_id,reply_to_msg_id:o||void 0,entities:i,clear_draft:s.clearDraft,schedule_date:s.scheduleDate||void 0,silent:s.silent},a),l.then(e=>{"updateShortSentMessage"===e._?(n.date=e.date,n.id=e.id,n.media=e.media,n.entities=e.entities,e={_:"updates",users:[],chats:[],seq:0,updates:[{_:"updateMessageID",random_id:n.random_id,id:e.id},{_:s.scheduleDate?"updateNewScheduledMessage":r?"updateNewChannelMessage":"updateNewMessage",message:n,pts:e.pts,pts_count:e.pts_count}]}):e.updates&&e.updates.forEach(e=>{"updateDraftMessage"===e._&&(e.local=!0)}),P.a.processUpdateMessage(e)},()=>{d(!0)}).finally(()=>{this.pendingAfterMsgs[e]===a&&delete this.pendingAfterMsgs[e]}),this.pendingAfterMsgs[e]=a},this.beforeMessageSending(n,{isScheduled:!!s.scheduleDate||void 0,threadId:s.threadId,clearDraft:s.clearDraft})}sendFile(e,t,s={}){e=S.a.getPeerMigratedTo(e)||e;const a=this.generateOutgoingMessage(e,s),o=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0;let l,c;const h="mime_type"in t?t.mime_type:t.type,u=t instanceof File?t.name:"",p=!(t instanceof File||t instanceof Blob);let m=s.caption||"";this.log("sendFile",t,h);const v=s.entities||[];m&&(m=f.a.parseMarkdown(m,v));const X=[],b=["image/jpeg","image/png","image/bmp"].indexOf(h)>=0;let y,C,M="";if(p)l="document",c="";else if(0===h.indexOf("audio/")||["video/ogg"].indexOf(h)>=0){l="audio",c="audio."+("ogg"===h.split("/")[1]?"ogg":"mp3"),M="sendMessageUploadAudioAction",s.isVoiceMessage&&(l="voice",a.pFlags.media_unread=!0);let e={_:"documentAttributeAudio",pFlags:{voice:s.isVoiceMessage},waveform:s.waveform,duration:s.duration||0};X.push(e)}else if(s.isMedia)if(b)l="photo",c="photo."+h.split("/")[1],M="sendMessageUploadPhotoAction",y={_:"photo",id:""+a.id,sizes:[{_:"photoSize",w:s.width,h:s.height,type:"full",location:null,size:t.size}],w:s.width,h:s.height},Object(d.c)(y,["downloaded","url"]),y.downloaded=t.size,y.url=s.objectURL||"",k.a.savePhoto(y);else if(0===h.indexOf("video/")){l="video",c="video.mp4",M="sendMessageUploadVideoAction";let e={_:"documentAttributeVideo",pFlags:{round_message:s.isRoundMessage},duration:s.duration,w:s.width,h:s.height};X.push(e)}else l="document",c="document."+h.split("/")[1],M="sendMessageUploadDocumentAction";else l="document",c="document."+h.split("/")[1],M="sendMessageUploadDocumentAction";if(X.push({_:"documentAttributeFilename",file_name:u||c}),-1!==["document","video","audio","voice"].indexOf(l)&&!p){const e=[];if(C={_:"document",id:""+a.id,duration:s.duration,attributes:X,w:s.width,h:s.height,thumbs:e,mime_type:h,size:t.size},Object(d.c)(C,["downloaded","url"]),C.downloaded=t.size,C.url=s.objectURL||"",b)X.push({_:"documentAttributeImageSize",w:s.width,h:s.height}),e.push({_:"photoSize",w:s.width,h:s.height,type:"full",location:null,size:t.size,url:s.objectURL});else if("video"===l){s.thumbURL&&e.push({_:"photoSize",w:s.width,h:s.height,type:"full",location:null,size:s.thumbBlob.size,url:s.thumbURL});const t=e[0],a=k.a.getDocumentCachedThumb(C.id);a.downloaded=t.size,a.url=t.url}I.a.saveDoc(C)}this.log("sendFile",l,c,t.type,s);const A=p?void 0:new i.a({attachMethod:"prepend",tryAgainOnFail:!1,isUpload:!0}),D=Object(n.a)();A&&(A.attachPromise(D),D.cancel=()=>{const e=new Error("Download canceled");e.name="AbortError",D.reject(e)},D.catch(t=>{"AbortError"!==t.name||j||(this.log("cancelling upload",F),D.reject(t),this.cancelPendingMessage(a.random_id),this.setTyping(e,"sendMessageCancelAction"),(null==x?void 0:x.cancel)&&x.cancel())}));const F=p?void 0:{_:y?"messageMediaPhoto":"messageMediaDocument",pFlags:{},preloader:A,photo:y,document:C,promise:D};a.entities=v,a.message=m,a.media=p?{_:"messageMediaDocument",pFlags:{},document:t}:F;const T=e=>{e?a.error=!0:delete a.error,_.default.broadcast("messages_pending")};let j=!1,x=null;return a.send=()=>{if(p){const{id:e,access_hash:s,file_reference:a}=t,i={_:"inputMediaDocument",id:{_:"inputDocument",id:e,access_hash:s,file_reference:a}};D.resolve(i)}else if(t instanceof File||t instanceof Blob){const i=()=>{let i;return j&&!a.error||(j=!1,x=w.a.upload(t),D.notifyAll({done:0,total:t.size})),"video"===l&&s.objectURL&&(i=new Promise((e,t)=>{(s.thumbBlob?Promise.resolve(s.thumbBlob):Object(r.a)(s.objectURL)).then(s=>{s?w.a.upload(s).then(e,t):e(null)},t)})),x&&x.then(e=>H(this,void 0,void 0,(function*(){let t;switch(delete a.media.preloader,e.name=c,j=!0,l){case"photo":t={_:"inputMediaUploadedPhoto",file:e};break;default:t={_:"inputMediaUploadedDocument",file:e,mime_type:h,attributes:X}}if(i)try{const e=yield i;t.thumb=e}catch(e){this.log.error("sendFile thumb upload error:",e)}D.resolve(t)})),()=>{T(!0)}),x.addNotifyListener(t=>{const s=Math.max(1,Math.floor(100*t.done/t.total));this.setTyping(e,{_:M,progress:0|s}),D.notifyAll(t)}),D};s.isGroupedItem?i():this.sendSmthLazyLoadQueue.push({load:i})}return D},this.beforeMessageSending(a,{isGroupedItem:s.isGroupedItem,isScheduled:!!s.scheduleDate||void 0,threadId:s.threadId,clearDraft:s.clearDraft}),s.isGroupedItem||D.then(t=>(this.setTyping(e,"sendMessageCancelAction"),g.a.invokeApi("messages.sendMedia",{background:s.background,peer:S.a.getInputPeerById(e),media:t,message:m,random_id:a.random_id,reply_to_msg_id:o,schedule_date:s.scheduleDate,silent:s.silent,entities:v,clear_draft:s.clearDraft}).then(e=>{P.a.processUpdateMessage(e)},e=>{if("photo"===l&&400===e.code&&("PHOTO_INVALID_DIMENSIONS"===e.type||"PHOTO_SAVE_FILE_INVALID"===e.type))return e.handled=!0,l="document",void a.send();T(!0)}))),{message:a,promise:D}}sendAlbum(e,t,s={}){return H(this,void 0,void 0,(function*(){if(s.threadId&&!s.replyToMsgId&&(s.replyToMsgId=s.threadId),1===t.length)return this.sendFile(e,t[0],Object.assign(Object.assign({},s),s.sendFileDetails[0]));e=S.a.getPeerMigratedTo(e)||e;const a=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0;let i=s.caption||"",n=s.entities||[];i&&(i=f.a.parseMarkdown(i,n)),this.log("sendAlbum",t,s);const o=""+ ++this.groupedTempId,r=t.map((t,r)=>{const d=s.sendFileDetails[r],l=Object.assign({isGroupedItem:!0,isMedia:s.isMedia,scheduleDate:s.scheduleDate,silent:s.silent,replyToMsgId:a,threadId:s.threadId,groupId:o},d);return 0===r&&(l.caption=i,l.entities=n),this.sendFile(e,t,l).message});s.threadId?j.a.syncDraft(e,s.threadId):j.a.saveDraft(e,s.threadId,null,{notify:!0});const d=(e,t)=>{t?e.error=!0:delete e.error,_.default.broadcast("messages_pending")},l=S.a.getInputPeerById(e),c=t=>{this.setTyping(e,"sendMessageCancelAction"),this.sendSmthLazyLoadQueue.push({load:()=>g.a.invokeApi("messages.sendMultiMedia",{peer:l,multi_media:t,reply_to_msg_id:a,schedule_date:s.scheduleDate,silent:s.silent,clear_draft:s.clearDraft}).then(e=>{P.a.processUpdateMessage(e)},e=>{r.forEach(e=>d(e,!0))})})},h=r.map((e,t)=>e.send().then(e=>g.a.invokeApi("messages.uploadMedia",{peer:l,media:e})).then(t=>{let s;if("messageMediaPhoto"===t._){const e=k.a.savePhoto(t.photo);s=k.a.getInput(e)}else if("messageMediaDocument"===t._){const e=I.a.saveDoc(t.document);s=I.a.getMediaInput(e)}const a={_:"inputSingleMedia",media:s,random_id:e.random_id,message:i,entities:n};return i&&(i="",n=[]),a}).catch(t=>{if("AbortError"===t.name)return null;throw this.log.error("sendAlbum upload item error:",t,e),d(e,!0),t}));Promise.all(h).then(e=>{c(e.filter(Boolean))})}))}sendOther(e,t,s={}){e=S.a.getPeerMigratedTo(e)||e;const a=this.generateOutgoingMessage(e,s),i=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0;let n;switch(t._){case"inputMediaPoll":{t.poll.id=a.id,A.a.savePoll(t.poll,{_:"pollResults",flags:4,total_voters:0,pFlags:{}});const{poll:e,results:s}=A.a.getPoll(""+a.id);n={_:"messageMediaPoll",poll:e,results:s};break}}a.media=n;a.send=()=>{const n={};let o;this.pendingAfterMsgs[e]&&(n.afterMessageId=this.pendingAfterMsgs[e].messageId),o=s.viaBotId?g.a.invokeApiAfter("messages.sendInlineBotResult",{peer:S.a.getInputPeerById(e),random_id:a.random_id,reply_to_msg_id:i||void 0,query_id:s.queryId,id:s.resultId,clear_draft:s.clearDraft},n):g.a.invokeApiAfter("messages.sendMedia",{peer:S.a.getInputPeerById(e),media:t,random_id:a.random_id,reply_to_msg_id:i||void 0,message:"",clear_draft:s.clearDraft,schedule_date:s.scheduleDate,silent:s.silent},n),o.then(e=>{e.updates&&e.updates.forEach(e=>{"updateDraftMessage"===e._&&(e.local=!0)}),P.a.processUpdateMessage(e)},e=>{_.default.broadcast("messages_pending")}).finally(()=>{this.pendingAfterMsgs[e]===n&&delete this.pendingAfterMsgs[e]}),this.pendingAfterMsgs[e]=n},this.beforeMessageSending(a,{isScheduled:!!s.scheduleDate||void 0,threadId:s.threadId,clearDraft:s.clearDraft})}beforeMessageSending(e,t={}){const s=e.id,a=this.getMessagePeer(e),i=t.isScheduled?this.getScheduledMessagesStorage(a):this.getMessagesStorage(a);if(t.isScheduled)this.saveMessages([e],{storage:i,isScheduled:!0,isOutgoing:!0}),setTimeout(()=>{_.default.broadcast("scheduled_new",{peerId:a,mid:s})},0);else{if(t.threadId){this.getHistoryStorage(a,t.threadId).history.unshift(s)}this.getHistoryStorage(a).history.unshift(s),this.saveMessages([e],{storage:i,isOutgoing:!0}),setTimeout(()=>{this.setDialogTopMessage(e),_.default.broadcast("history_append",{storage:i,peerId:a,mid:s})},0)}!t.isGroupedItem&&t.clearDraft&&(t.threadId?j.a.syncDraft(a,t.threadId):j.a.saveDraft(a,t.threadId,null,{notify:!0})),this.pendingByRandomId[e.random_id]={peerId:a,tempId:s,threadId:t.threadId,storage:i},!t.isGroupedItem&&e.send&&setTimeout(e.send,0)}generateOutgoingMessage(e,t){t.threadId&&!t.replyToMsgId&&(t.replyToMsgId=t.threadId);return{_:"message",id:this.generateTempMessageId(e),from_id:this.generateFromId(e),peer_id:S.a.getOutputPeer(e),pFlags:this.generateFlags(e),date:t.scheduleDate||Object(o.g)(!0)+m.a.serverTimeOffset,message:"",grouped_id:t.groupId,random_id:Object(l.b)(),reply_to:this.generateReplyHeader(t.replyToMsgId,t.threadId),via_bot_id:t.viaBotId,reply_markup:t.reply_markup,replies:this.generateReplies(e),views:S.a.isBroadcast(e)&&1,pending:!0}}generateReplyHeader(e,t){const s={_:"messageReplyHeader",reply_to_msg_id:e||t};return t&&s.reply_to_msg_id!==t&&(s.reply_to_top_id=t),s}generateReplies(e){let t;if(S.a.isBroadcast(e)){const s=U.default.chatsFull[-e];(null==s?void 0:s.linked_chat_id)&&(t={_:"messageReplies",flags:1,pFlags:{comments:!0},channel_id:s.linked_chat_id,replies:0,replies_pts:0})}return t}generateFromId(e){var t,s;return e<0&&(S.a.isBroadcast(e)||(null===(s=null===(t=S.a.getPeer(e).admin_rights)||void 0===t?void 0:t.pFlags)||void 0===s?void 0:s.anonymous))?void 0:S.a.getOutputPeer(F.a.getSelf().id)}generateFlags(e){const t={};return e!==F.a.getSelf().id&&(t.out=!0,S.a.isChannel(e)||F.a.isBot(e)||(t.unread=!0)),S.a.isBroadcast(e)&&(t.post=!0),t}generateForwardHeader(e,t){const s=F.a.getSelf().id;if(t.fromId===s&&t.peerId===s&&!t.fwd_from)return;const a={_:"messageFwdHeader",flags:0,date:t.date};return t.fwd_from?(a.from_id=t.fwd_from.from_id,a.from_name=t.fwd_from.from_name,a.post_author=t.fwd_from.post_author):(a.from_id=S.a.getOutputPeer(t.fromId),a.post_author=t.post_author),S.a.isBroadcast(t.peerId)&&(t.post_author&&(a.post_author=t.post_author),a.channel_post=t.id),e===s&&(a.saved_from_msg_id=t.id,a.saved_from_peer=S.a.getOutputPeer(t.peerId)),a}generateFakeAvatarMessage(e,t){const s=Number.MAX_SAFE_INTEGER,a={_:"messageService",action:{_:"messageActionChannelEditPhoto",photo:t},mid:s,peerId:e,date:t.date,fromId:e};return this.getMessagesStorage(e)[s]=a,a}setDialogTopMessage(e,t=this.getDialogByPeerId(e.peerId)[0]){if(t){t.top_message=e.mid;this.getHistoryStorage(e.peerId).maxId=e.mid,this.dialogsStorage.generateIndexForDialog(t,!1,e),this.newDialogsToHandle[e.peerId]=t,this.scheduleHandleNewDialogs()}}cancelPendingMessage(e){const t=this.pendingByRandomId[e];if(t){const{peerId:s,tempId:a,storage:i}=t,n=this.getHistoryStorage(s).history.findSlice(a);return P.a.processUpdateMessage({_:"updateShort",update:{_:"updateDeleteMessages",messages:[a]}}),n&&n.slice.splice(n.index,1),delete this.pendingByRandomId[e],delete i[a],!0}return!1}refreshConversations(){return H(this,void 0,void 0,(function*(){const e=[];for(let t=0;t<2;++t){let s=0;for(;;){const{dialogs:a}=yield z.getTopMessages(100,t,s);if(!a.length)break;{e.push(...a);const t=a[a.length-1],i=S.a.getPeerId(t.peer),n=this.generateMessageId(t.top_message);if(s=this.getMessageByPeer(i,n).date,!s){console.error("refreshConversations: got no offsetDate",t);break}}}}let t={};return e.forEach(e=>{t[e.peerId]=e}),_.default.broadcast("dialogs_multiupdate",t),e}))}getConversationsAll(e="",t=0){return H(this,void 0,void 0,(function*(){const s=[];for(;t<2;++t){let a=0;for(;;){const{dialogs:i}=yield z.getConversations(e,a,100,t);if(!i.length)break;s.push(...i),a=i[i.length-1].index||0}}return s}))}getConversations(e="",t,s=20,a=0){const i=a>1?0:a;let n=this.dialogsStorage.getFolder(a);if(e){if(!s||this.cachedResults.query!==e||this.cachedResults.folderId!==a){this.cachedResults.query=e,this.cachedResults.folderId=a;const t=v.a.search(e,this.dialogsStorage.dialogsIndex);this.cachedResults.dialogs=[];for(const e in this.dialogsStorage.dialogs){const s=this.dialogsStorage.dialogs[e];t[s.peerId]&&s.folder_id===a&&this.cachedResults.dialogs.push(s)}this.cachedResults.dialogs.sort((e,t)=>t.index-e.index),this.cachedResults.count=this.cachedResults.dialogs.length}n=this.cachedResults.dialogs}else this.cachedResults.query="";let o=0;if(t>0)for(;o<n.length&&!(t>n[o].index);o++);return e||this.dialogsStorage.allDialogsLoaded[i]||n.length>=o+s?Promise.resolve({dialogs:n.slice(o,o+s),count:this.dialogsStorage.allDialogsLoaded[i]?n.length:null,isEnd:this.dialogsStorage.allDialogsLoaded[i]&&o+s>=n.length}):this.getTopMessages(s,i).then(e=>{if(o=0,t>0)for(;o<n.length&&!(t>n[o].index);o++);return{dialogs:n.slice(o,o+s),count:"messages.dialogs"===e._?e.dialogs.length:e.count,isEnd:this.dialogsStorage.allDialogsLoaded[i]&&o+s>=n.length}})}getReadMaxIdIfUnread(e,t){const s=this.getHistoryStorage(e,t);if(t){const t=this.getHistoryStorage(e),a=Math.max(t.readMaxId,s.readMaxId);return!this.getMessageByPeer(e,s.maxId).pFlags.out&&a<s.maxId?a:0}{const t=this.getMessageByPeer(e,s.maxId),a=e>0?Math.max(s.readMaxId,s.readOutboxMaxId):s.readMaxId;return!t.pFlags.out&&a<s.maxId?a:0}}getTopMessages(e,t,s){const a=this.dialogsStorage.getFolder(t);let i=0;return void 0===s&&(s=this.dialogsStorage.getOffsetDate(t)),s&&(i=65536*s,s+=m.a.serverTimeOffset),g.a.invokeApi("messages.getDialogs",{folder_id:t,offset_date:s,offset_id:0,offset_peer:S.a.getInputPeerById(0),limit:e,hash:0},{noErrorBox:!0}).then(e=>{if("messages.dialogsNotModified"===e._)return null;O.b&&this.log("messages.getDialogs result:",e.dialogs,Object.assign({},e.dialogs[0])),F.a.saveApiUsers(e.users),M.a.saveApiChats(e.chats),this.saveMessages(e.messages);let n=!!s,o=!1;const r={};Object(X.c)(e.dialogs,e=>{var s;this.saveConversation(e,null!==(s=e.folder_id)&&void 0!==s?s:t),void 0!==e.peerId&&(i&&e.index>i&&(this.newDialogsToHandle[e.peerId]=e,o=!0),this.getServerMessageId(e.read_inbox_max_id)||this.getServerMessageId(e.read_outbox_max_id)||(r[e.peerId]=e,this.log.error("noIdsDialogs",e)),n||S.a.isChannel(S.a.getPeerId(e.peer))||(this.incrementMaxSeenId(e.top_message),n=!0))}),Object.keys(r).length&&this.reloadConversation(Object.keys(r).map(e=>+e)).then(()=>{_.default.broadcast("dialogs_multiupdate",r);for(let e in r)_.default.broadcast("dialog_unread",{peerId:+e})});const d=e.count;return(!e.dialogs.length||!d||a.length>=d)&&(this.dialogsStorage.allDialogsLoaded[t]=!0),o?this.scheduleHandleNewDialogs():_.default.broadcast("dialogs_multiupdate",{}),e})}forwardMessages(e,t,s,a={}){e=S.a.getPeerMigratedTo(e)||e,s=s.slice().sort((e,t)=>e-t);const i={},n=s.map(s=>{var n,o;const r=this.getMessageByPeer(t,s),d=this.generateOutgoingMessage(e,a);d.fwd_from=this.generateForwardHeader(e,r),["entities","forwards","message","media","reply_markup","views"].forEach(e=>{d[e]=r[e]});const l=null===(n=d.media)||void 0===n?void 0:n.document;if(l){["round","voice"].includes(l.type)&&(d.pFlags.media_unread=!0)}if(r.grouped_id){(null!==(o=i[r.grouped_id])&&void 0!==o?o:i[r.grouped_id]={tempId:""+ ++this.groupedTempId,messages:[]}).messages.push(d)}return d});for(const e in i){const t=i[e];t.messages.length>1&&t.messages.forEach(e=>{e.grouped_id=t.tempId})}n.forEach(e=>{this.beforeMessageSending(e,{isScheduled:!!a.scheduleDate||void 0})});const o={};this.pendingAfterMsgs[e]&&(o.afterMessageId=this.pendingAfterMsgs[e].messageId);const r=g.a.invokeApiAfter("messages.forwardMessages",{from_peer:S.a.getInputPeerById(t),id:s.map(e=>this.getServerMessageId(e)),random_id:n.map(e=>e.random_id),to_peer:S.a.getInputPeerById(e),with_my_score:a.withMyScore,silent:a.silent,schedule_date:a.scheduleDate},o).then(e=>{this.log("forwardMessages updates:",e),P.a.processUpdateMessage(e)}).finally(()=>{this.pendingAfterMsgs[e]===o&&delete this.pendingAfterMsgs[e]});return this.pendingAfterMsgs[e]=o,r}getMessageFromStorage(e,t){return e&&e[t]||{_:"messageEmpty",id:t,deleted:!0,pFlags:{}}}createMessageStorage(){return{}}getMessagesStorage(e){var t;return null!==(t=this.messagesStorageByPeerId[e])&&void 0!==t?t:this.messagesStorageByPeerId[e]=this.createMessageStorage()}getMessageById(e){for(const t in this.messagesStorageByPeerId){if(S.a.isChannel(+t))continue;const s=this.messagesStorageByPeerId[t][e];if(s)return s}return this.getMessageFromStorage(null,e)}getMessageByPeer(e,t){return e?this.getMessageFromStorage(this.getMessagesStorage(e),t):this.getMessageById(t)}getMessagePeer(e){return e.peer_id&&S.a.getPeerId(e.peer_id)||0}getDialogByPeerId(e){return this.dialogsStorage.getDialog(e)}reloadConversation(e){return[].concat(e).forEach(e=>{this.reloadConversationsPeers.includes(e)||this.reloadConversationsPeers.push(e)}),this.reloadConversationsPromise?this.reloadConversationsPromise:this.reloadConversationsPromise=new Promise((e,t)=>{setTimeout(()=>{const s=this.reloadConversationsPeers.map(e=>S.a.getInputDialogPeerById(e));this.reloadConversationsPeers.length=0,g.a.invokeApi("messages.getPeerDialogs",{peers:s}).then(t=>{this.applyConversations(t),e()},t).finally(()=>{this.reloadConversationsPromise=null})},0)})}doFlushHistory(e,t,s){return g.a.invokeApi("messages.deleteHistory",{just_clear:t,revoke:s,peer:e,max_id:0}).then(s=>(P.a.processUpdateMessage({_:"updateShort",update:{_:"updatePts",pts:s.pts,pts_count:s.pts_count}}),!s.offset||this.doFlushHistory(e,t)))}flushHistory(e,t,s){return H(this,void 0,void 0,(function*(){if(S.a.isChannel(e)){const t=this.getHistory(e,0,1),s=t instanceof Promise?yield t:t,a=-e,i=s.history[0]||0;return g.a.invokeApi("channels.deleteHistory",{channel:M.a.getChannelInput(a),max_id:i}).then(()=>(P.a.processUpdateMessage({_:"updateShort",update:{_:"updateChannelAvailableMessages",channel_id:a,available_min_id:i}}),!0))}return this.doFlushHistory(S.a.getInputPeerById(e),t,s).then(()=>{delete this.historiesStorage[e],delete this.messagesStorageByPeerId[e],t?_.default.broadcast("dialog_flush",{peerId:e}):(this.dialogsStorage.dropDialog(e),_.default.broadcast("dialog_drop",{peerId:e}))})}))}hidePinnedMessages(e){return Promise.all([D.default.getState(),this.getPinnedMessage(e)]).then(([t,s])=>{t.hiddenPinnedMessages[e]=s.maxId,_.default.broadcast("peer_pinned_hidden",{peerId:e,maxId:s.maxId})})}getPinnedMessage(e){var t;const s=null!==(t=this.pinnedMessages[e])&&void 0!==t?t:this.pinnedMessages[e]={};return s.promise?s.promise:s.maxId?Promise.resolve(s):s.promise=this.getSearch({peerId:e,inputFilter:{_:"inputMessagesFilterPinned"},maxId:0,limit:1}).then(e=>{var t;return s.count=e.count,s.maxId=null===(t=e.history[0])||void 0===t?void 0:t.mid,s}).finally(()=>{delete s.promise})}updatePinnedMessage(e,t,s,a,i){return g.a.invokeApi("messages.updatePinnedMessage",{peer:S.a.getInputPeerById(e),unpin:s,silent:a,pm_oneside:i,id:this.getServerMessageId(t)}).then(e=>{P.a.processUpdateMessage(e)})}unpinAllMessages(e){return g.a.invokeApi("messages.unpinAllMessages",{peer:S.a.getInputPeerById(e)}).then(t=>{if(P.a.processUpdateMessage({_:"updateShort",update:{_:"updatePts",pts:t.pts,pts_count:t.pts_count}}),!t.offset){const t=this.getMessagesStorage(e);for(const e in t){const s=t[e];s.pFlags.pinned&&delete s.pFlags.pinned}return _.default.broadcast("peer_pinned_messages",{peerId:e,unpinAll:!0}),delete this.pinnedMessages[e],!0}return this.unpinAllMessages(e)})}getAlbumText(e){const t=this.groupedMessagesStorage[e];let s,a,i,n=0;for(const e in t){const o=t[e];if(o.message){if(++n>1)break;s=o.message,a=o.totalEntities,i=o.entities}}return n>1&&(s=void 0,a=void 0,i=void 0),{message:s,entities:i,totalEntities:a}}getMidsByAlbum(e){return Object(d.e)(this.groupedMessagesStorage[e],"asc")}getMidsByMessage(e){return(null==e?void 0:e.grouped_id)?this.getMidsByAlbum(e.grouped_id):[e.mid]}filterMessages(e,t){const s=[];if(e.grouped_id){const a=this.groupedMessagesStorage[e.grouped_id];for(const e in a){const i=a[e];t(i)&&s.push(i)}}else t(e)&&s.push(e);return s}generateTempMessageId(e){const t=this.getDialogByPeerId(e)[0];return this.generateMessageId((null==t?void 0:t.top_message)||0,!0)}generateMessageId(e,t=!1){const s=W.MESSAGE_ID_OFFSET,a=t?++this.tempNum:0;return e>=s?t?e+(a&W.MESSAGE_ID_INCREMENT-1):e:s+(e*W.MESSAGE_ID_INCREMENT+(a&W.MESSAGE_ID_INCREMENT-1))}getServerMessageId(e){const t=W.MESSAGE_ID_OFFSET;if(e<t)return e;const s=W.MESSAGE_ID_INCREMENT-1,a=e&s;return a!==s&&(e-=a+1),(e-t)/W.MESSAGE_ID_INCREMENT}incrementMessageId(e,t){return this.generateMessageId(this.getServerMessageId(e)+t)}saveMessages(e,t={}){e.forEach(e=>{var s;if(void 0===e.pFlags&&(e.pFlags={}),"messageEmpty"===e._)return;const a=this.getMessagePeer(e),i=t.storage||this.getMessagesStorage(a),n="peerChannel"===e.peer_id._,o=n?-a:0,r=n&&M.a.isBroadcast(o);t.isScheduled&&(e.pFlags.is_scheduled=!0),t.isOutgoing&&(e.pFlags.is_outgoing=!0);const d=this.generateMessageId(e.id);if(e.mid=d,e.grouped_id){(null!==(s=this.groupedMessagesStorage[e.grouped_id])&&void 0!==s?s:this.groupedMessagesStorage[e.grouped_id]={})[d]=e}const l=this.getDialogByPeerId(a)[0];l&&d&&d>l[e.pFlags.out?"read_outbox_max_id":"read_inbox_max_id"]&&(e.pFlags.unread=!0),e.reply_to&&(e.reply_to.reply_to_msg_id&&(e.reply_to.reply_to_msg_id=e.reply_to_mid=this.generateMessageId(e.reply_to.reply_to_msg_id)),e.reply_to.reply_to_top_id&&(e.reply_to.reply_to_top_id=this.generateMessageId(e.reply_to.reply_to_top_id))),e.replies&&(e.replies.max_id&&(e.replies.max_id=this.generateMessageId(e.replies.max_id)),e.replies.read_max_id&&(e.replies.read_max_id=this.generateMessageId(e.replies.read_max_id)));const c=!!e.peerId;c||(e.date-=m.a.serverTimeOffset);const h=F.a.getSelf().id;e.peerId=a,e.peerId===h?e.fromId=e.fwd_from?e.fwd_from.from_id?S.a.getPeerId(e.fwd_from.from_id):0:h:e.fromId=e.pFlags.post||!e.from_id?a:S.a.getPeerId(e.from_id);const u=e.fwd_from;if(u){u.saved_from_msg_id&&(u.saved_from_msg_id=this.generateMessageId(u.saved_from_msg_id)),u.channel_post&&(u.channel_post=this.generateMessageId(u.channel_post));const t=u.saved_from_peer||u.from_id,s=u.saved_from_msg_id||u.channel_post;if(t&&s){const a=S.a.getPeerId(t),i=this.generateMessageId(s);e.savedFrom=a+"_"+i}e.fwdFromId=S.a.getPeerId(u.from_id),c||(u.date-=m.a.serverTimeOffset)}e.via_bot_id>0&&(e.viaBotId=e.via_bot_id);const g={type:"message",peerId:a,messageId:d};if(e.media)switch(e.media._){case"messageMediaEmpty":delete e.media;break;case"messageMediaPhoto":e.media.ttl_seconds?e.media={_:"messageMediaUnsupportedWeb"}:e.media.photo=k.a.savePhoto(e.media.photo,g),e.media.photo||delete e.media;break;case"messageMediaPoll":e.media.poll=A.a.savePoll(e.media.poll,e.media.results);break;case"messageMediaDocument":e.media.ttl_seconds?e.media={_:"messageMediaUnsupportedWeb"}:e.media.document=I.a.saveDoc(e.media.document,g);break;case"messageMediaWebPage":e.media.webpage=T.a.saveWebPage(e.media.webpage,e.mid,g);break;case"messageMediaInvoice":e.media={_:"messageMediaUnsupportedWeb"}}if(e.action){let t,s;switch(e.action._){case"messageActionChatEditPhoto":e.action.photo=k.a.savePhoto(e.action.photo,g),e.action.photo.video_sizes?e.action._=r?"messageActionChannelEditVideo":"messageActionChatEditVideo":r&&(e.action._="messageActionChannelEditPhoto");break;case"messageActionChatEditTitle":r&&(e.action._="messageActionChannelEditTitle");break;case"messageActionChatDeletePhoto":r&&(e.action._="messageActionChannelDeletePhoto");break;case"messageActionChatAddUser":if(1===e.action.users.length){if(e.action.user_id=e.action.users[0],e.fromId===e.action.user_id){let t=e.fromId===F.a.getSelf().id?"You":"";e.action._=n?"messageActionChatJoined"+t:"messageActionChatReturn"+t}}else e.action.users.length>1&&(e.action._="messageActionChatAddUsers");break;case"messageActionChatDeleteUser":e.fromId===e.action.user_id&&(e.action._="messageActionChatLeave");break;case"messageActionChannelMigrateFrom":t=-e.action.chat_id,s=-o;break;case"messageActionChatMigrateTo":t=-o,s=-e.action.channel_id;break;case"messageActionHistoryClear":e.clear_history=!0,delete e.pFlags.out,delete e.pFlags.unread;break;case"messageActionPhoneCall":delete e.fromId,e.action.type=(e.pFlags.out?"out_":"in_")+("phoneCallDiscardReasonMissed"===e.action.reason._||"phoneCallDiscardReasonBusy"===e.action.reason._?"missed":"ok")}t&&s&&!this.migratedFromTo[t]&&!this.migratedToFrom[s]&&this.migrateChecks(t,s)}if(e.message&&e.message.length&&!e.totalEntities){const t=f.a.parseEntities(e.message),s=e.entities||[];e.totalEntities=f.a.mergeEntities(s,t)}i[d]=e})}wrapMessageForReply(e,t=e.message,s,a,i){const n=[],o=(e,t,s)=>{if(e&&(t=a?h.default.format(e,!0):Object(h.i18n)(e)),a)n.push(t);else{const e=document.createElement("i");"string"==typeof t?e.innerHTML=t:e.append(t),n.push(e)}s&&n.push(", ")};if(e.media){let i=!0;if(e.grouped_id){if(s){const t=this.getMidsByMessage(e);if(s.length===t.length){for(const e of t)if(!s.includes(e)){i=!1;break}}else i=!1}i&&o("AttachAlbum",void 0,t=this.getAlbumText(e.grouped_id).message)}else i=!1;if(!i){const s=e.media;switch(s._){case"messageMediaPhoto":o("AttachPhoto",void 0,e.message);break;case"messageMediaDice":o(void 0,a?s.emoticon:f.a.wrapEmojiText(s.emoticon));break;case"messageMediaVenue":{const e=a?s.title:f.a.wrapEmojiText(s.title);o("AttachLocation",void 0,e),n.push(Object(N.p)(e));break}case"messageMediaGeo":o("AttachLocation");break;case"messageMediaGeoLive":o("AttachLiveLocation");break;case"messageMediaPoll":o(void 0,a?"📊 "+(s.poll.question||"poll"):s.poll.rReply);break;case"messageMediaContact":o("AttachContact");break;case"messageMediaGame":{const e="🎮 ";o(void 0,a?e+s.game.title:f.a.wrapEmojiText(e+s.game.title));break}case"messageMediaDocument":let i=s.document;"video"===i.type?o("AttachVideo",void 0,e.message):"voice"===i.type?o("AttachAudio",void 0,e.message):"gif"===i.type?o("AttachGif",void 0,e.message):"round"===i.type?o("AttachRound",void 0,e.message):"sticker"===i.type?(o(void 0,((a?i.stickerEmojiRaw:i.stickerEmoji)||"")+"Sticker"),t=""):o(i.file_name,void 0,e.message)}}}if(e.action){const t=this.wrapMessageActionTextNew(e,a);t&&o(void 0,t)}if(t)if(t=Object(c.g)(t,100),a)n.push(t);else{let e=f.a.parseEntities(t.replace(/\n/g," "));if(i){e||(e=[]);let s,a=!1,n=new RegExp(Object(c.f)(i),"gi");for(;null!==(s=n.exec(t));)e.push({_:"messageEntityHighlight",length:i.length,offset:s.index}),a=!0;a&&e.sort((e,t)=>e.offset-t.offset)}const s=f.a.wrapRichText(t,{noLinebreaks:!0,entities:e,noLinks:!0,noTextFormat:!0});n.push(Object(N.p)(s))}if(a)return n.join("");{const e=document.createDocumentFragment();return e.append(...n),e}}getSenderToPeerText(e){let t,s="";return s=e.pFlags.out?"You":S.a.getPeerTitle(e.fromId,!1,!1),t=S.a.isAnyGroup(e.peerId)||e.pFlags.out&&e.peerId!==_.default.myId?S.a.getPeerTitle(e.peerId,!1,!1):"",t&&(s+=" ➝ "+t),s}wrapMessageActionTextNew(e,t){const s=t?void 0:document.createElement("span"),a=e.action;if(a.message)return t?f.a.wrapPlainText(e.message):(s.innerHTML=f.a.wrapRichText(a.message,{noLinebreaks:!0}),s);{let i,n,o=a._;const r=(e,t)=>t?S.a.getPeerTitle(e,t)+" ":new B.a({peerId:e}).element;switch(a._){case"messageActionPhoneCall":{o+="."+a.type;const e=a.duration||1,t=[];t.push(e%60+" s"),e>=60&&t.push((e/60|0)+" min"),i=h.langPack[o],n=[t.reverse().join(" ")];break}case"messageActionPinMessage":case"messageActionContactSignUp":case"messageActionChatReturn":case"messageActionChatLeave":case"messageActionChatJoined":case"messageActionChatCreate":case"messageActionChatEditPhoto":case"messageActionChatDeletePhoto":case"messageActionChatEditVideo":case"messageActionChatJoinedByLink":case"messageActionChannelEditVideo":case"messageActionChannelDeletePhoto":i=h.langPack[o],n=[r(e.fromId,t)];break;case"messageActionChannelEditTitle":case"messageActionChatEditTitle":i=h.langPack[o],n=[],"messageActionChatEditTitle"===a._&&n.push(r(e.fromId,t)),n.push(t?a.title:Object(N.q)(f.a.wrapEmojiText(a.title)));break;case"messageActionChatDeleteUser":case"messageActionChatAddUsers":case"messageActionChatAddUser":{const s=a.users||[a.user_id];if(i=h.langPack[o],n=[r(e.fromId,t)],s.length>1)if(t)n.push(...s.map(e=>r(e,!0).trim()).join(", "));else{const e=document.createElement("span");e.append(...Object(h.join)(s.map(e=>r(e,!1)),!1)),n.push(e)}else n.push(r(s[0],t));break}case"messageActionBotAllowed":{const e=f.a.wrapRichText(a.domain,{entities:[{_:"messageEntityUrl",length:a.domain.length,offset:0}]}),t=Object(N.q)(e);i=h.langPack[o],n=[t];break}default:i=h.langPack[o]||`[${a._}]`}return i||(i=h.langPack[o],void 0===i&&(i="["+o+"]")),t?h.default.format(i,!0,n):Object(h._i18n)(s,i,n)}}editPeerFolders(e,t){g.a.invokeApi("folders.editPeerFolders",{folder_peers:e.map(e=>({_:"inputFolderPeer",peer:S.a.getInputPeerById(e),folder_id:t}))}).then(e=>{P.a.processUpdateMessage(e)})}toggleDialogPin(e,t){var s;if(t>1)return void this.filtersStorage.toggleDialogPin(e,t);const a=this.getDialogByPeerId(e)[0];if(!a)return Promise.reject();const i=!(null===(s=a.pFlags)||void 0===s?void 0:s.pinned)||void 0;return g.a.invokeApi("messages.toggleDialogPin",{peer:S.a.getInputDialogPeerById(e),pinned:i}).then(s=>{if(s){const s=i?{pinned:i}:{};this.onUpdateDialogPinned({_:"updateDialogPinned",peer:S.a.getDialogPeer(e),folder_id:t,pFlags:s})}})}markDialogUnread(e,t){var s;const a=this.getDialogByPeerId(e)[0];if(!a)return Promise.reject();const i=!t&&!(null===(s=a.pFlags)||void 0===s?void 0:s.unread_mark)||void 0;return g.a.invokeApi("messages.markDialogUnread",{peer:S.a.getInputDialogPeerById(e),unread:i}).then(t=>{if(t){const t=i?{unread:i}:{};this.onUpdateDialogUnreadMark({_:"updateDialogUnreadMark",peer:S.a.getDialogPeer(e),pFlags:t})}})}migrateChecks(e,t){if(!this.migratedFromTo[e]&&!this.migratedToFrom[t]&&M.a.hasChat(-t)){const s=M.a.getChat(-e);if(s&&s.migrated_to&&s.migrated_to.channel_id===-t){this.migratedFromTo[e]=t,this.migratedToFrom[t]=e,_.default.broadcast("dialog_migrate",{migrateFrom:e,migrateTo:t});const s=this.dialogsStorage.dropDialog(e);s.length&&_.default.broadcast("dialog_drop",{peerId:e,dialog:s[0]})}}}canMessageBeEdited(e,t){if(e.pFlags.is_outgoing)return!1;const s=["messageMediaPhoto","messageMediaDocument","messageMediaWebPage"];return"poll"===t&&s.push("messageMediaPoll"),!("message"!==e._||e.deleted||e.fwd_from||e.via_bot_id||e.media&&-1===s.indexOf(e.media._)||e.fromId&&F.a.isBot(e.fromId))&&(!e.media||"messageMediaDocument"!==e.media._||!e.media.document.sticker&&"round"!==e.media.document.type)}canEditMessage(e,t="text"){var s;return!(!e||!this.canMessageBeEdited(e,t))&&(!(!e.pFlags.out&&this.getMessagePeer(e)!==F.a.getSelf().id)||!(e.date<Object(o.g)(!0)-172800&&"messageMediaPoll"!==(null===(s=e.media)||void 0===s?void 0:s._)||!e.pFlags.out))}canDeleteMessage(e){return e&&(e.peerId>0||e.fromId===_.default.myId||"chat"===M.a.getChat(e.peerId)._||M.a.hasRights(e.peerId,"delete_messages"))&&!e.pFlags.is_outgoing}applyConversations(e){Object(X.c)(e.dialogs,(t,s)=>{"dialogFolder"===t._&&e.dialogs.splice(s,1)}),F.a.saveApiUsers(e.users),M.a.saveApiChats(e.chats),this.saveMessages(e.messages),this.log("applyConversation",e);const t={};e.dialogs.forEach(e=>{const s=S.a.getPeerId(e.peer);let a=e.top_message;const i=this.pendingTopMsgs[s];if(i&&(!a||this.getMessageByPeer(s,i).date>this.getMessageByPeer(s,a).date)&&(e.top_message=a=i,this.getHistoryStorage(s).maxId=i),a||e.draft&&"draftMessage"===e.draft._)this.saveConversation(e),t[s]=e;else{const e=this.dialogsStorage.dropDialog(s);e.length&&_.default.broadcast("dialog_drop",{peerId:s,dialog:e[0]})}if(void 0!==this.newUpdatesAfterReloadToHandle[s]){for(const e of this.newUpdatesAfterReloadToHandle[s])P.a.saveUpdate(e);delete this.newUpdatesAfterReloadToHandle[s]}}),Object.keys(t).length&&_.default.broadcast("dialogs_multiupdate",t)}generateDialog(e){return{_:"dialog",pFlags:{},peer:S.a.getOutputPeer(e),top_message:0,read_inbox_max_id:0,read_outbox_max_id:0,unread_count:0,unread_mentions_count:0,notify_settings:{_:"peerNotifySettings"}}}saveConversation(e,t=0){const s=S.a.getPeerId(e.peer);if(!s)return console.error("saveConversation no peerId???",e,t),!1;"dialog"!==e._&&console.error("saveConversation not regular dialog",e,Object.assign({},e));const a=S.a.isChannel(s)?-s:0;if(s<0){const e=M.a.getChat(-s);if("channelForbidden"===e._||"chatForbidden"===e._||e.pFlags.left||e.pFlags.kicked)return!1}const i=S.a.getPeerSearchText(s);let n,o;if(v.a.indexObject(s,i,this.dialogsStorage.dialogsIndex),e.top_message?(n=this.generateMessageId(e.top_message),o=this.getMessageByPeer(s,n)):(n=this.generateTempMessageId(s),o={_:"message",id:n,mid:n,from_id:S.a.getOutputPeer(F.a.getSelf().id),peer_id:S.a.getOutputPeer(s),deleted:!0,pFlags:{out:!0},date:0,message:""},this.saveMessages([o],{isOutgoing:!0})),(null==o?void 0:o.pFlags)||this.log.error("saveConversation no message:",e,o),!a&&s<0){const e=M.a.getChat(-s);if(e&&e.migrated_to&&e.pFlags.deactivated){const t=S.a.getPeerId(e.migrated_to);return this.migratedFromTo[s]=t,void(this.migratedToFrom[t]=s)}}const r=this.getDialogByPeerId(s)[0];e.top_message=n,e.read_inbox_max_id=this.generateMessageId(r&&!e.read_inbox_max_id?r.read_inbox_max_id:e.read_inbox_max_id),e.read_outbox_max_id=this.generateMessageId(r&&!e.read_outbox_max_id?r.read_outbox_max_id:e.read_outbox_max_id),e.hasOwnProperty("folder_id")||"dialog"===e._&&(e.folder_id=r?r.folder_id:t),e.draft=j.a.saveDraft(s,0,e.draft),e.peerId=s,o.pFlags.is_outgoing&&(n>e[o.pFlags.out?"read_outbox_max_id":"read_inbox_max_id"]?o.pFlags.unread=!0:delete o.pFlags.unread);let d=this.getHistoryStorage(s);d.history.slice.length||d.history.unshift(n),d.maxId=n,d.readMaxId=e.read_inbox_max_id,d.readOutboxMaxId=e.read_outbox_max_id,R.a.savePeerSettings(s,e.notify_settings),a&&e.pts&&P.a.addChannelState(a,e.pts),this.dialogsStorage.generateIndexForDialog(e),this.dialogsStorage.pushDialog(e,o.date)}mergeReplyKeyboard(e,t){var s;if(!t.reply_markup&&!(null===(s=t.pFlags)||void 0===s?void 0:s.out)&&!t.action)return!1;if(t.reply_markup&&"replyInlineMarkup"===t.reply_markup._)return!1;var a=t.reply_markup,i=e.reply_markup;if(a)return!(i&&i.mid>=t.mid)&&(!a.pFlags.selective&&(e.maxOutId&&t.mid<e.maxOutId&&a.pFlags.single_use&&(a.pFlags.hidden=!0),"replyKeyboardHide"!==(a=Object.assign({mid:t.mid},a))._&&(a.fromId=S.a.getPeerId(t.from_id)),e.reply_markup=a,!0));if(t.pFlags.out)if(i){if(i.pFlags.single_use&&!i.pFlags.hidden&&(t.mid>i.mid||t.pFlags.is_outgoing)&&t.message)return i.pFlags.hidden=!0,!0}else(!e.maxOutId||t.mid>e.maxOutId)&&(e.maxOutId=t.mid);return!(!t.action||"messageActionChatDeleteUser"!==t.action._||!(i?t.action.user_id===i.fromId:F.a.isBot(t.action.user_id)))&&(e.reply_markup={_:"replyKeyboardHide",mid:t.mid,pFlags:{}},!0)}getSearchStorage(e,t){return this.searchesStorage[e]||(this.searchesStorage[e]={}),this.searchesStorage[e][t]||(this.searchesStorage[e][t]={history:[]}),this.searchesStorage[e][t]}getSearchCounters(e,t,s=!0){return(s?g.a.invokeApiCacheable:g.a.invokeApi).bind(g.a)("messages.getSearchCounters",{peer:S.a.getInputPeerById(e),filters:t})}getSearch({peerId:e,query:t,inputFilter:s,maxId:a,limit:i,nextRate:n,backLimit:o,threadId:r,folderId:d,minDate:l,maxDate:c}){e||(e=0),t||(t=""),s||(s={_:"inputMessagesFilterEmpty"}),void 0===i&&(i=20),n||(n=0),o||(o=0),l=l?l/1e3|0:0,c=c?c/1e3|0:0;const h=[];o&&(i+=o);let u;if(e&&!o&&!a&&!t&&1!==i&&!r){u=this.getHistoryStorage(e);let t=!0;const a=u.history;if(void 0!==u&&a.length){const n={},o=[],r=[];switch(s._){case"inputMessagesFilterPhotos":n.messageMediaPhoto=!0;break;case"inputMessagesFilterPhotoVideo":n.messageMediaPhoto=!0,n.messageMediaDocument=!0,o.push("video");break;case"inputMessagesFilterVideo":n.messageMediaDocument=!0,o.push("video");break;case"inputMessagesFilterDocument":n.messageMediaDocument=!0,r.push("video");break;case"inputMessagesFilterVoice":n.messageMediaDocument=!0,o.push("voice");break;case"inputMessagesFilterRoundVoice":n.messageMediaDocument=!0,o.push("round","voice");break;case"inputMessagesFilterRoundVideo":n.messageMediaDocument=!0,o.push("round");break;case"inputMessagesFilterMusic":n.messageMediaDocument=!0,o.push("audio");break;case"inputMessagesFilterUrl":n.url=!0;break;case"inputMessagesFilterChatPhotos":n.avatar=!0;break;default:t=!1}if(t){const t=this.getMessagesStorage(e);for(let e=0,s=a.length;e<s;e++){const s=t[a.slice[e]];if(!s)continue;let d=!1;if(s.media&&n[s.media._]&&!s.fwd_from){if("messageMediaDocument"===s.media._&&(o.length&&!o.includes(s.media.document.type)||r.includes(s.media.document.type)))continue;d=!0}else if(n.url&&s.message){const e=["messageEntityTextUrl","messageEntityUrl"];(s.totalEntities.find(t=>e.includes(t._))||f.a.matchUrl(s.message))&&(d=!0)}else n.avatar&&s.action&&["messageActionChannelEditPhoto","messageActionChatEditPhoto","messageActionChannelEditVideo","messageActionChatEditVideo"].includes(s.action._)&&(d=!0);if(d&&(h.push(s),h.length>=i))break}}}}if(h.length){if(!(h.length<i))return Promise.resolve({count:0,next_rate:0,offset_id_offset:0,history:h});a=h[h.length-1].mid,i-=h.length}else 0;const p=g.a.invokeApi.bind(g.a);let m;if(e&&!n&&void 0===d)m=p("messages.search",{peer:S.a.getInputPeerById(e),q:t||"",filter:s,min_date:l,max_date:c,limit:i,offset_id:this.getServerMessageId(a)||0,add_offset:o?-o:0,max_id:0,min_id:0,hash:0,top_msg_id:this.getServerMessageId(r)||0},{noErrorBox:!0});else{let o=0,r=0,h=a&&this.getMessageByPeer(e,a);h&&h.date&&(r=h.id,o=this.getMessagePeer(h)),m=p("messages.searchGlobal",{q:t,filter:s,min_date:l,max_date:c,offset_rate:n,offset_peer:S.a.getInputPeerById(o),offset_id:r,limit:i,folder_id:d},{noErrorBox:!0})}return m.then(e=>{F.a.saveApiUsers(e.users),M.a.saveApiChats(e.chats),this.saveMessages(e.messages),O.b&&this.log("getSearch result:",s,e);const t=e.count||h.length+e.messages.length;return e.messages.forEach(e=>{const t=this.getMessagePeer(e);if(t<0){const e=M.a.getChat(-t);e.migrated_to&&this.migrateChecks(t,-e.migrated_to.channel_id)}h.push(e)}),{count:t,offset_id_offset:e.offset_id_offset||0,next_rate:e.next_rate,history:h}})}subscribeRepliesThread(e,t){const s=e+"_"+t;for(const e in this.threadsToReplies)if(this.threadsToReplies[e]===s)return;this.getDiscussionMessage(e,t)}generateThreadServiceStartMessage(e){const t=e.peerId+"_"+e.mid;if(this.threadsServiceMessagesIdsStorage[t])return;const s=this.getServerMessageId(Math.max(...this.getMidsByMessage(e))),a={_:"messageService",pFlags:{is_single:!0},id:this.generateMessageId(s,!0),date:e.date,from_id:{_:"peerUser",user_id:0},peer_id:e.peer_id,action:{_:"messageActionCustomAction",message:"Discussion started"},reply_to:this.generateReplyHeader(e.id)};this.saveMessages([a],{isOutgoing:!0}),this.threadsServiceMessagesIdsStorage[t]=a.mid}getDiscussionMessage(e,t){return g.a.invokeApi("messages.getDiscussionMessage",{peer:S.a.getInputPeerById(e),msg_id:this.getServerMessageId(t)}).then(s=>{M.a.saveApiChats(s.chats),F.a.saveApiUsers(s.users),this.saveMessages(s.messages);const a=this.filterMessages(s.messages[0],e=>!!e.replies)[0],i=a.peerId+"_"+a.mid;this.generateThreadServiceStartMessage(a);const n=this.getHistoryStorage(a.peerId,a.mid);return s.max_id=n.maxId=this.generateMessageId(s.max_id)||0,s.read_inbox_max_id=n.readMaxId=this.generateMessageId(s.read_inbox_max_id)||0,s.read_outbox_max_id=n.readOutboxMaxId=this.generateMessageId(s.read_outbox_max_id)||0,this.threadsToReplies[i]=e+"_"+t,a})}scheduleHandleNewDialogs(){this.newDialogsHandlePromise||(this.newDialogsHandlePromise=window.setTimeout(this.handleNewDialogs,0))}deleteMessages(e,t,s){let a;const i=t.map(e=>this.getServerMessageId(e));if(e<0&&S.a.isChannel(e)){const s=-e,n=M.a.getChat(s);if(!(n.pFlags.creator||n.pFlags.editor&&n.pFlags.megagroup)){const s=[];if((n.pFlags.editor||n.pFlags.megagroup)&&t.forEach((a,i)=>{this.getMessageByPeer(e,t[i]).pFlags.out&&s.push(a)}),!s.length)return;t=s}a=g.a.invokeApi("channels.deleteMessages",{channel:M.a.getChannelInput(s),id:i}).then(e=>{P.a.processUpdateMessage({_:"updateShort",update:{_:"updateDeleteChannelMessages",channel_id:s,messages:t,pts:e.pts,pts_count:e.pts_count}})})}else a=g.a.invokeApi("messages.deleteMessages",{revoke:s,id:i}).then(e=>{P.a.processUpdateMessage({_:"updateShort",update:{_:"updateDeleteMessages",messages:t,pts:e.pts,pts_count:e.pts_count}})});return a}readHistory(e,t=0,s,a=!1){if(this.log("readHistory:",e,t,s),!this.getReadMaxIdIfUnread(e,s)&&!a)return this.log("readHistory: isn't unread"),Promise.resolve();const i=this.getHistoryStorage(e,s);if(i.triedToReadMaxId>=t)return Promise.resolve();let n;if(s?(i.readPromise||(n=g.a.invokeApi("messages.readDiscussion",{peer:S.a.getInputPeerById(e),msg_id:this.getServerMessageId(s),read_max_id:this.getServerMessageId(t)})),P.a.processUpdateMessage({_:"updateShort",update:{_:"updateReadChannelDiscussionInbox",channel_id:-e,top_msg_id:s,read_max_id:t}})):S.a.isChannel(e)?(i.readPromise||(n=g.a.invokeApi("channels.readHistory",{channel:M.a.getChannelInput(-e),max_id:this.getServerMessageId(t)})),P.a.processUpdateMessage({_:"updateShort",update:{_:"updateReadChannelInbox",max_id:t,channel_id:-e}})):(i.readPromise||(n=g.a.invokeApi("messages.readHistory",{peer:S.a.getInputPeerById(e),max_id:this.getServerMessageId(t)}).then(e=>{P.a.processUpdateMessage({_:"updateShort",update:{_:"updatePts",pts:e.pts,pts_count:e.pts_count}})})),P.a.processUpdateMessage({_:"updateShort",update:{_:"updateReadHistoryInbox",max_id:t,peer:S.a.getOutputPeer(e)}})),!s&&i&&i.history.length){const t=i.history.slice;for(const s of t){const t=this.getMessageByPeer(e,s);t&&!t.pFlags.out&&(t.pFlags.unread=!1,R.a.cancel("msg"+s))}}return R.a.soundReset(S.a.getPeerString(e)),i.readPromise?i.readPromise:(i.triedToReadMaxId=t,n.finally(()=>{delete i.readPromise,this.log("readHistory: promise finally",t,i.readMaxId),i.readMaxId>t&&this.readHistory(e,i.readMaxId,s,!0)}),i.readPromise=n)}readAllHistory(e,t,s=!1){const a=this.getHistoryStorage(e,t);a.maxId&&this.readHistory(e,a.maxId,t,s)}readMessages(e,t){if(t=t.map(e=>this.getServerMessageId(e)),e<0&&S.a.isChannel(e)){const s=-e;g.a.invokeApi("channels.readMessageContents",{channel:M.a.getChannelInput(s),id:t}).then(()=>{P.a.processUpdateMessage({_:"updateShort",update:{_:"updateChannelReadMessagesContents",channel_id:s,messages:t}})})}else g.a.invokeApi("messages.readMessageContents",{id:t}).then(e=>{P.a.processUpdateMessage({_:"updateShort",update:{_:"updateReadMessagesContents",messages:t,pts:e.pts,pts_count:e.pts_count}})})}getHistoryStorage(e,t){var s,a;return t?(this.threadsStorage[e]||(this.threadsStorage[e]={}),null!==(s=this.threadsStorage[e][t])&&void 0!==s?s:this.threadsStorage[e][t]={count:null,history:new L.b}):null!==(a=this.historiesStorage[e])&&void 0!==a?a:this.historiesStorage[e]={count:null,history:new L.b}}updateMessageRepliesIfNeeded(e){try{const t=this.getThreadKey(e);if(t){const e=this.threadsToReplies[t];if(e){const[t,s]=e.split("_").map(e=>+e);this.updateMessage(t,s,"replies_updated")}}}catch(t){this.log.error("incrementMessageReplies err",t,e)}}getThreadKey(e){let t="";if(e.peerId<0&&e.reply_to){const s=e.reply_to.reply_to_top_id||e.reply_to.reply_to_msg_id;t=e.peerId+"_"+s}return t}updateMessage(e,t,s){return this.wrapSingleMessage(e,t,!0).then(()=>{const a=this.getMessageByPeer(e,t);return s&&_.default.broadcast(s,a),a})}checkPendingMessage(e){const t=this.pendingByMessageId[e.mid];let s;if(t){const a=this.pendingByRandomId[t];(s=this.finalizePendingMessage(t,e))&&_.default.broadcast("history_update",{storage:a.storage,peerId:e.peerId,mid:e.mid}),delete this.pendingByMessageId[e.mid]}return s}mutePeer(e,t){const s={_:"inputPeerNotifySettings"};if(void 0===t){t=!1;const s=z.getDialogByPeerId(e)[0];s&&s.notify_settings&&(t=(s.notify_settings.mute_until||0)<=(Date.now()/1e3|0))}return s.mute_until=t?4294967295:0,R.a.updateNotifySettings({_:"inputNotifyPeer",peer:S.a.getInputPeerById(e)},s)}canWriteToPeer(e){if(e<0){const t=S.a.isChannel(e),s=t&&M.a.hasRights(-e,"send_messages");return!t||s}return F.a.canSendToUser(e)}finalizePendingMessage(e,t){const s=this.pendingByRandomId[e];if(s){const{peerId:a,tempId:i,threadId:n,storage:o}=s;[this.getHistoryStorage(a),n?this.getHistoryStorage(a,n):void 0].filter(Boolean).forEach(e=>{e.history.delete(i)});const r=this.getMessageFromStorage(o,i);return r.deleted||(delete r.pFlags.is_outgoing,delete r.pending,delete r.error,delete r.random_id,delete r.send,_.default.broadcast("messages_pending")),delete this.pendingByRandomId[e],this.finalizePendingMessageCallbacks(o,i,t.mid),r}return!1}finalizePendingMessageCallbacks(e,t,s){const a=this.getMessageFromStorage(e,s),i=this.tempFinalizeCallbacks[t];if(void 0!==i){for(const e in i){const{deferred:t,callback:s}=i[e];s(a).then(t.resolve,t.reject)}delete this.tempFinalizeCallbacks[t]}if(a.media)if(a.media.photo){const e=k.a.getPhoto(""+t);if(e){const t=a.media.photo;Object(d.c)(t,["downloaded","url"]),t.downloaded=e.downloaded,t.url=e.url;const s=t.sizes[t.sizes.length-1];Object(d.c)(s,["url"]),s.url=e.url;const i=k.a.getPhotoDownloadOptions(t,s),n=Object(E.a)(i.location);w.a.fakeDownload(n,e.url)}}else if(a.media.document){const e=I.a.getDoc(""+t);if(e&&e.type&&"sticker"!==e.type){const t=a.media.document;t.downloaded=e.downloaded,t.url=e.url;const s=I.a.getInputFileName(t);w.a.fakeDownload(s,e.url)}}else a.media.poll&&(delete A.a.polls[t],delete A.a.results[t]);const n=this.getMessageFromStorage(e,t);delete e[t],_.default.broadcast("message_sent",{storage:e,tempId:t,tempMessage:n,mid:s})}incrementMaxSeenId(e){if(!e||this.maxSeenId&&!(e>this.maxSeenId))return!1;this.maxSeenId=e,g.a.invokeApi("messages.receivedMessages",{max_id:this.getServerMessageId(e)})}notifyAboutMessage(e,t={}){const s=this.getMessagePeer(e),a={},i=S.a.getPeerString(s);let n;n=t.peerTypeNotifySettings.show_previews?"message"===e._&&e.fwd_from&&t.fwdCount?h.default.format("Notifications.Forwarded",!0,[t.fwdCount]):this.wrapMessageForReply(e,void 0,void 0,!0):h.default.format("Notifications.New",!0),a.title=S.a.getPeerTitle(s,!0),s<0&&e.fromId!==e.peerId&&(a.title=S.a.getPeerTitle(e.fromId,!0)+" @ "+a.title),a.title=f.a.wrapPlainText(a.title),a.onclick=()=>{_.default.broadcast("history_focus",{peerId:s,mid:e.mid})},a.message=n,a.key="msg"+e.mid,a.tag=i,a.silent=!0;const o=S.a.getPeerPhoto(s);o?U.default.loadAvatar(s,o,"photo_small").loadPromise.then(t=>{e.pFlags.unread&&(a.image=t,R.a.notify(a))}):R.a.notify(a)}getScheduledMessagesStorage(e){var t;return null!==(t=this.scheduledMessagesStorage[e])&&void 0!==t?t:this.scheduledMessagesStorage[e]=this.createMessageStorage()}getScheduledMessages(e){if(!this.canWriteToPeer(e))return Promise.resolve([]);const t=this.getScheduledMessagesStorage(e);return Object.keys(t).length?Promise.resolve(Object.keys(t).map(e=>+e)):g.a.invokeApi("messages.getScheduledHistory",{peer:S.a.getInputPeerById(e),hash:0}).then(t=>{if("messages.messagesNotModified"!==t._){F.a.saveApiUsers(t.users),M.a.saveApiChats(t.chats);const s=this.getScheduledMessagesStorage(e);return this.saveMessages(t.messages,{storage:s,isScheduled:!0}),Object.keys(s).map(e=>+e)}return[]})}sendScheduledMessages(e,t){return g.a.invokeApi("messages.sendScheduledMessages",{peer:S.a.getInputPeerById(e),id:t.map(e=>this.getServerMessageId(e))}).then(e=>{P.a.processUpdateMessage(e)})}deleteScheduledMessages(e,t){return g.a.invokeApi("messages.deleteScheduledMessages",{peer:S.a.getInputPeerById(e),id:t.map(e=>this.getServerMessageId(e))}).then(e=>{P.a.processUpdateMessage(e)})}getHistory(e,t=0,s,a,i){const n=this.getHistoryStorage(e,i);let o=0;a&&(o=-a,s+=a);const r=n.history.sliceMe(t,o,s);return r&&(r.slice.length===s||r.fulfilled&L.a.Both)?{count:n.count,history:r.slice,offsetIdOffset:r.offsetIdOffset}:this.fillHistoryStorage(e,t,s,o,n,i).then(()=>{const e=n.history.sliceMe(t,o,s);return{count:n.count,history:(null==e?void 0:e.slice)||n.history.constructSlice(),offsetIdOffset:(null==e?void 0:e.offsetIdOffset)||n.count}})}fillHistoryStorage(e,t,s,a,i,n){return this.requestHistory(e,t,s,a,void 0,n).then(n=>{i.count=n.count||n.messages.length;const o=n.offset_id_offset||0,r=o>=i.count-s||i.count<s+a;n.messages.forEach(t=>{this.mergeReplyKeyboard(i,t)&&_.default.broadcast("history_reply_markup",{peerId:e})});const d=n.messages.map(e=>e.mid);if(t&&!d.includes(t)&&o<i.count){let e=0;for(const s=d.length;e<s&&!(t>d[e]);++e);d.splice(e,0,t)}i.history.insertSlice(d),r&&i.history.last.setEnd(L.a.Top)})}requestHistory(e,t,s=0,a=0,i=0,n=0){const o={peer:S.a.getInputPeerById(e),offset_id:this.getServerMessageId(t)||0,offset_date:i,add_offset:a,limit:s,max_id:0,min_id:0,hash:0};n&&(o.msg_id=this.getServerMessageId(n)||0);return g.a.invokeApi(n?"messages.getReplies":"messages.getHistory",o,{noErrorBox:!0}).then(o=>{O.b&&this.log("requestHistory result:",e,o,t,s,a),F.a.saveApiUsers(o.users),M.a.saveApiChats(o.chats),this.saveMessages(o.messages),S.a.isChannel(e)&&P.a.addChannelState(-e,o.pts);let r=o.messages.length;r&&o.messages[r-1].deleted&&(o.messages.splice(r-1,1),r--,o.count--);const d=this.getHistoryStorage(e,n);return r&&o.messages[r-1].grouped_id&&d.history.length+o.messages.length<o.count?this.requestHistory(e,o.messages[r-1].mid,10,0,i,n).then(e=>o):o},t=>{switch(t.type){case"CHANNEL_PRIVATE":let t=M.a.getChat(-e);t={_:"channelForbidden",access_hash:t.access_hash,title:t.title},P.a.processUpdateMessage({_:"updates",updates:[{_:"updateChannel",channel_id:-e}],chats:[t],users:[]})}throw t})}fetchSingleMessages(){return this.fetchSingleMessagesPromise?this.fetchSingleMessagesPromise:this.fetchSingleMessagesPromise=new Promise(e=>{setTimeout(()=>{let t=[];for(const e in this.needSingleMessages){const s=this.needSingleMessages[e];delete this.needSingleMessages[e];const a=s.map(e=>({_:"inputMessageID",id:this.getServerMessageId(e)}));let i;i=+e<0&&S.a.isChannel(+e)?g.a.invokeApi("channels.getMessages",{channel:M.a.getChannelInput(-+e),id:a}):g.a.invokeApi("messages.getMessages",{id:a}),t.push(i.then(t=>{"messages.messagesNotModified"!==t._&&(F.a.saveApiUsers(t.users),M.a.saveApiChats(t.chats),this.saveMessages(t.messages)),_.default.broadcast("messages_downloaded",{peerId:+e,mids:s})}))}Promise.all(t).finally(()=>{this.fetchSingleMessagesPromise=null,Object.keys(this.needSingleMessages).length&&this.fetchSingleMessages(),e()})},0)})}wrapSingleMessage(e,t,s=!1){var a;return this.getMessageByPeer(e,t).deleted||s?this.needSingleMessages[e]&&-1!==this.needSingleMessages[e].indexOf(t)?this.fetchSingleMessagesPromise?this.fetchSingleMessagesPromise:void 0:((null!==(a=this.needSingleMessages[e])&&void 0!==a?a:this.needSingleMessages[e]=[]).push(t),this.fetchSingleMessages()):(_.default.broadcast("messages_downloaded",{peerId:e,mids:[t]}),Promise.resolve())}setTyping(e,t){if(!_.default.myId||!e||!this.canWriteToPeer(e)||e===_.default.myId)return Promise.resolve(!1);const s="string"==typeof t?{_:t}:t;return g.a.invokeApi("messages.setTyping",{peer:S.a.getInputPeerById(e),action:s})}handleDeletedMessages(e,t,s){const a={count:0,unread:0,msgs:{}};for(const i of s){const s=this.getMessageFromStorage(t,i);if(s.deleted)continue;if(s.media){const t=s.media.webpage||s.media,a=t.photo||t.document;(null==a?void 0:a.file_reference)&&p.a.deleteContext(a.file_reference,{type:"message",peerId:e,messageId:i}),s.media.webpage&&T.a.deleteWebPageFromPending(s.media.webpage,i)}if(this.updateMessageRepliesIfNeeded(s),s.pFlags.out||s.pFlags.is_outgoing||!s.pFlags.unread||(a.unread++,R.a.cancel("msg"+i)),a.count++,a.msgs[i]=!0,s.deleted=!0,"messageService"!==s._&&s.grouped_id){const e=this.groupedMessagesStorage[s.grouped_id];e&&(delete e[i],a.albums||(a.albums={}),(a.albums[s.grouped_id]||(a.albums[s.grouped_id]=new Set)).add(i),Object.keys(e).length||(delete a.albums,delete this.groupedMessagesStorage[s.grouped_id]))}delete t[i];const n=this.newMessagesToHandle[e];n&&n.has(i)&&n.delete(i)}if(a.albums)for(const t in a.albums)_.default.broadcast("album_edit",{peerId:e,groupId:t,deletedMids:[...a.albums[t]]});return a}handleEditedMessage(e,t){var s;(null===(s=e.media)||void 0===s?void 0:s.webpage)&&T.a.deleteWebPageFromPending(e.media.webpage,e.mid)}}W.MESSAGE_ID_INCREMENT=65536,W.MESSAGE_ID_OFFSET=4294967295;const z=new W;O.a.appMessagesManager=z;t.a=z},,,function(e,t,s){"use strict";var a=s(10),i=s(15),n=s(11),o=s(9),r=s(25),d=s(18);const l=["#fc5c51","#0fb297","#d09306","#3d72ed","#895dd5","#cd4073","#00c1a6","#fa790f"],c=["red","green","yellow","blue","violet","pink","cyan","orange"],h=[0,7,4,1,6,3,5];const u=new class{constructor(){o.default.addMultipleEventsListeners({updatePeerBlocked:e=>{o.default.broadcast("peer_block",{peerId:this.getPeerId(e.peer_id),blocked:e.blocked})}})}canPinMessage(e){return e>0||r.a.hasRights(-e,"pin_messages")}getPeerPhoto(e){const t=e>0?d.a.getUserPhoto(e):r.a.getChatPhoto(-e);return"chatPhotoEmpty"!==t._&&"userProfilePhotoEmpty"!==t._?t:null}getPeerMigratedTo(e){if(e>=0)return!1;let t=r.a.getChat(-e);return!!(t&&t.migrated_to&&t.pFlags.deactivated)&&this.getPeerId(t.migrated_to)}getPeerTitle(e,t=!1,s=!1){e||(e=o.default.myId);let a={};a=Object(i.f)(e)?e:this.getPeer(e);let r="";return e>0?(a.first_name&&(r+=a.first_name),a.last_name&&(r+=" "+a.last_name),r=r?r.trim():a.pFlags.deleted?"Deleted Account":a.username):r=a.title,s&&(r=r.split(" ")[0]),t?r:n.a.wrapEmojiText(r)}getOutputPeer(e){if(e>0)return{_:"peerUser",user_id:e};let t=-e;return r.a.isChannel(t)?{_:"peerChannel",channel_id:t}:{_:"peerChat",chat_id:t}}getPeerString(e){return e>0?d.a.getUserString(e):r.a.getChatString(-e)}getPeerUsername(e){return e>0?d.a.getUser(e).username||"":r.a.getChat(-e).username||""}getPeer(e){return e>0?d.a.getUser(e):r.a.getChat(-e)}getPeerId(e){if("number"==typeof e)return e;if(Object(i.f)(e))return e.user_id||-(e.channel_id||e.chat_id);if(!e)return 0;const t="u"===e.charAt(0),s=e.substr(1).split("_");return t?+s[0]:-s[0]||0}getDialogPeer(e){return{_:"dialogPeer",peer:this.getOutputPeer(e)}}isChannel(e){return e<0&&r.a.isChannel(-e)}isMegagroup(e){return e<0&&r.a.isMegagroup(-e)}isAnyGroup(e){return e<0&&!r.a.isBroadcast(-e)}isBroadcast(e){return this.isChannel(e)&&!this.isMegagroup(e)}isBot(e){return e>0&&d.a.isBot(e)}getInputNotifyPeerById(e,t){return t?e>0?{_:"inputNotifyUsers"}:u.isBroadcast(e)?{_:"inputNotifyBroadcasts"}:{_:"inputNotifyChats"}:{_:"inputNotifyPeer",peer:this.getInputPeerById(e)}}getInputPeerById(e){if(!e)return{_:"inputPeerEmpty"};if(e<0){const t=-e;return r.a.isChannel(t)?r.a.getChannelInputPeer(t):r.a.getChatInputPeer(t)}return{_:"inputPeerUser",user_id:e,access_hash:d.a.getUser(e).access_hash}}getInputDialogPeerById(e){return{_:"inputDialogPeer",peer:this.getInputPeerById(e)}}getPeerColorById(e,t=!0){if(!e)return"";return(t?c:l)[h[(e<0?-e:e)%7]]}getPeerSearchText(e){let t;if(e>0)t="%pu "+d.a.getUserSearchText(e);else if(e<0){t="%pg "+(r.a.getChat(-e).title||"")}return t}getDialogType(e){return u.isMegagroup(e)?"megagroup":u.isChannel(e)?"channel":e<0?"group":e===o.default.myId?"saved":"chat"}getDeleteButtonText(e){switch(this.getDialogType(e)){case"channel":return"ChatList.Context.LeaveChannel";case"megagroup":return"ChatList.Context.LeaveGroup";case"group":return"ChatList.Context.DeleteAndExit";default:return"ChatList.Context.DeleteChat"}}};a.a.appPeersManager=u,t.a=u},function(e,t,s){"use strict";var a=s(10),i=s(48),n=s(15),o=s(8),r=s(13),d=s(11),l=s(9),c=s(51),h=s(21),u=s(24),g=s(34),p=s(14),m=s(18),f=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};const _=new class{constructor(){this.chats={},this.megagroupOnlines={},this.typingsInPeer={},this.onUpdateUserTyping=e=>{var t;const s=e.user_id||u.a.getPeerId(e.from_id);if(l.default.myId===s||"speakingInGroupCallAction"===e.action._)return;const a="updateUserTyping"===e._?s:-(e.chat_id||e.channel_id),i=null!==(t=this.typingsInPeer[a])&&void 0!==t?t:this.typingsInPeer[a]=[];let n=i.find(e=>e.userId===s);const o=()=>{delete n.timeout;const e=i.indexOf(n);-1!==e&&i.splice(e,1),l.default.broadcast("peer_typings",{peerId:a,typings:i}),i.length||delete this.typingsInPeer[a]};if(n&&void 0!==n.timeout&&clearTimeout(n.timeout),"sendMessageCancelAction"!==e.action._)n||(n={userId:s},i.push(n)),n.action=e.action,m.a.hasUser(s)||"updateChatUserTyping"===e._&&e.chat_id&&_.hasChat(e.chat_id)&&!_.isChannel(e.chat_id)&&g.default.getChatFull(e.chat_id),m.a.forceUserOnline(s),n.timeout=window.setTimeout(o,6e3),l.default.broadcast("peer_typings",{peerId:a,typings:i});else{if(!n)return;o()}},this.onChatUpdated=(e,t)=>{c.a.processUpdateMessage(t),t&&this.isChannel(e)&&g.default.invalidateChannelParticipants(e)},l.default.addMultipleEventsListeners({updateChannel:e=>{const t=e.channel_id;l.default.broadcast("channel_settings",{channelId:t})},updateChannelParticipant:e=>{r.a.clearCache("channels.getParticipants",t=>t.channel.channel_id===e.channel_id)},updateChatDefaultBannedRights:e=>{const t=-u.a.getPeerId(e.peer),s=this.chats[t];s&&(s.default_banned_rights=e.default_banned_rights,l.default.broadcast("chat_update",t))},updateUserTyping:this.onUpdateUserTyping,updateChatUserTyping:this.onUpdateUserTyping,updateChannelUserTyping:this.onUpdateUserTyping}),p.default.getState().then(e=>{this.chats=e.chats})}getPeerTypings(e){return this.typingsInPeer[e]}saveApiChats(e,t){e.forEach(e=>this.saveApiChat(e,t))}saveApiChat(e,t){var s,a;const i=this.chats[e.id];if(void 0===e.pFlags&&(e.pFlags={}),e.pFlags.min&&void 0!==i)return;e.initials=d.a.getAbbreviation(e.title),"channel"===e._&&void 0===e.participants_count&&void 0!==i&&i.participants_count&&(e.participants_count=i.participants_count);let o=!1,r=!1;if(void 0===i)this.chats[e.id]=e;else{const t=null===(s=i.photo)||void 0===s?void 0:s.photo_small,d=null===(a=e.photo)||void 0===a?void 0:a.photo_small;JSON.stringify(t)!==JSON.stringify(d)&&(o=!0),i.title!==e.title&&(r=!0),Object(n.i)(i,e),l.default.broadcast("chat_update",e.id)}o&&l.default.broadcast("avatar_update",-e.id),r&&l.default.broadcast("peer_title_edit",-e.id)}getChat(e){return e<0&&(e=-e),this.chats[e]||{_:"chatEmpty",id:e,deleted:!0,access_hash:"",pFlags:{}}}combineParticipantBannedRights(e,t){const s=this.getChat(e);if(s.default_banned_rights){t=Object(n.a)(t);const e=s.default_banned_rights.pFlags;for(let s in e)t.pFlags[s]=e[s]}return t}hasRights(e,t,s){const a=this.getChat(e);if("chatEmpty"===a._)return!1;if("chatForbidden"===a._||"channelForbidden"===a._||a.pFlags.kicked||a.pFlags.left&&!a.pFlags.megagroup)return!1;if(a.pFlags.creator&&void 0===s)return!0;if(s||(s=a.admin_rights||a.banned_rights||a.default_banned_rights),!s)return!1;let i={};switch(s&&(i=s.pFlags),t){case"embed_links":case"send_games":case"send_gifs":case"send_inline":case"send_media":case"send_messages":case"send_polls":case"send_stickers":if("chatBannedRights"===s._&&i[t])return!1;if("channel"===a._&&!a.pFlags.megagroup&&!i.post_messages)return!1;break;case"delete_messages":return!!i.delete_messages;case"pin_messages":return"chatAdminRights"===s._?i[t]||!!i.post_messages:!i[t];case"invite_users":case"change_info":return"chatAdminRights"===s._?i[t]:!i[t];case"change_type":case"delete_chat":return!1;case"change_permissions":return"chatAdminRights"===s._&&i.ban_users;case"view_participants":return!("chat"!==a._&&a.pFlags.broadcast&&!a.pFlags.creator&&!a.admin_rights)}return!0}editChatDefaultBannedRights(e,t){const s=this.getChat(e);return s.default_banned_rights&&s.default_banned_rights.until_date===t.until_date&&Object(n.b)(s.default_banned_rights.pFlags,t.pFlags)?Promise.resolve():r.a.invokeApi("messages.editChatDefaultBannedRights",{peer:u.a.getInputPeerById(-e),banned_rights:t}).then(this.onChatUpdated.bind(this,e))}isChannel(e){e<0&&(e=-e);const t=this.chats[e];return t&&("channel"===t._||"channelForbidden"===t._)}isMegagroup(e){const t=this.chats[e];return t&&"channel"===t._&&t.pFlags.megagroup}isBroadcast(e){return this.isChannel(e)&&!this.isMegagroup(e)}getChannelInput(e){e<0&&(e=-e);const t=this.getChat(e);return"chatEmpty"!==t._&&t.access_hash?{_:"inputChannel",channel_id:e,access_hash:t.access_hash||"0"}:{_:"inputChannelEmpty"}}getChatInputPeer(e){return{_:"inputPeerChat",chat_id:e}}getChannelInputPeer(e){return{_:"inputPeerChannel",channel_id:e,access_hash:this.getChat(e).access_hash||0}}hasChat(e,t){const s=this.chats[e];return Object(n.f)(s)&&(t||!s.pFlags.min)}getChatPhoto(e){const t=this.getChat(e);return t&&t.photo||{_:"chatPhotoEmpty"}}getChatString(e){const t=this.getChat(e);return this.isChannel(e)?(this.isMegagroup(e)?"s":"c")+e+"_"+t.access_hash:"g"+e}getChatMembersString(e){var t,s;const a=this.getChat(e),n=g.default.chatsFull[e];let r;r=n?"channelFull"===n._?n.participants_count:null===(t=n.participants.participants)||void 0===t?void 0:t.length:a.participants_count||(null===(s=a.participants)||void 0===s?void 0:s.participants.length);r=r||1;let d=this.isBroadcast(e)?"Peer.Status.Subscribers":"Peer.Status.Member";return Object(o.i18n)(d,[Object(i.d)(r)])}createChannel(e,t){return r.a.invokeApi("channels.createChannel",{broadcast:!0,title:e,about:t}).then(e=>{c.a.processUpdateMessage(e);const t=e.chats[0].id;return l.default.broadcast("history_focus",{peerId:-t}),t})}inviteToChannel(e,t){const s=this.getChannelInput(e),a=t.map(e=>m.a.getUserInput(e));return r.a.invokeApi("channels.inviteToChannel",{channel:s,users:a}).then(e=>{c.a.processUpdateMessage(e)})}createChat(e,t){return r.a.invokeApi("messages.createChat",{users:t.map(e=>m.a.getUserInput(e)),title:e}).then(e=>{c.a.processUpdateMessage(e);const t=e.chats[0].id;return l.default.broadcast("history_focus",{peerId:-t}),t})}getOnlines(e){var t,s;return f(this,void 0,void 0,(function*(){if(this.isMegagroup(e)){const a=Date.now()/1e3|0,i=null!==(t=this.megagroupOnlines[e])&&void 0!==t?t:this.megagroupOnlines[e]={timestamp:0,onlines:1};if(a-i.timestamp<60)return i.onlines;const n=yield r.a.invokeApi("messages.getOnlines",{peer:this.getChannelInputPeer(e)}),o=null!==(s=n.onlines)&&void 0!==s?s:1;return i.timestamp=a,i.onlines=o,o}if(this.isBroadcast(e))return 1;const a=(yield g.default.getChatFull(e)).participants;if(a&&a.participants){return a.participants.reduce((e,t)=>{const s=m.a.getUser(t.user_id);return s&&s.status&&"userStatusOnline"===s.status._?e+1:e},0)}return 1}))}leaveChannel(e){return r.a.invokeApi("channels.leaveChannel",{channel:this.getChannelInput(e)}).then(this.onChatUpdated.bind(this,e))}joinChannel(e){return r.a.invokeApi("channels.joinChannel",{channel:this.getChannelInput(e)}).then(this.onChatUpdated.bind(this,e))}addChatUser(e,t,s=100){return r.a.invokeApi("messages.addChatUser",{chat_id:e,user_id:m.a.getUserInput(t),fwd_limit:s}).then(this.onChatUpdated.bind(this,e))}deleteChatUser(e,t){return r.a.invokeApi("messages.deleteChatUser",{chat_id:e,user_id:m.a.getUserInput(t)}).then(this.onChatUpdated.bind(this,e))}leaveChat(e,t=!0){let s=this.deleteChatUser(e,m.a.getSelf().id);return t&&(s=s.then(()=>h.a.flushHistory(-e))),s}leave(e){return this.isChannel(e)?this.leaveChannel(e):this.leaveChat(e)}delete(e){return this.isChannel(e)?this.deleteChannel(e):this.deleteChat(e)}deleteChannel(e){return r.a.invokeApi("channels.deleteChannel",{channel:this.getChannelInput(e)}).then(this.onChatUpdated.bind(this,e))}deleteChat(e){return r.a.invokeApi("messages.deleteChat",{chat_id:e})}migrateChat(e){const t=this.getChat(e);return"channel"===t._?Promise.resolve(t.id):r.a.invokeApi("messages.migrateChat",{chat_id:e}).then(t=>{this.onChatUpdated(e,t);return t.updates.find(e=>"updateChannel"===e._).channel_id})}updateUsername(e,t){return r.a.invokeApi("channels.updateUsername",{channel:this.getChannelInput(e),username:t}).then(s=>{if(s){this.getChat(e).username=t}return s})}editPhoto(e,t){const s={_:"inputChatUploadedPhoto",file:t};let a;return a=this.isChannel(e)?r.a.invokeApi("channels.editPhoto",{channel:this.getChannelInput(e),photo:s}):r.a.invokeApi("messages.editChatPhoto",{chat_id:e,photo:s}),a.then(e=>{c.a.processUpdateMessage(e)})}editTitle(e,t){let s;return s=this.isChannel(e)?r.a.invokeApi("channels.editTitle",{channel:this.getChannelInput(e),title:t}):r.a.invokeApi("messages.editChatTitle",{chat_id:e,title:t}),s.then(e=>{c.a.processUpdateMessage(e)})}editAbout(e,t){return r.a.invokeApi("messages.editChatAbout",{peer:u.a.getInputPeerById(-e),about:t}).then(t=>{l.default.broadcast("peer_bio_edit",-e)})}editBanned(e,t,s){const a="number"==typeof t?t:t.user_id;return r.a.invokeApi("channels.editBanned",{channel:this.getChannelInput(e),user_id:m.a.getUserInput(a),banned_rights:s}).then(i=>{if(this.onChatUpdated(e,i),"number"!=typeof t){const i=Date.now()/1e3|0;c.a.processUpdateMessage({_:"updateShort",update:{_:"updateChannelParticipant",channel_id:e,date:i,user_id:a,prev_participant:t,new_participant:Object.keys(s.pFlags).length?{_:"channelParticipantBanned",date:i,banned_rights:s,kicked_by:m.a.getSelf().id,user_id:a,pFlags:{}}:void 0}})}})}clearChannelParticipantBannedRights(e,t){return this.editBanned(e,t,{_:"chatBannedRights",until_date:0,pFlags:{}})}kickFromChannel(e,t){return this.editBanned(e,t,{_:"chatBannedRights",until_date:0,pFlags:{view_messages:!0}})}};a.a.appChatsManager=_,t.a=_},,,,,,function(e,t,s){"use strict";s.d(t,"f",(function(){return n})),s.d(t,"a",(function(){return r})),s.d(t,"c",(function(){return l})),s.d(t,"d",(function(){return c})),s.d(t,"e",(function(){return h})),s.d(t,"g",(function(){return u})),s.d(t,"b",(function(){return X}));var a=s(10),i=s(8);const n=["January","February","March","April","May","June","July","August","September","October","November","December"],o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],r=86400,d=e=>{const t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())),s=t.getUTCDay()||7;t.setUTCDate(t.getUTCDate()+4-s);const a=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t.getTime()-a.getTime())/r+1)/7)},l=e=>{const t=new Date,s=t.getTime()/1e3|0,a=e.getTime()/1e3|0;let i;return i=s-a<r&&t.getDate()===e.getDate()?("0"+e.getHours()).slice(-2)+":"+("0"+e.getMinutes()).slice(-2):t.getFullYear()!==e.getFullYear()?e.getDate()+"."+("0"+(e.getMonth()+1)).slice(-2)+"."+(""+e.getFullYear()).slice(-2):s-a<7*r&&d(t)===d(e)?o[e.getDay()].slice(0,3):n[e.getMonth()].slice(0,3)+" "+("0"+e.getDate()).slice(-2),i};function c(e){const t=new Date,s=t.getTime()/1e3|0,a=e.getTime()/1e3|0,n={};return s-a<r&&t.getDate()===e.getDate()?n.hour=n.minute="2-digit":t.getFullYear()!==e.getFullYear()?(n.year=n.day="numeric",n.month="2-digit"):s-a<7*r&&d(t)===d(e)?n.weekday="short":(n.month="short",n.day="numeric"),new i.default.IntlDateElement({date:e,options:n}).element}a.a&&(a.a.formatDateAccordingToTodayNew=c);const h=(e,t={})=>{const s=t.monthAsNumber?".":" ",a=("0"+e.getHours()).slice(-2)+":"+("0"+e.getMinutes()).slice(-2)+(t.noSeconds?"":":"+("0"+e.getSeconds()).slice(-2));return(t.leadingZero?("0"+e.getDate()).slice(-2):e.getDate())+s+(t.monthAsNumber?("0"+(e.getMonth()+1)).slice(-2):n[e.getMonth()])+s+e.getFullYear()+(t.noTime?"":", "+a)};function u(e){const t=Date.now();return e?Math.floor(t/1e3):t}const g=new RegExp("20[0-9]{1,2}"),p=new RegExp("(\\w{3,}) ([0-9]{0,4})","i"),m=new RegExp("([0-9]{0,4}) (\\w{2,})","i"),f=new RegExp("^([0-9]{1,4})(\\.| |/|\\-)([0-9]{1,4})$","i"),_=new RegExp("^([0-9]{1,2})(\\.| |/|\\-)([0-9]{1,2})(\\.| |/|\\-)([0-9]{1,4})$","i"),v=[31,29,31,30,31,30,31,31,30,31,30,31];function X(e,t){const s=e.trim().toLowerCase();if(s.length<3)return;if(0==="today".indexOf(s)){const e=new Date,s=e.getFullYear(),a=e.getMonth(),i=e.getDate();e.setFullYear(s,a,i),e.setHours(0,0,0);const n=e.getTime();e.setFullYear(s,a,i+1),e.setHours(0,0,0);const o=e.getTime()-1;return void t.push({title:"Today",minDate:n,maxDate:o})}if(0==="yesterday".indexOf(s)){const e=new Date,s=e.getFullYear(),a=e.getMonth(),i=e.getDate();e.setFullYear(s,a,i),e.setHours(0,0,0);const n=e.getTime()-864e5;e.setFullYear(s,a,i+1),e.setHours(0,0,0);const o=e.getTime()-86400001;return void t.push({title:"Yesterday",minDate:n,maxDate:o})}const a=function(e){const t=new Date;if(e.length<=3)return-1;for(let s=0;s<7;s++)if(t.setDate(t.getDate()+1),0===I(t.getTime()).toLowerCase().indexOf(e))return t.getDay();return-1}(s);if(a>=0){const e=new Date,s=e.getTime(),i=a-e.getDay();e.setDate(e.getDate()+i),e.getTime()>s&&e.setTime(e.getTime()-6048e5);const n=e.getFullYear(),o=e.getMonth(),r=e.getDate();e.setFullYear(n,o,r),e.setHours(0,0,0);const d=e.getTime();e.setFullYear(n,o,r+1),e.setHours(0,0,0);const l=e.getTime()-1;return void t.push({title:I(d),minDate:d,maxDate:l})}let i;if(null===(i=f.exec(s)))if(null===(i=_.exec(s)))if(null===(i=g.exec(s))){if(null!==(i=p.exec(s))){const e=i[1],s=i[2],a=S(e);if(a>=0){const e=+s;if(e>0&&e<=31){return void y(t,e-1,a)}if(e>=2013){return void b(t,a,e)}}}if(null!==(i=m.exec(s))){const e=i[1],s=S(i[2]);if(s>=0){const a=+e;if(a>0&&a<=31){return void y(t,a-1,s)}if(a>=2013){b(t,s,a)}}}}else{let e=+s;const a=(new Date).getFullYear();if(e<2013){e=2013;for(let s=a;s>=e;s--){const e=new Date;e.setFullYear(s,0,1),e.setHours(0,0,0);const a=e.getTime();e.setFullYear(s+1,0,1),e.setHours(0,0,0);const i=e.getTime()-1;t.push({title:""+s,minDate:a,maxDate:i})}}else if(e<=a){const s=new Date;s.setFullYear(e,0,1),s.setHours(0,0,0);const a=s.getTime();s.setFullYear(e+1,0,1),s.setHours(0,0,0);const i=s.getTime()-1;t.push({title:""+e,minDate:a,maxDate:i})}}else{const e=i[1],s=i[3],a=i[5];if(!i[2]===i[4])return;const n=parseInt(e),o=parseInt(s)-1;let r=parseInt(a);r>=10&&r<=99&&(r+=2e3);const d=(new Date).getFullYear();if(w(n-1,o)&&r>=2013&&r<=d){const e=new Date;e.setFullYear(r,o,n),e.setHours(0,0,0);const s=e.getTime();e.setFullYear(r,o,n+1),e.setHours(0,0,0);const a=e.getTime()-1;return void t.push({title:M(s),minDate:s,maxDate:a})}}else{const e=i[1],s=i[3],a=parseInt(e),n=parseInt(s);if(a>0&&a<=31){if(n>=2013&&a<=12){return void b(t,a-1,n)}if(n<=12){y(t,a-1,n-1)}}else if(a>=2013&&n<=12){b(t,n-1,a)}}}function b(e,t,s){const a=(new Date).getFullYear(),i=Date.now();if(s>=2013&&s<=a){const a=new Date;a.setFullYear(s,t,1),a.setHours(0,0,0);const n=a.getTime();if(n>i)return;a.setMonth(a.getMonth()+1);const o=a.getTime()-1;e.push({title:C(n),minDate:n,maxDate:o})}}function y(e,t,s){if(w(t,s)){const i=(new Date).getFullYear(),n=Date.now();for(let o=i;o>=2013;o--){if(1===s&&28===t&&(((a=o)%4!=0||a%100==0)&&a%400!=0))continue;const r=new Date;r.setFullYear(o,s,t+1),r.setHours(0,0,0);const d=r.getTime();if(d>n)continue;r.setFullYear(o,s,t+2),r.setHours(0,0,0);const l=r.getTime()-1;o===i?e.push({title:P(d),minDate:d,maxDate:l}):e.push({title:M(d),minDate:d,maxDate:l})}}var a}function C(e){const t=new Date(e);return n[t.getMonth()].slice(0,3)+" "+t.getFullYear()}function P(e){const t=new Date(e);return n[t.getMonth()].slice(0,3)+" "+t.getDate()}function M(e){const t=new Date(e);return("0"+t.getDate()).slice(-2)+"."+("0"+(t.getMonth()+1)).slice(-2)+"."+t.getFullYear()}function I(e){const t=new Date(e);return o[t.getDay()]}function w(e,t){return t>=0&&t<12&&e>=0&&e<v[t]}function S(e){e=e.toLowerCase();for(let t=0;t<12;t++){if(0===n[t].toLowerCase().indexOf(e))return t}return-1}a.a.fillTipDates=X},,,function(e,t,s){"use strict";s.r(t),s.d(t,"AppProfileManager",(function(){return v}));var a=s(10),i=s(31),n=s(7),o=s(52),r=s(55),d=s(13),l=s(11),c=s(9),h=s(51),u=s(25),g=s(53),p=s(58),m=s(24),f=s(35),_=s(18);class v{constructor(){this.botInfos={},this.usersFull={},this.chatsFull={},this.fullPromises={},this.savedAvatarURLs={},c.default.addMultipleEventsListeners({updateChatParticipants:e=>{const t=e.participants;if("chatParticipants"===t._){const e=t.chat_id,s=this.chatsFull[e];void 0!==s&&(s.participants=t,c.default.broadcast("chat_full_update",e))}},updateChatParticipantAdd:e=>{const t=this.chatsFull[e.chat_id];if(void 0!==t){const s=t.participants,a=s.participants||[];for(let t=0,s=a.length;t<s;t++)if(a[t].user_id===e.user_id)return;a.push({_:"chatParticipant",user_id:e.user_id,inviter_id:e.inviter_id,date:Object(i.g)(!0)}),s.version=e.version,c.default.broadcast("chat_full_update",e.chat_id)}},updateChatParticipantDelete:e=>{const t=this.chatsFull[e.chat_id];if(void 0!==t){const s=t.participants,a=s.participants||[];for(let t=0,i=a.length;t<i;t++)if(a[t].user_id===e.user_id)return a.splice(t,1),s.version=e.version,void c.default.broadcast("chat_full_update",e.chat_id)}}}),c.default.on("chat_update",e=>{const t=this.chatsFull[e],s=u.a.getChat(e);if(!s.photo||!t)return;const a="chatPhotoEmpty"===s.photo._;if(t.chat_photo&&a!==("photoEmpty"===t.chat_photo._))return delete this.chatsFull[e],void c.default.broadcast("chat_full_update",e);if(a)return;const i=s.photo.photo_small,n=t.chat_photo?f.a.choosePhotoSize(t.chat_photo,0,0):void 0;n&&JSON.stringify(i)===JSON.stringify(n.location)||(delete this.chatsFull[e],c.default.broadcast("chat_full_update",e))})}saveBotInfo(e){const t=e&&e.user_id;if(!t)return null;const s={};return e.commands.forEach(e=>{s[e.command]=e.description}),this.botInfos[t]={id:t,version:e.version,shareText:e.share_text,description:e.description,commands:s}}getProfile(e,t){return this.usersFull[e]&&!t?Promise.resolve(this.usersFull[e]):this.fullPromises[e]?this.fullPromises[e]:this.fullPromises[e]=d.a.invokeApi("users.getFullUser",{id:_.a.getUserInput(e)}).then(t=>{const s=t.user;return _.a.saveApiUser(s,!0),t.profile_photo&&(t.profile_photo=f.a.savePhoto(t.profile_photo,{type:"profilePhoto",peerId:e})),void 0!==t.about&&(t.rAbout=l.a.wrapRichText(t.about,{noLinebreaks:!0})),p.a.savePeerSettings(e,t.notify_settings),t.bot_info&&(t.bot_info=this.saveBotInfo(t.bot_info)),delete this.fullPromises[e],this.usersFull[e]=t})}getProfileByPeerId(e,t){return e<0?this.getChatFull(-e,t):this.getProfile(e,t)}getFullPhoto(e){return this.getProfileByPeerId(e).then(e=>{switch(e._){case"userFull":return e.profile_photo;case"channelFull":case"chatFull":return e.chat_photo}})}getChatFull(e,t){if(u.a.isChannel(e))return this.getChannelFull(e,t);const s=this.chatsFull[e];if(s&&!t){const t=u.a.getChat(e);if(t.version===s.participants.version||t.pFlags.left)return Promise.resolve(s)}const a=-e;return void 0!==this.fullPromises[a]?this.fullPromises[a]:this.fullPromises[a]=d.a.invokeApi("messages.getFullChat",{chat_id:e}).then(t=>{u.a.saveApiChats(t.chats,!0),_.a.saveApiUsers(t.users);const s=t.full_chat;return s&&s.chat_photo&&s.chat_photo.id&&(s.chat_photo=f.a.savePhoto(s.chat_photo,{type:"profilePhoto",peerId:a})),p.a.savePeerSettings(a,s.notify_settings),delete this.fullPromises[a],this.chatsFull[e]=s,c.default.broadcast("chat_full_update",e),s})}getChatInviteLink(e,t){return this.getChatFull(e).then(s=>!t&&s.exported_invite&&"chatInviteExported"==s.exported_invite._?s.exported_invite.link:d.a.invokeApi("messages.exportChatInvite",{peer:m.a.getInputPeerById(-e)}).then(t=>(void 0!==this.chatsFull[e]&&(this.chatsFull[e].exported_invite=t),t.link)))}getChannelParticipants(e,t={_:"channelParticipantsRecent"},s=200,a=0){if("channelParticipantsRecent"===t._){const t=u.a.getChat(e);if(t&&t.pFlags&&(t.pFlags.kicked||t.pFlags.broadcast&&!t.pFlags.creator&&!t.admin_rights))return Promise.reject()}return d.a.invokeApiCacheable("channels.getParticipants",{channel:u.a.getChannelInput(e),filter:t,offset:a,limit:s,hash:0},{cacheSeconds:60}).then(e=>(_.a.saveApiUsers(e.users),e))}getChannelParticipant(e,t){return d.a.invokeApiSingle("channels.getParticipant",{channel:u.a.getChannelInput(e),user_id:_.a.getUserInput(t)}).then(e=>(_.a.saveApiUsers(e.users),e.participant))}getChannelFull(e,t){if(void 0!==this.chatsFull[e]&&!t)return Promise.resolve(this.chatsFull[e]);const s=-e;return void 0!==this.fullPromises[s]?this.fullPromises[s]:this.fullPromises[s]=d.a.invokeApi("channels.getFullChannel",{channel:u.a.getChannelInput(e)}).then(t=>{u.a.saveApiChats(t.chats,!0),_.a.saveApiUsers(t.users);const a=t.full_chat;return a&&a.chat_photo.id&&(a.chat_photo=f.a.savePhoto(a.chat_photo,{type:"profilePhoto",peerId:s})),p.a.savePeerSettings(s,a.notify_settings),delete this.fullPromises[s],this.chatsFull[e]=a,c.default.broadcast("chat_full_update",e),a},t=>{switch(t.type){case"CHANNEL_PRIVATE":let t=u.a.getChat(e);t={_:"channelForbidden",access_hash:t.access_hash,title:t.title},h.a.processUpdateMessage({_:"updates",updates:[{_:"updateChannel",channel_id:e}],chats:[t],users:[]})}return Promise.reject(t)})}invalidateChannelParticipants(e){delete this.chatsFull[e],delete this.fullPromises[-e],d.a.clearCache("channels.getParticipants",t=>t.channel.channel_id===e),c.default.broadcast("chat_full_update",e)}updateProfile(e,t,s){return d.a.invokeApi("account.updateProfile",{first_name:e,last_name:t,about:s}).then(e=>(_.a.saveApiUser(e),this.getProfile(c.default.myId,!0)))}uploadProfilePhoto(e){return d.a.invokeApi("photos.uploadProfilePhoto",{file:e}).then(e=>{_.a.saveApiUsers(e.users);const t=c.default.myId;f.a.savePhoto(e.photo,{type:"profilePhoto",peerId:t}),h.a.processUpdateMessage({_:"updateShort",update:{_:"updateUserPhoto",user_id:t,date:Object(i.g)(!0),photo:_.a.getUser(t).photo,previous:!0}})})}removeFromAvatarsCache(e){this.savedAvatarURLs[e]&&delete this.savedAvatarURLs[e]}loadAvatar(e,t,s){const a=m.a.getInputPeerById(e);let i,n=!1,o=this.savedAvatarURLs[e];if(o&&o[s])"string"!=typeof o[s]?i=o[s]:(i=Promise.resolve(o[s]),n=!0);else{o||(o=this.savedAvatarURLs[e]={});const n={_:"inputPeerPhotoFileLocation",pFlags:{},peer:a,volume_id:t[s].volume_id,local_id:t[s].local_id};"photo_big"===s&&(n.pFlags.big=!0);const r={dcId:t.dc_id,location:n},d=g.a.download(r);i=o[s]=d.then(e=>o[s]=URL.createObjectURL(e))}return{cached:n,loadPromise:i}}putAvatar(e,t,s,a,i=new Image){const{cached:d,loadPromise:l}=this.loadAvatar(t,s,a);let h;if(d)h=()=>{Object(n.z)(e,i),e.dataset.color=""};else{const t=c.default.settings.animationsEnabled;t&&i.classList.add("fade-in"),h=()=>{Object(n.z)(e,i),setTimeout(()=>{e.childElementCount&&(e.dataset.color="",t&&r.a.mutateElement(i,()=>{i.classList.remove("fade-in")}))},t?200:0)}}return{cached:d,loadPromise:l.then(e=>new Promise(t=>{Object(o.a)(i,e,()=>{h(),t()})}))}}putPhoto(e,t,s=!1,a=""){var i;const n=m.a.getPeerPhoto(t),o=n&&n.photo_small,r=!!e.firstElementChild,d=c.default.myId;if(t===d&&s)return e.innerText="",e.dataset.color="",e.classList.add("tgico-saved"),void e.classList.remove("tgico-deletedaccount");if(t>0){const s=_.a.getUser(t);if(s&&s.pFlags&&s.pFlags.deleted)return e.innerText="",e.dataset.color=m.a.getPeerColorById(t),e.classList.add("tgico-deletedaccount"),void e.classList.remove("tgico-saved")}if(!o||!r||!this.savedAvatarURLs[t]){let n,o="";!t||t===d&&s||(o=m.a.getPeerColorById(t)),e.innerText="",e.classList.remove("tgico-saved","tgico-deletedaccount"),e.dataset.color=o,n=a?l.a.getAbbreviation(a):null!==(i=m.a.getPeer(t).initials)&&void 0!==i?i:"",e.innerHTML=n}return o?this.putAvatar(e,t,n,"photo_small"):void 0}}const X=new v;a.a.appProfileManager=X,t.default=X},function(e,t,s){"use strict";var a=s(60),i=s(72),n=s(15),o=s(1),r=s(13),d=s(70),l=s(7),c=s(53),h=s(18),u=s(89),g=s(10),p=s(52);class m{constructor(){this.photos={},this.documentThumbsCache={},this.windowW=0,this.windowH=0;const e="visualViewport"in window?window.visualViewport:window,t=()=>{this.windowW=e.width||e.innerWidth,this.windowH=e.height||e.innerHeight};e.addEventListener("resize",t),t()}savePhoto(e,t){var s;if("photoEmpty"===e._)return;const a=this.photos[e.id];if(e.file_reference&&(Object(n.h)("file_reference",a,e),d.a.saveContext(e.file_reference,t)),null===(s=e.sizes)||void 0===s?void 0:s.length){const t=e.sizes[e.sizes.length-1];"photoSizeProgressive"===t._&&(t.size=t.sizes[t.sizes.length-1])}return a?Object.assign(a,e):this.photos[e.id]=e}choosePhotoSize(e,t=0,s=0,a=!1){window.devicePixelRatio>1&&(t*=2,s*=2);let i={_:"photoSizeEmpty",type:""};const n=e.sizes||e.thumbs;if(null==n?void 0:n.length){for(const e of n){if(!("w"in e)&&!("h"in e))continue;i=e;const{w:a,h:n}=Object(l.d)(e.w,e.h,t,s);if(a>=t||n>=s)break}a&&"photoSizeEmpty"===i._&&"photoStrippedSize"===n[0]._&&(i=n[0])}return i}getUserPhotos(e,t="0",s=20){const a=h.a.getUserInput(e);return r.a.invokeApiCacheable("photos.getUserPhotos",{user_id:a,offset:0,limit:s,max_id:t},{cacheSeconds:60}).then(t=>{h.a.saveApiUsers(t.users);const s=t.photos.map((s,a)=>(t.photos[a]=this.savePhoto(s,{type:"profilePhoto",peerId:e}),s.id));return{count:t.count||t.photos.length,photos:s}})}getPreviewURLFromBytes(e,t=!1){let s,a;t?s=e instanceof Uint8Array?e:new Uint8Array(e):(s=m.jf.concat(e.slice(3),m.Df),s[164]=e[1],s[166]=e[2]),a=t?o.isSafari?"image/png":"image/webp":"image/jpeg";const i=new Blob([s],{type:a});return URL.createObjectURL(i)}getPathFromPhotoPathSize(e){const t=e.bytes;let s="M";for(let e=0,a=t.length;e<a;++e){const a=t[e];a>=192?s+="AACAAAAHAAALMAAAQASTAVAAAZaacaaaahaaalmaaaqastava.az0123456789-,"[a-128-64]:(a>=128?s+=",":a>=64&&(s+="-"),s+=""+(63&a))}return s+="z",s}getPreviewURLFromThumb(e,t=!1){var s;return null!==(s=e.url)&&void 0!==s?s:(Object(n.c)(e,["url"]),e.url=this.getPreviewURLFromBytes(e.bytes,t))}getImageFromStrippedThumb(e,t){const s=this.getPreviewURLFromThumb(e,!1),a=new Image;a.classList.add("thumbnail");const i=(t?Object(u.a)(s):Promise.resolve(s)).then(e=>new Promise(t=>{Object(p.a)(a,e,t)}));return{image:a,loadPromise:i}}setAttachmentSize(e,t,s,a,i=!0,n){const o=this.choosePhotoSize(e,s,a);let r,d;"document"===e._?(r=e.w||512,d=e.h||512):(r="w"in o?o.w:100,d="h"in o?o.h:100);let{w:c,h:h}=Object(l.d)(r,d,s,a,i);return t instanceof SVGForeignObjectElement?(t.setAttributeNS(null,"width",""+c),t.setAttributeNS(null,"height",""+h)):(t.style.width=c+"px",t.style.height=h+"px"),o}getStrippedThumbIfNeeded(e,t){if(!e.downloaded||"video"===e.type||"gif"===e.type){if("document"===e._){if(this.getCacheContext(e).downloaded)return null}const s=e.sizes||e.thumbs,a=(null==s?void 0:s.length)?s.find(e=>"photoStrippedSize"===e._):null;if(a&&"bytes"in a)return f.getImageFromStrippedThumb(a,t)}return null}getPhotoDownloadOptions(e,t,s,a){const i="document"===e._;if(!t||"photoSizeEmpty"===t._)throw new Error("photoSizeEmpty!");const n=("photoSize"===t._||"photoSizeProgressive"===t._)&&e.access_hash&&e.file_reference,o=n?{_:i?"inputDocumentFileLocation":"inputPhotoFileLocation",id:e.id,access_hash:e.access_hash,file_reference:e.file_reference,thumb_size:t.type}:t.location;return{dcId:e.dc_id,location:o,size:n?t.size:void 0,queueId:s,onlyCache:a}}isDownloaded(e){const t="photo"===e._?this.getPhoto(e.id):null;let s;if(t)s=t.downloaded>0;else{const t=this.getDocumentCachedThumb(e.id);s=(null==t?void 0:t.downloaded)>0}return s}preloadPhoto(e,t,s,a){const o=this.getPhoto(e);if(!o||"photoEmpty"===o._)throw new Error("preloadPhoto photoEmpty!");if(!t){const e=this.windowW,s=this.windowH;t=this.choosePhotoSize(o,e,s)}const r=this.getCacheContext(o);if(r.downloaded>=("size"in t?t.size:0)&&r.url)return Promise.resolve();const d=this.getPhotoDownloadOptions(o,t,s,a),l=Object(i.a)(d.location);let h=c.a.getDownload(l);return h||(h=c.a.download(d),h.then(e=>{const s=URL.createObjectURL(e);return(!r.downloaded||r.downloaded<e.size)&&(Object(n.c)(r,["downloaded","url"]),r.downloaded=e.size,r.url=s),Object(n.c)(t,["url"]),t.url=s,e}).catch(()=>{}),h)}getCacheContext(e){return"document"===e._?this.getDocumentCachedThumb(e.id):e}getDocumentCachedThumb(e){var t;return null!==(t=this.documentThumbsCache[e])&&void 0!==t?t:this.documentThumbsCache[e]={downloaded:0,url:""}}getPhoto(e){return Object(n.f)(e)?e:this.photos[e]}getInput(e){return{_:"inputMediaPhoto",id:{_:"inputPhoto",id:e.id,access_hash:e.access_hash,file_reference:e.file_reference},ttl_seconds:0}}savePhotoFile(e,t){const s=this.choosePhotoSize(e,65535,65535);if("photoSize"!==s._&&"photoSizeProgressive"!==s._)return;const a={_:"document"===e._?"inputDocumentFileLocation":"inputPhotoFileLocation",id:e.id,access_hash:e.access_hash,file_reference:e.file_reference,thumb_size:s.type};c.a.downloadToDisc({dcId:e.dc_id,location:a,size:s.size,fileName:"photo"+e.id+".jpg",queueId:t},"photo"+e.id+".jpg")}}m.jf=new Uint8Array(Object(a.c)("ffd8ffe000104a46494600010100000100010000ffdb004300281c1e231e19282321232d2b28303c64413c37373c7b585d4964918099968f808c8aa0b4e6c3a0aadaad8a8cc8ffcbdaeef5ffffff9bc1fffffffaffe6fdfff8ffdb0043012b2d2d3c353c76414176f8a58ca5f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8ffc00011080000000003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00")),m.Df=Object(a.c)("ffd9");const f=new m;g.a.appPhotosManager=f,t.a=f},,,function(e,t,s){"use strict";var a=s(72),i=s(15),n=s(70),o=s(92),r=s(11),d=s(81),l=s(53),c=s(35),h=s(89),u=s(13),g=s(10),p=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};const m=new class{constructor(){this.docs={},this.savingLottiePreview={}}onServiceWorkerFail(){for(const e in this.docs){const t=this.docs[e];delete t.supportsStreaming,delete t.url}}saveDoc(e,t){if("documentEmpty"===e._)return;const s=this.docs[e.id];if(e.file_reference&&(Object(i.h)("file_reference",s,e),n.a.saveContext(e.file_reference,t)),s)return e.thumbs&&(s.thumbs||(s.thumbs=e.thumbs)),s;if(this.docs[e.id]=e,Object(i.c)(e,["downloaded","url"]),e.attributes.forEach(t=>{switch(t._){case"documentAttributeFilename":e.file_name=r.a.wrapPlainText(t.file_name);break;case"documentAttributeAudio":e.duration=t.duration,e.audioTitle=t.title,e.audioPerformer=t.performer,e.type=t.pFlags.voice&&"audio/ogg"===e.mime_type?"voice":"audio";break;case"documentAttributeVideo":e.duration=t.duration,e.w=t.w,e.h=t.h,t.pFlags.round_message?e.type="round":e.type="video";break;case"documentAttributeSticker":void 0!==t.alt&&(e.stickerEmojiRaw=t.alt,e.stickerEmoji=r.a.wrapRichText(e.stickerEmojiRaw,{noLinks:!0,noLinebreaks:!0})),t.stickerset&&("inputStickerSetEmpty"===t.stickerset._?delete t.stickerset:"inputStickerSetID"===t.stickerset._&&(e.stickerSetInput=t.stickerset)),"image/webp"===e.mime_type&&(e.thumbs||d.a.isWebpSupported())&&(e.type="sticker",e.sticker=1);break;case"documentAttributeImageSize":e.type="photo",e.w=t.w,e.h=t.h;break;case"documentAttributeAnimated":"image/gif"!==e.mime_type&&"video/mp4"!==e.mime_type||(e.type="gif"),e.animated=!0}}),!e.mime_type)switch(e.type){case"gif":case"video":case"round":e.mime_type="video/mp4";break;case"sticker":e.mime_type="image/webp";break;case"audio":e.mime_type="audio/mpeg";break;case"voice":e.mime_type="audio/ogg";break;default:e.mime_type="application/octet-stream"}return u.a.isServiceWorkerOnline()&&("gif"===e.type&&e.size>8e6||"audio"===e.type||"video"===e.type)&&(e.supportsStreaming=!0,e.url||(e.url=this.getFileURL(e))),e.file_name||(e.file_name=""),"application/x-tgsticker"===e.mime_type&&"AnimatedSticker.tgs"===e.file_name&&(e.type="sticker",e.animated=!0,e.sticker=2),e}getDoc(e){return Object(i.f)(e)&&"string"!=typeof e?e:this.docs[e]}getMediaInput(e){return{_:"inputMediaDocument",id:{_:"inputDocument",id:e.id,access_hash:e.access_hash,file_reference:e.file_reference},ttl_seconds:0}}getInput(e,t){return{_:"inputDocumentFileLocation",id:e.id,access_hash:e.access_hash,file_reference:e.file_reference,thumb_size:t}}getFileDownloadOptions(e,t,s,a){const i=this.getInput(e,null==t?void 0:t.type);let n;return n=t?e.sticker?"image/webp":"image/jpeg":e.mime_type||"application/octet-stream",{dcId:e.dc_id,location:i,size:t?t.size:e.size,mimeType:n,fileName:e.file_name,queueId:s,onlyCache:a}}getFileURL(e,t=!1,s){let i;return i=t?"download":s?"thumb":e.supportsStreaming?"stream":"document",Object(a.b)(i,this.getFileDownloadOptions(e,s))}getThumbURL(e,t){let s=Promise.resolve();return t.url||(s="bytes"in t?Object(h.a)(c.a.getPreviewURLFromBytes(t.bytes,!!e.sticker)).then(s=>{Object(i.c)(t,["url"]);c.a.getCacheContext(e).url=t.url=s}):c.a.preloadPhoto(e,t)),{thumb:t,promise:s}}getThumb(e,t=!0){const s=c.a.choosePhotoSize(e,0,0,!t);return"photoSizeEmpty"===s._?null:this.getThumbURL(e,s)}getInputFileName(e,t){return Object(a.a)(this.getInput(e,t),{fileName:e.file_name})}downloadDoc(e,t,s){const a=this.getInputFileName(e);let i=l.a.getDownload(a);if(i)return i;const n=this.getFileDownloadOptions(e,void 0,t,s);i=l.a.download(n);const r=i;return r.then(t=>{e.url=URL.createObjectURL(t),e.downloaded=!0},()=>{}),"voice"!==e.type||o.a.isPlaySupported()||(i=r.then(t=>p(this,void 0,void 0,(function*(){const s=new FileReader;return yield new Promise((a,i)=>{s.onloadend=t=>{const s=new Uint8Array(t.target.result);o.a.decode(s).then(t=>{e.url=t.url,a()},t=>{delete e.downloaded,i(t)})},s.readAsArrayBuffer(t)}),t})))),i}saveLottiePreview(e,t,s){const a=e.id+"-"+s;if(this.savingLottiePreview[a])return;e.stickerCachedThumbs||(Object(i.c)(e,["stickerCachedThumbs"]),e.stickerCachedThumbs={});const n=e.stickerCachedThumbs[s];n&&n.w>=t.width&&n.h>=t.height||(this.savingLottiePreview[a]=!0,t.toBlob(i=>{const n={url:URL.createObjectURL(i),w:t.width,h:t.height};e.stickerCachedThumbs[s]=n,delete this.savingLottiePreview[a]}))}saveDocFile(e,t){const s=this.downloadDoc(e,t);return s.then(()=>{l.a.createDownloadAnchor(e.url,e.file_name)}),s}};g.a.appDocsManager=m,t.a=m},,,function(e,t,s){"use strict";s.d(t,"a",(function(){return l}));var a=s(10),i=s(24),n=s(9),o=s(7),r=s(8);const d=new WeakMap;a.a.peerTitleWeakMap=d,n.default.on("peer_title_edit",e=>{Array.from(document.querySelectorAll(`.peer-title[data-peer-id="${e}"]`)).forEach(e=>{const t=d.get(e);t&&t.update()})});class l{constructor(e){this.plainText=!1,this.onlyFirstName=!1,this.dialog=!1,this.element=document.createElement("span"),this.element.classList.add("peer-title"),this.update(e),d.set(this.element,this)}update(e){if(e)for(let t in e)this.element.dataset[t]=e[t]?""+("boolean"==typeof e[t]?+e[t]:e[t]):"0",this[t]=e[t];this.peerId===n.default.myId&&this.dialog?Object(o.z)(this.element,Object(r.i18n)(this.onlyFirstName?"Saved":"SavedMessages")):this.element.innerHTML=i.a.getPeerTitle(this.peerId,this.plainText,this.onlyFirstName)}}},function(e,t,s){"use strict";function a(e){return Math.floor(Math.random()*e)}function i(){return""+a(4294967295)+a(16777215)}s.d(t,"a",(function(){return a})),s.d(t,"b",(function(){return i}))},,function(e,t,s){"use strict";var a=s(10),i=s(1),n=s(7),o=s(26),r=s(16);const d=new class{constructor(){this.navigations=[],this.id=Date.now(),this.manual=!1,this.log=Object(o.b)("NC"),this.debug=!0,this.currentHash=window.location.hash;let e=!1;if(window.addEventListener("popstate",t=>{if(this.debug&&this.log("popstate",t,e),window.location.hash!==this.currentHash)return this.onHashChange&&this.onHashChange(),void this.replaceState();this.currentHash=window.location.hash;if(t.state!==this.id)return void this.pushState();const s=this.navigations.pop();s?(this.manual=!e,this.handleItem(s)):this.pushState()}),window.addEventListener("keydown",e=>{const t=this.navigations[this.navigations.length-1];t&&("Escape"!==e.key||t.onEscape&&!t.onEscape()||(Object(n.f)(e),this.back()))},{capture:!0}),i.isMobileSafari){const t={passive:!0};window.addEventListener("touchstart",s=>{if(s.touches.length>1)return;this.debug&&this.log("touchstart");const a=()=>{window.removeEventListener("touchend",o),window.removeEventListener("touchmove",n)};let i=!1;const n=e=>{this.debug&&this.log("touchmove"),e.touches.length>1?a():i=!0},o=t=>{this.debug&&this.log("touchend"),t.touches.length>1||!i||(e=!0,Object(r.b)().then(()=>{e=!1})),a()};window.addEventListener("touchend",o,t),window.addEventListener("touchmove",n,t)},t)}history.scrollRestoration="manual",this.pushState()}handleItem(e){const t=e.onPop(!!this.manual&&void 0);this.debug&&this.log("popstate, navigation:",e,this.navigations),!1===t?this.pushItem(e):Object(n.c)(),this.manual=!1}findItemByType(e){for(let t=this.navigations.length-1;t>=0;--t){const s=this.navigations[t];if(s.type===e)return{item:s,index:t}}}back(e){if(e){const t=this.findItemByType(e);if(t)return this.manual=!0,this.navigations.splice(t.index,1),void this.handleItem(t.item)}history.back()}pushItem(e){this.navigations.push(e),this.debug&&this.log("pushstate",e,this.navigations),e.noHistory||this.pushState()}pushState(){this.manual=!1,history.pushState(this.id,"")}replaceState(){history.replaceState(this.id,"",location.origin+location.pathname)}removeItem(e){this.navigations.findAndSplice(t=>t===e)}removeByType(e,t=!1){for(let s=this.navigations.length-1;s>=0;--s){if(this.navigations[s].type===e&&(this.navigations.splice(s,1),t))break}}};a.a.appNavigationController=d,t.a=d},,,function(e,t,s){"use strict";s.d(t,"a",(function(){return a})),s.d(t,"b",(function(){return i})),s.d(t,"c",(function(){return n})),s.d(t,"d",(function(){return o}));const a=(e,t)=>e.reduce((e,t)=>e+t,t);function i(e,t){const s=[];let a=-1;for(;-1!==(a=e.findIndex(t));)s.push(e.splice(a,1)[0]);return s}function n(e,t){for(let s=e.length-1;s>=0;--s)t(e[s],s,e)}function o(e,t,s,a){void 0===a&&-1!==(a=e.indexOf(t))&&e.splice(a,1);const i=t[s],n=e.length;if(!n||i<=e[n-1][s])return e.push(t)-1;if(i>=e[0][s])return e.unshift(t),0;for(let a=0;a<n;a++)if(i>e[a][s])return e.splice(a,0,t),a;return console.error("wtf",e,t),e.indexOf(t)}},function(e,t,s){"use strict";function a(e,t=" "){const s=e.toString().split(".");return s[0]=s[0].replace(/\B(?=(\d{3})+(?!\d))/g,t),s.join(".")}function i(e,t=2){if(0===e)return"0 Bytes";const s=t<0?0:t,a=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,a)).toFixed(s))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][a]}function n(e,t=2){if(0===e)return"0";const s=t<0?0:t,a=Math.floor(Math.log(e)/Math.log(1e3));return parseFloat((e/Math.pow(1e3,a)).toFixed(s))+["","K","M","B","T"][a]}function o(e,t,s){return e<t?t:e>s?s:e}s.d(t,"d",(function(){return a})),s.d(t,"b",(function(){return i})),s.d(t,"c",(function(){return n})),s.d(t,"a",(function(){return o}))},,,function(e,t,s){"use strict";var a=s(10),i=s(15),n=s(26),o=s(13),r=s(9),d=s(25),l=s(24),c=s(14),h=s(18),u=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};const g=new class{constructor(){this.updatesState={pendingPtsUpdates:[],pendingSeqUpdates:{},syncPending:null,syncLoading:null},this.channelStates={},this.attached=!1,this.log=Object(n.b)("UPDATES",n.a.error|n.a.log|n.a.warn|n.a.debug),this.debug=a.b,this.processUpdateMessage=e=>{const t={date:e.date,seq:e.seq,seqStart:e.seq_start};switch(this.debug&&this.log("processUpdateMessage",e),e._){case"updatesTooLong":case"new_session_created":this.forceGetDifference();break;case"updateShort":this.processUpdate(e.update,t);break;case"updateShortMessage":case"updateShortChatMessage":{this.debug&&this.log("updateShortMessage | updateShortChatMessage",Object.assign({},e));const s=e.pFlags.out,a=e.from_id||(s?r.default.myId:e.user_id),i=e.chat_id?-e.chat_id:e.user_id||r.default.myId;this.processUpdate({_:"updateNewMessage",message:{_:"message",pFlags:e.pFlags,id:e.id,from_id:l.a.getOutputPeer(a),peer_id:l.a.getOutputPeer(i),date:e.date,message:e.message,fwd_from:e.fwd_from,reply_to:e.reply_to,entities:e.entities},pts:e.pts,pts_count:e.pts_count},t);break}case"updatesCombined":case"updates":h.a.saveApiUsers(e.users),d.a.saveApiChats(e.chats),e.updates.forEach(e=>{this.processUpdate(e,t)});break;default:this.log.warn("Unknown update message",e)}}}popPendingSeqUpdate(){const e=this.updatesState,t=e.seq+1,s=e.pendingSeqUpdates[t];if(!s)return!1;const a=s.updates;for(let e=0,t=a.length;e<t;++e)this.saveUpdate(a[e]);return e.seq=s.seq,s.date&&e.date<s.date&&(e.date=s.date),delete e.pendingSeqUpdates[t],!this.popPendingSeqUpdate()&&e.syncPending&&e.syncPending.seqAwaiting&&e.seq>=e.syncPending.seqAwaiting&&(e.syncPending.ptsAwaiting?delete e.syncPending.seqAwaiting:(clearTimeout(e.syncPending.timeout),e.syncPending=null)),!0}popPendingPtsUpdate(e){const t=e?this.getChannelState(e):this.updatesState;if(!t.pendingPtsUpdates.length)return!1;t.pendingPtsUpdates.sort((e,t)=>e.pts-t.pts);let s=t.pts,a=0,i=0;for(let e=0,n=t.pendingPtsUpdates.length;e<n;++e){const n=t.pendingPtsUpdates[e];s+=n.pts_count,s>=n.pts&&(a=n.pts,i=e)}if(!a)return!1;this.debug&&this.log("pop pending pts updates",a,t.pendingPtsUpdates.slice(0,i+1)),t.pts=a;for(let e=0;e<=i;++e){const s=t.pendingPtsUpdates[e];this.saveUpdate(s)}return t.pendingPtsUpdates.splice(0,i+1),!t.pendingPtsUpdates.length&&t.syncPending&&(t.syncPending.seqAwaiting?delete t.syncPending.ptsAwaiting:(clearTimeout(t.syncPending.timeout),t.syncPending=null)),!0}forceGetDifference(){this.updatesState.syncLoading||this.getDifference()}getDifference(e=!1){const t=this.updatesState;let s=t.syncLoading;s||(t.pendingSeqUpdates={},t.pendingPtsUpdates=[]),t.syncPending&&(clearTimeout(t.syncPending.timeout),t.syncPending=null);const a=o.a.invokeApi("updates.getDifference",{pts:t.pts,date:t.date,qts:-1},{timeout:2147483647}).then(s=>{if(this.debug&&this.log("Get diff result",s),"updates.differenceEmpty"===s._)return this.debug&&this.log("apply empty diff",s.seq),t.date=s.date,void(t.seq=s.seq);if(e&&r.default.broadcast("state_synchronizing"),"updates.differenceTooLong"!==s._){h.a.saveApiUsers(s.users),d.a.saveApiChats(s.chats),s.other_updates.forEach(e=>{switch(e._){case"updateChannelTooLong":case"updateNewChannelMessage":case"updateEditChannelMessage":return void this.processUpdate(e)}this.saveUpdate(e)}),s.new_messages.forEach(e=>{this.saveUpdate({_:"updateNewMessage",message:e,pts:t.pts,pts_count:0})});const e="updates.difference"===s._?s.state:s.intermediate_state;t.seq=e.seq,t.pts=e.pts,t.date=e.date}else t.pts=s.pts,delete t.seq,delete t.date;if("updates.differenceSlice"===s._)return this.getDifference();this.debug&&this.log("finished get diff")});return s||this.justAName(t,a),a}getChannelDifference(e){const t=this.getChannelState(e),s=t.syncLoading;s||(t.pendingPtsUpdates=[]),t.syncPending&&(clearTimeout(t.syncPending.timeout),t.syncPending=null);const a=o.a.invokeApi("updates.getChannelDifference",{channel:d.a.getChannelInput(e),filter:{_:"channelMessagesFilterEmpty"},pts:t.pts,limit:30},{timeout:2147483647}).then(s=>{if(this.debug&&this.log("Get channel diff result",s),t.pts="pts"in s?s.pts:void 0,"updates.channelDifferenceEmpty"!==s._){if("updates.channelDifferenceTooLong"===s._)return this.debug&&this.log("channel diff too long",s),delete this.channelStates[e],void this.saveUpdate({_:"updateChannelReload",channel_id:e});if(h.a.saveApiUsers(s.users),d.a.saveApiChats(s.chats),this.debug&&this.log("applying",s.other_updates.length,"channel other updates"),s.other_updates.forEach(e=>{this.saveUpdate(e)}),this.debug&&this.log("applying",s.new_messages.length,"channel new messages"),s.new_messages.forEach(e=>{this.saveUpdate({_:"updateNewChannelMessage",message:e,pts:t.pts,pts_count:0})}),this.debug&&this.log("apply channel diff",t.pts),"updates.channelDifference"===s._&&!s.pFlags.final)return this.getChannelDifference(e);this.debug&&this.log("finished channel get diff")}else this.debug&&this.log("apply channel empty diff",s)});return s||this.justAName(t,a,e),a}justAName(e,t,s){e.syncLoading=t,r.default.broadcast("state_synchronizing",s),t.then(()=>{e.syncLoading=null,r.default.broadcast("state_synchronized",s)},()=>{e.syncLoading=null})}addChannelState(e,t){if(!t)throw new Error("Add channel state without pts "+e);return!(e in this.channelStates)&&(this.channelStates[e]={pts:t,pendingPtsUpdates:[],syncPending:null,syncLoading:null},!0)}getChannelState(e,t){return void 0===this.channelStates[e]&&this.addChannelState(e,t),this.channelStates[e]}processUpdate(e,t={}){let s=0;switch(e._){case"updateNewChannelMessage":case"updateEditChannelMessage":s=-l.a.getPeerId(e.message.peer_id);break;case"updateDeleteChannelMessages":s=e.channel_id;break;case"updateChannelTooLong":if(s=e.channel_id,!(s in this.channelStates))return!1}const a=s?this.getChannelState(s,e.pts):this.updatesState;if(a.syncLoading)return!1;if("updateChannelTooLong"===e._)return(!a.lastPtsUpdateTime||a.lastPtsUpdateTime<Date.now()-6)&&this.getChannelDifference(s),!1;if("updateNewMessage"===e._||"updateEditMessage"===e._||"updateNewChannelMessage"===e._||"updateEditChannelMessage"===e._){const t=e.message,a=l.a.getPeerId(t.peer_id),i=t.fwd_from||{};let n=!1;if(t.from_id&&!h.a.hasUser(l.a.getPeerId(t.from_id),t.pFlags.post)&&(n="author")||i.from_id&&!h.a.hasUser(l.a.getPeerId(i.from_id),!!i.channel_id)&&(n="fwdAuthor")||i.channel_id&&!d.a.hasChat(i.channel_id,!0)&&(n="fwdChannel")||a>0&&!h.a.hasUser(a)&&(n="toPeer User")||a<0&&!d.a.hasChat(-a)&&(n="toPeer Chat"))return this.log.warn("Not enough data for message update",a,n,t),s&&d.a.hasChat(s)?this.getChannelDifference(s):this.forceGetDifference(),!1}else if(s&&!d.a.hasChat(s))return!1;let i,n;if(e.pts){if(a.pts+(e.pts_count||0)<e.pts)return this.debug&&this.log.warn("Pts hole",a,e,s&&d.a.getChat(s)),a.pendingPtsUpdates.push(e),a.syncPending||a.syncLoading||(a.syncPending={timeout:window.setTimeout(()=>{a.syncPending=null,a.syncLoading||(s?this.getChannelDifference(s):this.getDifference())},6)}),a.syncPending.ptsAwaiting=!0,!1;if(e.pts>a.pts)a.pts=e.pts,i=!0,a.lastPtsUpdateTime=Date.now();else if(e.pts_count)return!1;s&&t.date&&this.updatesState.date<t.date&&(this.updatesState.date=t.date)}else if(!s&&t.seq>0){const s=t.seq,i=t.seqStart||s;if(i!==a.seq+1&&i>a.seq)return this.debug&&this.log.warn("Seq hole",a,a.syncPending&&a.syncPending.seqAwaiting),void 0===a.pendingSeqUpdates[i]&&(a.pendingSeqUpdates[i]={seq:s,date:t.date,updates:[]}),a.pendingSeqUpdates[i].updates.push(e),a.syncPending||(a.syncPending={timeout:window.setTimeout(()=>{a.syncPending=null,a.syncLoading||this.getDifference()},6)}),(!a.syncPending.seqAwaiting||a.syncPending.seqAwaiting<i)&&(a.syncPending.seqAwaiting=i),!1;a.seq!==s&&(a.seq=s,t.date&&a.date<t.date&&(a.date=t.date),n=!0)}this.saveUpdate(e),i?this.popPendingPtsUpdate(s):n&&this.popPendingSeqUpdate()}saveUpdate(e){r.default.dispatchEvent(e._,e)}attach(){this.attached||(this.log("attach"),this.attached=!0,c.default.getState().then(e=>{const t=e.updates;t&&t.pts&&t.date&&t.seq?(Object.assign(this.updatesState,t),this.log("will get difference",Object(i.a)(t)),this.getDifference(!0)):(this.log("will get new state"),this.updatesState.syncLoading=new Promise(e=>{o.a.invokeApi("updates.getState",{},{noErrorBox:!0}).then(t=>{this.updatesState.seq=t.seq,this.updatesState.pts=t.pts,this.updatesState.date=t.date,this.updatesState.syncLoading=null,e()})})),o.a.setUpdatesProcessor(this.processUpdateMessage),this.updatesState.syncLoading.then(()=>{c.default.addEventListener("save",()=>u(this,void 0,void 0,(function*(){const e=this.updatesState;c.default.pushToState("updates",{seq:e.seq,pts:e.pts,date:e.date})})))})}))}};a.a.apiUpdatesManager=g,t.a=g},function(e,t,s){"use strict";s.d(t,"a",(function(){return n}));const a={},i=(e,t)=>{e instanceof HTMLImageElement||e instanceof HTMLVideoElement?e.src=t:e instanceof SVGImageElement?e.setAttributeNS(null,"href",t):e.style.backgroundImage="url("+t+")"};function n(e,t,s,n=!0){if(a[t]&&n||e instanceof HTMLVideoElement)return e&&i(e,t),s&&s(),!0;{const n=e instanceof HTMLImageElement,o=n?e:new Image;return o.src=t,o.addEventListener("load",()=>{!n&&e&&i(e,t),a[t]=!0,s&&s()}),s&&o.addEventListener("error",s),!1}}},function(e,t,s){"use strict";var a=s(9),i=s(13),n=s(30),o=s(70),r=s(72),d=s(88);t.a=new class{constructor(){this.cacheStorage=new d.a("cachedFiles"),this.downloads={},this.progress={},this.progressCallbacks={},this.uploadId=0,a.default.on("download_progress",e=>{const t=e;this.progress[t.fileName]=t;const s=this.progressCallbacks[t.fileName];s&&s.forEach(e=>e(t));const a=this.downloads[t.fileName];a&&a.notifyAll(t)})}getNewDeferred(e){const t=Object(n.a)();return t.cancel=()=>{const s=new Error("Download canceled");s.name="AbortError",i.a.cancelDownload(e),t.reject(s),t.cancel=()=>{}},t.finally(()=>{delete this.progress[e],delete this.progressCallbacks[e]}),t.catch(()=>{this.clearDownload(e)}),this.downloads[e]=t}clearDownload(e){delete this.downloads[e]}fakeDownload(e,t){const s=this.getNewDeferred(e);return"string"==typeof t?fetch(t).then(e=>e.blob()).then(e=>s.resolve(e)):s.resolve(t),s}download(e){const t=Object(r.a)(e.location,{fileName:e.fileName});if(this.downloads.hasOwnProperty(t))return this.downloads[t];const s=this.getNewDeferred(t),a=t=>{var a;switch(t.type){case"FILE_REFERENCE_EXPIRED":{const t=null===(a=null==e?void 0:e.location)||void 0===a?void 0:a.file_reference;if(t){o.a.refreshReference(t).then(n);break}console.warn("FILE_REFERENCE_EXPIRED: no context for bytes:",t)}default:s.reject(t)}},n=()=>{if(!i.a.worker||e.onlyCache){const n=this.cacheStorage.getFile(t).then(t=>{if(t.size<e.size)throw"wrong size";s.resolve(t)});return e.onlyCache?n.catch(a):n.catch(()=>i.a.downloadFile(e).then(s.resolve,a))}return i.a.downloadFile(e).then(s.resolve,a)};return n(),s}upload(e,t){if(!t){const s=null==e?void 0:e.type;if(s){const e=this.uploadId+++"."+s.split("/")[1];t=["image/jpeg","image/png","image/bmp"].indexOf(s)>=0?"photo"+e:0===s.indexOf("audio/")||["video/ogg"].indexOf(s)>=0?"audio"+e:0===s.indexOf("video/")?"video"+e:"document"+e}else t="upload-"+this.uploadId++}const s=this.getNewDeferred(t);return i.a.uploadFile({file:e,fileName:t}).then(s.resolve,s.reject),s.finally(()=>{this.clearDownload(t)}),s}getDownload(e){return this.downloads[e]}addProgressCallback(e,t){var s;const a=this.progress[e];(null!==(s=this.progressCallbacks[e])&&void 0!==s?s:this.progressCallbacks[e]=[]).push(t),a&&t(a)}createDownloadAnchor(e,t,s){const a=document.createElement("a");a.href=e,a.download=t,a.target="_blank",a.style.position="absolute",a.style.top="1px",a.style.left="1px",document.body.append(a);try{var i=document.createEvent("MouseEvents");i.initMouseEvent("click",!0,!1,window,0,0,0,0,0,!1,!1,!1,!1,0,null),a.dispatchEvent(i)}catch(t){console.error("Download click error",t);try{a.click()}catch(t){window.open(e,"_blank")}}setTimeout(()=>{a.remove(),s&&s()},100)}downloadToDisc(e,t){const s=this.download(e);return s.then(e=>{const s=URL.createObjectURL(e);this.createDownloadAnchor(s,t,()=>{URL.revokeObjectURL(s)})}),s}}},function(e,t,s){"use strict";s.d(t,"a",(function(){return d})),s.d(t,"d",(function(){return c})),s.d(t,"b",(function(){return h})),s.d(t,"c",(function(){return u}));var a=s(16),i=s(26);class n{constructor(e){this.items=new Map,this.locked=!1,this.observer=new IntersectionObserver(t=>{if(this.locked)return;const s=[];t.forEach(e=>{const t=e.target;this.items.get(t)!==e.isIntersecting&&(this.items.set(t,e.isIntersecting),s[e.isIntersecting?"unshift":"push"]({target:t,visible:e.isIntersecting}))}),s.forEach(t=>{e(t.target,t.visible)})})}getVisible(){const e=[];return this.items.forEach((t,s)=>{t&&e.push(s)}),e}clearVisible(){const e=this.getVisible();for(const t of e)this.items.set(t,!1)}isVisible(e){return this.items.get(e)}disconnect(){this.observer.disconnect(),this.items.clear()}refresh(){this.observer.disconnect();const e=[...this.items.keys()];for(const t of e)this.observer.observe(t)}refreshVisible(){const e=this.getVisible();for(const t of e)this.observer.unobserve(t);for(const t of e)this.observer.observe(t)}observe(e){this.items.set(e,!1),this.observer.observe(e)}unobserve(e){this.observer.unobserve(e),this.items.delete(e)}unlock(){this.locked=!1}unlockAndRefresh(){this.unlock(),this.refresh()}lock(){this.locked=!0}}var o=s(47),r=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};class d{constructor(e=8){this.parallelLimit=e,this.queueId=0,this.queue=[],this.inProcess=new Set,this.lockPromise=null,this.unlockResolve=null,this.log=Object(i.b)("LL",i.a.error),this.processQueue=Object(a.e)(()=>this._processQueue(),20,!1)}clear(){this.inProcess.clear(),this.queue.length=0}lock(){this.lockPromise||(this.lockPromise=new Promise((e,t)=>{this.unlockResolve=e}))}unlock(){this.unlockResolve&&(this.unlockResolve(),this.unlockResolve=this.lockPromise=null,this.processQueue())}processItem(e){return r(this,void 0,void 0,(function*(){if(!this.lockPromise){this.inProcess.add(e);try{yield this.loadItem(e)}catch(e){["NO_ENTRY_FOUND","STORAGE_OFFLINE"].includes(e)||this.log.error("loadMediaQueue error:",e)}this.inProcess.delete(e),this.processQueue()}}))}loadItem(e){return e.load()}getItem(){return this.queue.shift()}addElement(e,t){this.queue[e](t),this.processQueue()}_processQueue(e){if(!this.queue.length||this.lockPromise||this.parallelLimit>0&&this.inProcess.size>=this.parallelLimit)return;do{if(e?this.queue.findAndSplice(t=>t===e):e=this.getItem(),!e)break;this.processItem(e),e=null}while(this.inProcess.size<this.parallelLimit&&this.queue.length)}push(e){this.addElement("push",e)}unshift(e){this.addElement("unshift",e)}}class l extends d{constructor(e=8){super(e),this.parallelLimit=e,this.queue=[],this.inProcess=new Set}lock(){super.lock(),this.intersector.lock()}unlock(){super.unlock(),this.intersector.unlock()}unlockAndRefresh(){super.unlock(),this.intersector.unlockAndRefresh()}clear(){super.clear(),this.intersector.disconnect()}refresh(){this.intersector.refresh()}loadItem(e){return e.load(e.div)}addElement(e,t){if(this.queue.find(e=>e.div===t.div&&e.load===t.load))return!1;for(const e of this.inProcess)if(e.div===t.div&&e.load===t.load)return!1;return this.queue[e](t),!0}setProcessQueueTimeout(){this.intersectorTimeout||(this.intersectorTimeout=window.setTimeout(()=>{this.intersectorTimeout=0,this.processQueue()},0))}push(e){super.push(e)}unshift(e){super.unshift(e)}unobserve(e){Object(o.b)(this.queue,t=>t.div===e),this.intersector.unobserve(e)}}class c extends l{constructor(e=8){super(e),this.parallelLimit=e,this.onVisibilityChange=(e,t)=>{t&&(Object(o.b)(this.queue,t=>t.div===e).forEach(e=>{e.wasSeen=!0,this.queue.unshift(e)}),this.setProcessQueueTimeout())},this.intersector=new n(this.onVisibilityChange)}getItem(){return this.queue.findAndSplice(e=>e.wasSeen)}processItem(e){const t=Object.create(null,{processItem:{get:()=>super.processItem}});return r(this,void 0,void 0,(function*(){yield t.processItem.call(this,e),this.intersector.unobserve(e.div)}))}addElement(e,t){return!!super.addElement(e,t)&&(this.intersector.observe(t.div),t.hasOwnProperty("wasSeen")||(t.wasSeen=!1),!0)}}class h extends l{constructor(e=8,t){super(e),this.parallelLimit=e,this.onVisibilityChange=t,this._queue=new Map,this.intersector=new n((e,t)=>{const s=Object(o.b)(this.queue,t=>t.div===e);if(t){(s.length?s:[this._queue.get(e)]).forEach(t=>{this.queue.unshift(t||this._queue.get(e))})}this.onVisibilityChange&&this.onVisibilityChange(e,t),this.setProcessQueueTimeout()})}clear(){super.clear(),this._queue.clear()}observe(e){this._queue.set(e.div,e),this.intersector.observe(e.div)}}class u extends l{constructor(e=8,t){super(e),this.parallelLimit=e,this.onVisibilityChange=t,this.intersector=new n((e,t)=>{const s=Object(o.b)(this.queue,t=>t.div===e);t&&s.length&&s.forEach(e=>{this.queue.unshift(e)}),this.onVisibilityChange&&this.onVisibilityChange(e,t),this.setProcessQueueTimeout()})}observe(e){this.intersector.observe(e)}}},,,,function(e,t,s){"use strict";var a=s(85),i=s(10),n=s(30),o=s(31),r=s(15),d=s(33),l=s(1),c=s(8),h=s(13),u=s(9),g=s(64),p=s(51),m=s(24),f=s(14);const _=new class{constructor(){this.notificationsShown={},this.notificationIndex=0,this.notificationsCount=0,this.soundsPlayed={},this.vibrateSupport=!!navigator.vibrate,this.peerSettings={notifyPeer:{},notifyUsers:null,notifyChats:null,notifyBroadcasts:null},this.faviconEl=document.head.querySelector('link[rel="icon"]'),this.titleBackup=document.title,this.titleChanged=!1,this.stopped=!1,this.settings={},this.pushInited=!1,this.updateLocalSettings=()=>{Promise.all(["notify_nodesktop","notify_volume","notify_novibrate","notify_nopreview","notify_nopush"].map(e=>g.a.get(e))).then(e=>{this.settings.nodesktop=e[0],this.settings.volume=void 0===e[1]?.5:e[1],this.settings.novibrate=e[2],this.settings.nopreview=e[3],this.settings.nopush=e[4]}),f.default.getState().then(e=>{this.settings.nosound=!e.settings.notifications.sound})},this.requestPermission=()=>{Notification.requestPermission(),window.removeEventListener("click",this.requestPermission)},navigator.vibrate=navigator.vibrate||navigator.mozVibrate||navigator.webkitVibrate,this.notificationsUiSupport="Notification"in window||"mozNotification"in navigator,this.topMessagesDeferred=Object(n.a)(),this.notifySoundEl=document.createElement("div"),this.notifySoundEl.id="notify-sound",document.body.append(this.notifySoundEl),u.default.on("idle",e=>{this.stopped||(e||this.clear(),this.toggleToggler())}),u.default.addMultipleEventsListeners({updateNotifySettings:e=>{this.savePeerSettings("notifyPeer"===e.peer._?m.a.getPeerId(e.peer.peer):e.peer._,e.notify_settings),u.default.broadcast("notify_settings",e)}}),u.default.addEventListener("dialogs_multiupdate",()=>{this.topMessagesDeferred.resolve()},!0)}toggleToggler(e=u.default.idle.isIDLE){if(l.isMobile)return;const t=()=>{this.titleChanged=!1,document.title=this.titleBackup,this.setFavicon()};window.clearInterval(this.titleInterval),this.titleInterval=0,e?this.titleInterval=window.setInterval(()=>{if(this.notificationsCount)if(this.titleChanged)t();else{this.titleChanged=!0,document.title=c.default.format("Notifications.Count",!0,[this.notificationsCount]);const e=document.createElement("canvas");e.width=32*window.devicePixelRatio,e.height=e.width;const t=e.getContext("2d");t.beginPath(),t.arc(e.width/2,e.height/2,e.width/2,0,2*Math.PI,!1),t.fillStyle="#3390ec",t.fill();let s=24,i=""+this.notificationsCount;this.notificationsCount<10?s=22:this.notificationsCount<100?s=20:(i="99+",s=16),s*=window.devicePixelRatio,t.font=`700 ${s}px ${a.a}`,t.textBaseline="middle",t.textAlign="center",t.fillStyle="white",t.fillText(i,e.width/2,.5625*e.height),this.setFavicon(e.toDataURL())}else this.toggleToggler(!1)},1e3):t()}getLocalSettings(){return this.settings}getNotifySettings(e){let t=Object(d.c)(e._),s=this.peerSettings[t];return"inputNotifyPeer"===e._&&(t=m.a.getPeerId(e.peer),s=s[t]),s||((s||this.peerSettings)[t]=h.a.invokeApi("account.getNotifySettings",{peer:e}).then(e=>(this.savePeerSettings(t,e),e)))}getNotifyPeerTypeSettings(){if(this.getNotifyPeerTypePromise)return this.getNotifyPeerTypePromise;const e=["inputNotifyBroadcasts","inputNotifyUsers","inputNotifyChats"].map(e=>this.getNotifySettings({_:e}));return this.getNotifyPeerTypePromise=Promise.all(e)}updateNotifySettings(e,t){return h.a.invokeApi("account.updateNotifySettings",{peer:e,settings:t}).then(s=>{s&&p.a.processUpdateMessage({_:"updateShort",update:{_:"updateNotifySettings",peer:Object.assign(Object.assign({},e),{_:Object(d.c)(e._)}),notify_settings:Object.assign(Object.assign({},t),{_:"peerNotifySettings"})}})})}getNotifyExceptions(){h.a.invokeApi("account.getNotifyExceptions",{compare_sound:!0}).then(e=>{p.a.processUpdateMessage(e)})}getContactSignUpNotification(){return this.notifyContactsSignUp?this.notifyContactsSignUp:this.notifyContactsSignUp=h.a.invokeApi("account.getContactSignUpNotification")}setContactSignUpNotification(e){h.a.invokeApi("account.setContactSignUpNotification",{silent:e}).then(t=>{this.notifyContactsSignUp=Promise.resolve(!e)})}setFavicon(e="assets/img/favicon.ico"){if(this.prevFavicon===e)return;const t=this.faviconEl.cloneNode();t.href=e,this.faviconEl.parentNode.replaceChild(t,this.faviconEl),this.faviconEl=t,this.prevFavicon=e}savePeerSettings(e,t){let s;"number"==typeof e&&(s=this.peerSettings.notifyPeer),(s||this.peerSettings)[e]=t,"number"!=typeof e&&u.default.broadcast("notify_peer_type_settings",{key:e,settings:t})}isMuted(e){return"peerNotifySettings"===e._&&1e3*e.mute_until>Object(o.g)()}getPeerMuted(e){const t=this.getNotifySettings({_:"inputNotifyPeer",peer:m.a.getInputPeerById(e)});return(t instanceof Promise?t:Promise.resolve(t)).then(e=>this.isMuted(e))}getPeerLocalSettings(e,t=!0){const s={_:"peerNotifySettings"},a=this.peerSettings.notifyPeer[e];if(!a||a instanceof Promise||Object.assign(s,a),t){const t=m.a.getInputNotifyPeerById(e,!0),a=Object(d.c)(t._),i=this.peerSettings[a];if(i&&!(i instanceof Promise))for(let e in i)void 0===s[e]&&(s[e]=i[e])}return s}isPeerLocalMuted(e,t=!0){if(e===u.default.myId)return!1;const s=this.getPeerLocalSettings(e,t);return this.isMuted(s)}start(){if(this.updateLocalSettings(),u.default.on("settings_updated",this.updateLocalSettings),!this.notificationsUiSupport)return!1;"Notification"in window&&"granted"!==Notification.permission&&"denied"!==Notification.permission&&window.addEventListener("click",this.requestPermission);try{"onbeforeunload"in window&&window.addEventListener("beforeunload",this.clear)}catch(e){}}stop(){this.clear(),window.clearInterval(this.titleInterval),this.titleInterval=0,this.setFavicon(),this.stopped=!0}notify(e){if(console.log("notify",e,u.default.idle.isIDLE,this.notificationsUiSupport,this.stopped),this.stopped)return;e.image||(e.image="assets/img/logo_filled_rounded.png"),this.notificationsCount++,this.titleInterval||this.toggleToggler();const t=Object(o.g)();if(this.settings.volume>0&&!this.settings.nosound&&(this.testSound(this.settings.volume),this.soundsPlayed[e.tag]=t),!this.notificationsUiSupport||"Notification"in window&&"granted"!==Notification.permission)return!1;if(this.settings.nodesktop)return this.vibrateSupport&&!this.settings.novibrate?void navigator.vibrate([200,100,200]):void 0;const s=++this.notificationIndex,a=e.key||"k"+s;let i;if("Notification"in window){try{if(e.tag)for(let t in this.notificationsShown){const s=this.notificationsShown[t];s&&s.tag===e.tag&&(s.hidden=!0)}i=new Notification(e.title,{icon:e.image||"",body:e.message||"",tag:e.tag||"",silent:e.silent||!1}),console.log("notify constructed notification")}catch(e){return void(this.notificationsUiSupport=!1)}i.onclick=()=>{i.close(),this.clear(),e.onclick&&e.onclick()},i.onclose=()=>{i.hidden||(delete this.notificationsShown[a],this.clear())},i.show&&i.show(),this.notificationsShown[a]=i,l.isMobile||setTimeout(()=>{this.hide(a)},8e3)}}testSound(e){const t=Object(o.g)();if(this.nextSoundAt&&t<this.nextSoundAt&&this.prevSoundVolume===e)return;this.nextSoundAt=t+1e3,this.prevSoundVolume=e;const s="assets/audio/notification.mp3",a=document.createElement("audio");a.autoplay=!0,a.setAttribute("mozaudiochannel","notification"),a.volume=e,a.innerHTML=`\n <source src="${s}" type="audio/mpeg" />\n <embed hidden="true" autostart="true" loop="false" volume="${100*e}" src="${s}" />\n `,this.notifySoundEl.append(a),a.addEventListener("ended",()=>{a.remove()},{once:!0})}cancel(e){const t=this.notificationsShown[e];if(t){this.notificationsCount>0&&this.notificationsCount--;try{t.close&&(t.hidden=!0,t.close())}catch(e){}delete this.notificationsShown[e]}}hide(e){const t=this.notificationsShown[e];if(t)try{t.close&&(t.hidden=!0,t.close())}catch(e){}}soundReset(e){delete this.soundsPlayed[e]}clear(){for(let e in this.notificationsShown){const t=this.notificationsShown[e];try{t.close&&t.close()}catch(e){}}this.notificationsShown={},this.notificationsCount=0}registerDevice(e){if(this.registeredDevice&&Object(r.b)(this.registeredDevice,e))return!1;h.a.invokeApi("account.registerDevice",{token_type:e.tokenType,token:e.tokenValue,other_uids:[],app_sandbox:!1,secret:new Uint8Array}).then(()=>{this.registeredDevice=e},e=>{e.handled=!0})}unregisterDevice(e){if(!this.registeredDevice)return!1;h.a.invokeApi("account.unregisterDevice",{token_type:e.tokenType,token:e.tokenValue,other_uids:[]}).then(()=>{this.registeredDevice=!1},e=>{e.handled=!0})}getVibrateSupport(){return this.vibrateSupport}};i.a.appNotificationsManager=_,t.a=_},,function(e,t,s){"use strict";function a(e){e=e||[];let t=[];for(let s=0;s<e.length;++s)t.push((e[s]<16?"0":"")+(e[s]||0).toString(16));return t.join("")}function i(e){const t=e.length;let s=0,a=[];t%2&&(a.push(parseInt(e.charAt(0),16)),++s);for(let i=s;i<t;i+=2)a.push(parseInt(e.substr(i,2),16));return a}function n(e){let t,s="";for(let a=e.length,i=0,n=0;n<a;++n)t=n%3,i|=e[n]<<(16>>>t&24),2!==t&&a-n!=1||(s+=String.fromCharCode(o(i>>>18&63),o(i>>>12&63),o(i>>>6&63),o(63&i)),i=0);return s.replace(/A(?=A$|$)/g,"=")}function o(e){return e<26?e+65:e<52?e+71:e<62?e-4:62===e?43:63===e?47:65}function r(e,t){const s=e.length;if(s!==t.length)return!1;for(let a=0;a<s;++a)if(e[a]!==t[a])return!1;return!0}function d(e){return e instanceof ArrayBuffer?e:void 0!==e.buffer&&e.buffer.byteLength===e.length*e.BYTES_PER_ELEMENT?e.buffer:new Uint8Array(e).buffer}function l(...e){let t=0;e.forEach(e=>t+=e.byteLength||e.length);const s=new Uint8Array(t);let a=0;return e.forEach(e=>{s.set(e instanceof ArrayBuffer?new Uint8Array(e):e,a),a+=e.byteLength||e.length}),s}s.d(t,"e",(function(){return a})),s.d(t,"c",(function(){return i})),s.d(t,"d",(function(){return n})),s.d(t,"b",(function(){return r})),s.d(t,"f",(function(){return d})),s.d(t,"a",(function(){return l}))},function(e,t,s){"use strict";s.d(t,"a",(function(){return r}));var a=s(7),i=s(62),n=s(16),o=s(15);class r{constructor(e){this.tempId=0,this.detached=!0,this.promise=null,this.isUpload=!1,this.cancelable=!0,this.streamable=!1,this.tryAgainOnFail=!0,this.attachMethod="append",this.onClick=e=>{e&&Object(a.f)(e),this.preloader.classList.contains("manual")?this.loadFunc&&this.loadFunc():this.promise&&this.promise.cancel&&this.promise.cancel()},e&&Object(o.g)(this,e)}constructContainer(e={}){this.preloader||(this.preloader=document.createElement("div"),this.preloader.classList.add("preloader-container"),e.color&&this.preloader.classList.add("preloader-"+e.color),e.bold&&this.preloader.classList.add("preloader-bold"),this.streamable&&this.preloader.classList.add("preloader-streamable"))}constructDownloadIcon(){this.constructContainer()}construct(){this.construct=null,this.constructContainer(),this.preloader.innerHTML=`\n <div class="you-spin-me-round">\n <svg xmlns="http://www.w3.org/2000/svg" class="preloader-circular" viewBox="${this.streamable?"25 25 50 50":"27 27 54 54"}">\n <circle class="preloader-path-new" cx="${this.streamable?"50":"54"}" cy="${this.streamable?"50":"54"}" r="${this.streamable?19:24}" fill="none" stroke-miterlimit="10"/>\n </svg>\n </div>`,this.cancelable?(this.preloader.innerHTML+='\n <svg xmlns="http://www.w3.org/2000/svg" class="preloader-close" viewBox="0 0 24 24">\n <g fill="none" fill-rule="evenodd">\n <polygon points="0 0 24 0 24 24 0 24"/>\n <path fill="#000" fill-rule="nonzero" d="M5.20970461,5.38710056 L5.29289322,5.29289322 C5.65337718,4.93240926 6.22060824,4.90467972 6.61289944,5.20970461 L6.70710678,5.29289322 L12,10.585 L17.2928932,5.29289322 C17.6834175,4.90236893 18.3165825,4.90236893 18.7071068,5.29289322 C19.0976311,5.68341751 19.0976311,6.31658249 18.7071068,6.70710678 L13.415,12 L18.7071068,17.2928932 C19.0675907,17.6533772 19.0953203,18.2206082 18.7902954,18.6128994 L18.7071068,18.7071068 C18.3466228,19.0675907 17.7793918,19.0953203 17.3871006,18.7902954 L17.2928932,18.7071068 L12,13.415 L6.70710678,18.7071068 C6.31658249,19.0976311 5.68341751,19.0976311 5.29289322,18.7071068 C4.90236893,18.3165825 4.90236893,17.6834175 5.29289322,17.2928932 L10.585,12 L5.29289322,6.70710678 C4.93240926,6.34662282 4.90467972,5.77939176 5.20970461,5.38710056 L5.29289322,5.29289322 L5.20970461,5.38710056 Z"/>\n </g>\n </svg>\n <svg xmlns="http://www.w3.org/2000/svg" class="preloader-download" viewBox="0 0 24 24">\n <g fill="none" fill-rule="evenodd">\n <polygon points="0 0 24 0 24 24 0 24"/>\n <path fill="#000" fill-rule="nonzero" d="M5,19 L19,19 C19.5522847,19 20,19.4477153 20,20 C20,20.5128358 19.6139598,20.9355072 19.1166211,20.9932723 L19,21 L5,21 C4.44771525,21 4,20.5522847 4,20 C4,19.4871642 4.38604019,19.0644928 4.88337887,19.0067277 L5,19 L19,19 L5,19 Z M11.8833789,3.00672773 L12,3 C12.5128358,3 12.9355072,3.38604019 12.9932723,3.88337887 L13,4 L13,13.585 L16.2928932,10.2928932 C16.6533772,9.93240926 17.2206082,9.90467972 17.6128994,10.2097046 L17.7071068,10.2928932 C18.0675907,10.6533772 18.0953203,11.2206082 17.7902954,11.6128994 L17.7071068,11.7071068 L12.7071068,16.7071068 C12.3466228,17.0675907 11.7793918,17.0953203 11.3871006,16.7902954 L11.2928932,16.7071068 L6.29289322,11.7071068 C5.90236893,11.3165825 5.90236893,10.6834175 6.29289322,10.2928932 C6.65337718,9.93240926 7.22060824,9.90467972 7.61289944,10.2097046 L7.70710678,10.2928932 L11,13.585 L11,4 C11,3.48716416 11.3860402,3.06449284 11.8833789,3.00672773 L12,3 L11.8833789,3.00672773 Z"/>\n </g>\n </svg>',this.downloadSvg=this.preloader.lastElementChild,this.cancelSvg=this.downloadSvg.previousElementSibling):this.preloader.classList.add("preloader-swing"),this.circle=this.preloader.firstElementChild.firstElementChild.firstElementChild,this.cancelable&&Object(a.b)(this.preloader,this.onClick)}setDownloadFunction(e){this.loadFunc=e}setManual(){this.preloader.classList.add("manual"),this.setProgress(0)}attachPromise(e){if(this.isUpload&&this.promise)return;this.promise=e;const t=--this.tempId,s=Date.now(),a=a=>{if(e.notify=null,t!==this.tempId)return;const o=Date.now()-s;if(!a&&this.cancelable){this.setProgress(100);const e=150;o<e?this.detach():setTimeout(()=>{t===this.tempId&&this.detach()},e)}else this.tryAgainOnFail?(Object(i.a)(this.preloader,"",!0,200),Object(n.c)(()=>{this.setManual()})):this.detach();this.promise=e=null};e.then(()=>a(null)).catch(e=>a(e)),e.addNotifyListener&&e.addNotifyListener(e=>{if(t!==this.tempId)return;const s=e.done/e.total*100;this.setProgress(s)})}attach(e,t=!1,s){s&&this.attachPromise(s),this.detached=!1,this.construct&&this.construct(),this.preloader.parentElement&&this.preloader.classList.remove("manual"),this.preloader.parentElement!==e&&e[this.attachMethod](this.preloader),Object(n.c)(()=>{this.detached||Object(i.a)(this.preloader,"is-visible",!0,200)}),this.cancelable&&t&&this.setProgress(0)}detach(){this.detached=!0,this.preloader&&this.preloader.parentElement&&Object(n.c)(()=>{this.detached&&this.preloader.parentElement&&Object(i.a)(this.preloader,"is-visible",!1,200,()=>{this.preloader.remove()})})}setProgress(e){if(Object(a.r)(this.circle))if(0!==e)try{this.totalLength||(this.totalLength=this.circle.getTotalLength()),this.circle.style.strokeDasharray=Math.max(5,e/100*this.totalLength)+", "+this.totalLength}catch(e){}else this.circle.style.strokeDasharray=""}}},function(e,t,s){"use strict";var a=s(9);t.a=(e,t,s,i,n)=>{const o=e.dataset.timeout;void 0!==o&&clearTimeout(+o),s&&t&&e.classList.add(t);const r=()=>{delete e.dataset.timeout,!s&&t&&e.classList.remove("backwards",t),e.classList.remove("animating"),n&&n()};if(!a.default.settings.animationsEnabled)return e.classList.remove("animating","backwards"),void r();e.classList.add("animating"),e.classList.toggle("backwards",!s),e.dataset.timeout=""+setTimeout(r,i)}},function(e,t,s){"use strict";var a=s(10),i=s(31),n=s(64);const o=new class{constructor(){this.timestampNow=Object(i.g)(!0),this.midnightNoOffset=this.timestampNow-this.timestampNow%86400,this.midnightOffseted=new Date,this.midnightOffset=this.midnightNoOffset-Math.floor(+this.midnightOffseted/1e3),this.serverTimeOffset=0,this.timeParams={midnightOffset:this.midnightOffset,serverTimeOffset:this.serverTimeOffset},this.midnightOffseted.setHours(0,0,0,0),n.a.get("server_time_offset").then(e=>{e&&(this.serverTimeOffset=e,this.timeParams.serverTimeOffset=e)})}};a.a&&(a.a.serverTimeManager=o),t.a=o},,function(e,t,s){"use strict";s.d(t,"b",(function(){return o})),s.d(t,"a",(function(){return r})),s.d(t,"d",(function(){return d})),s.d(t,"c",(function(){return l})),s.d(t,"e",(function(){return c}));var a=s(16),i=s(1),n=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};function o(e){return new Promise((t,s)=>{e.onseeked=()=>{const s=document.createElement("canvas");s.width=Math.min(1280,e.videoWidth),s.height=Math.min(720,e.videoHeight);s.getContext("2d").drawImage(e,0,0),s.toBlob(e=>{t(e)},"image/jpeg",1)},e.onerror=s,e.currentTime=Math.min(e.duration,1)})}function r(e){return n(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise((t,s)=>{const a=document.createElement("video");a.volume=0,a.onloadedmetadata=()=>t(a),a.onerror=s,a.src=e})}(e);return Promise.race([Object(a.d)(2e3),o(t)])}))}function d(e){return new Promise(t=>{e.readyState>=e.HAVE_METADATA?t():e.addEventListener(i.isAppleMobile?"loadeddata":"canplay",()=>t(),{once:!0})})}function l(e,t=!1){return n(this,void 0,void 0,(function*(){const s=[],a=(e,i)=>n(this,void 0,void 0,(function*(){if(e.isDirectory){const t=e.createReader();yield new Promise((e,s)=>{t.readEntries(t=>n(this,void 0,void 0,(function*(){for(const e of t)yield a(e,i);e()})))})}else if(e)if(t)s.push(e.type);else{const t=i.getAsFile(),a=e instanceof File?e:e instanceof DataTransferItem?e.getAsFile():yield new Promise((s,a)=>e.file(s,e=>s(t)));if(!a)return;s.push(a)}}));if(e instanceof DragEvent&&e.dataTransfer.files&&!e.dataTransfer.items)for(let a=0;a<e.dataTransfer.files.length;a++){const i=e.dataTransfer.files[a];s.push(t?i.type:i)}else{const s=(e.dataTransfer||e.clipboardData||e.originalEvent.clipboardData).items,i=[];for(let e=0;e<s.length;++e){const n=s[e];if("file"===n.kind){const e=(t?n:n.webkitGetAsEntry())||n.getAsFile();i.push(a(e,n))}}yield Promise.all(i)}return s}))}function c(e){const t=document.createElement("input");t.type="file",t.style.display="none",e&&(t.accept=e),document.body.append(t);const s=new Promise((e,s)=>{t.addEventListener("change",t=>{const a=t.target.files[0];a?e(a):s("NO_FILE_SELECTED")},{once:!0})}).finally(()=>{t.remove()});return t.click(),s}},,,,,function(e,t,s){"use strict";var a=s(21),i=s(60),n=s(15),o=s(10);const r=new class{constructor(){this.contexts=new Map,this.links={}}saveContext(e,t,s){[s,e]=this.getContexts(e),s||(s=new Set,this.contexts.set(e,s),this.links[Object(i.e)(e)]=e);for(const e of s)if(Object(n.b)(e,t))return;s.add(t)}getReferenceByLink(e){return this.links[Object(i.e)(e)]}getContexts(e){return[this.contexts.get(e)||(e=this.getReferenceByLink(e)||e,this.contexts.get(e)),e]}getContext(e){const t=this.getContexts(e);return t?[t[0].values().next().value,t[1]]:void 0}deleteContext(e,t,s){if([s,e]=this.getContexts(e),s)for(const a of s)if(Object(n.b)(a,t))return s.delete(a),s.size||(this.contexts.delete(e),delete this.links[Object(i.e)(e)]),!0;return!1}refreshReference(e,t){switch([t,e]=this.getContext(e),null==t?void 0:t.type){case"message":return a.a.wrapSingleMessage(t.peerId,t.messageId,!0);default:return console.warn("FILE_REFERENCE_EXPIRED: not implemented context",t),Promise.reject()}}};o.a.referenceDatabase=r,t.a=r},function(e,t,s){"use strict";var a=s(82);class i{createIndex(){return{fullTexts:{}}}cleanSearchText(e,t=!0){const s="%"===e.charAt(0);return e=e.replace(i.badCharsRe,"").replace(i.trimRe,""),t&&(e=e.replace(/[^A-Za-z0-9]/g,e=>{const t=a.a.LatinizeMap[e];return void 0!==t?t:e})),e=e.toLowerCase(),s&&(e="%"+e),e}cleanUsername(e){return e&&e.toLowerCase()||""}indexObject(e,t,s){if(t.trim()&&(t=this.cleanSearchText(t)),!t)return delete s.fullTexts[e],!1;s.fullTexts[e]=t}search(e,t){const s=t.fullTexts,a={},i=(e=this.cleanSearchText(e)).split(" ");for(const e in s){const t=s[e];let n=!0;for(const e of i){const s=t.indexOf(e);if(-1===s||0!==s&&" "!==t[s-1]){n=!1;break}}n&&(a[e]=!0)}return a}}i.badCharsRe=/[`~!@#$%^&*()\-_=+\[\]\\|{}'";:\/?.>,<]+/g,i.trimRe=/^\s+|\s$/g,t.a=new i},function(e,t,s){"use strict";function a(e,t){const s=""["".length-1]||"";switch(e._){case"inputPhotoFileLocation":case"inputDocumentFileLocation":{const t=e.thumb_size?"_"+e.thumb_size:"";return(""[0]?""[0]+"_":"")+e.id+t+(s?"."+s:s)}case"fileLocationToBeDeprecated":case"inputPeerPhotoFileLocation":case"inputStickerSetThumb":case"inputFileLocation":return e.volume_id+"_"+e.local_id+(s?"."+s:s);default:return console.error("Unrecognized location:",e),""}}function i(e,t){return"/"+e+"/"+encodeURIComponent(JSON.stringify(t))}s.d(t,"a",(function(){return a})),s.d(t,"b",(function(){return i}))},function(e,t,s){"use strict";var a=s(10),i=s(15),n=s(26),o=s(13),r=s(11),d=s(9),l=s(51),c=s(21),h=s(24),u=s(18);const g=new class{constructor(){this.polls={},this.results={},this.log=Object(n.b)("POLLS",n.a.error),d.default.addMultipleEventsListeners({updateMessagePoll:e=>{this.log("updateMessagePoll:",e);let t=e.poll||this.polls[e.poll_id];t&&(t=this.savePoll(t,e.results),d.default.broadcast("poll_update",{poll:t,results:e.results}))}})}savePoll(e,t){const s=e.id;return this.polls[s]?(e=Object.assign(this.polls[s],e),this.saveResults(e,t),e):(this.polls[s]=e,e.rQuestion=r.a.wrapEmojiText(e.question),e.rReply=r.a.wrapEmojiText("📊")+" "+(e.rQuestion||"poll"),e.chosenIndexes=[],this.saveResults(e,t),e)}saveResults(e,t){var s;this.results[e.id]?t=Object.assign(this.results[e.id],t):this.results[e.id]=t,t.pFlags.min||(e.chosenIndexes.length=0,(null===(s=null==t?void 0:t.results)||void 0===s?void 0:s.length)&&t.results.forEach((t,s)=>{var a;(null===(a=t.pFlags)||void 0===a?void 0:a.chosen)&&e.chosenIndexes.push(s)}))}getPoll(e){return{poll:this.polls[e],results:this.results[e]}}getInputMediaPoll(e,t,s,a){return s&&(a||(a=[]),s=r.a.parseMarkdown(s,a)),{_:"inputMediaPoll",poll:e,correct_answers:t,solution:s,solution_entities:(null==a?void 0:a.length)?a:void 0}}sendVote(e,t){const s=e.media.poll,a=t.map(e=>s.answers[e].option),i=e.mid,n=e.peerId,r=h.a.getInputPeerById(n);return e.pFlags.is_outgoing?c.a.invokeAfterMessageIsSent(i,"sendVote",e=>(this.log("invoke sendVote callback"),this.sendVote(e,t))):o.a.invokeApi("messages.sendVote",{peer:r,msg_id:c.a.getServerMessageId(e.mid),options:a}).then(e=>{this.log("sendVote updates:",e),l.a.processUpdateMessage(e)})}getResults(e){const t=h.a.getInputPeerById(e.peerId);return o.a.invokeApi("messages.getPollResults",{peer:t,msg_id:c.a.getServerMessageId(e.mid)}).then(e=>{l.a.processUpdateMessage(e),this.log("getResults updates:",e)})}getVotes(e,t,s,a=20){return o.a.invokeApi("messages.getPollVotes",{peer:h.a.getInputPeerById(e.peerId),id:c.a.getServerMessageId(e.mid),option:t,offset:s,limit:a}).then(e=>(this.log("getPollVotes messages:",e),u.a.saveApiUsers(e.users),e))}stopPoll(e){const t=e.media.poll;if(t.pFlags.closed)return Promise.resolve();const s=Object(i.a)(t);return s.pFlags.closed=!0,c.a.editMessage(e,void 0,{newMedia:this.getInputMediaPoll(s)}).then(()=>{},e=>{this.log.error("stopPoll error:",e)})}};a.a.appPollsManager=g,t.a=g},,,,,,,,function(e,t,s){"use strict";var a=s(100),i=s.n(a),n=s(10),o=s(30),r=s(13);const d=new class{constructor(){this.convertPromises={}}init(){this.worker=new i.a,this.worker.addEventListener("message",e=>{const t=e.data.payload;if(0===t.fileName.indexOf("main-")){const e=this.convertPromises[t.fileName];e&&(t.bytes?e.resolve(t.bytes):e.reject(),delete this.convertPromises[t.fileName])}else r.a.postMessage(e.data)})}postMessage(e){this.init&&(this.init(),this.init=null),this.worker.postMessage(e)}isWebpSupported(){return void 0===this.isWebpSupportedCache&&(this.isWebpSupportedCache=document.createElement("canvas").toDataURL("image/webp").startsWith("data:image/webp")),this.isWebpSupportedCache}convert(e,t){if(e="main-"+e,this.convertPromises.hasOwnProperty(e))return this.convertPromises[e];const s=Object(o.a)();return this.postMessage({type:"convertWebp",payload:{fileName:e,bytes:t}}),this.convertPromises[e]=s}};n.a.webpWorkerController=d,t.a=d},,function(e,t,s){"use strict";s.d(t,"a",(function(){return n}));var a=s(10);const i=[{phoneCode:"7 840",code:"AB",name:"Abkhazia",pattern:"",emoji:""},{phoneCode:"93",code:"AF",name:"Afghanistan",pattern:"93 XXX XXX XXX",emoji:"🇦🇫"},{phoneCode:"358 18",code:"AX",name:"Aland Islands",pattern:"",emoji:"🇦🇽"},{phoneCode:"355",code:"AL",name:"Albania",pattern:"355 XX XXX XXXX",emoji:"🇦🇱"},{phoneCode:"213",code:"DZ",name:"Algeria",pattern:"213 XXX XX XX XX",emoji:"🇩🇿"},{phoneCode:"1 684",code:"AS",name:"American Samoa",pattern:"1684 XXX XXXX",emoji:"🇦🇸"},{phoneCode:"376",code:"AD",name:"Andorra",pattern:"376 XX XX XX",emoji:"🇦🇩"},{phoneCode:"244",code:"AO",name:"Angola",pattern:"244 XXX XXX XXX",emoji:"🇦🇴"},{phoneCode:"1 264",code:"AI",name:"Anguilla",pattern:"1264 XXX XXXX",emoji:"🇦🇮"},{phoneCode:"1 268",code:"AG",name:"Antigua & Barbuda",pattern:"1268 XXX XXXX",emoji:"🇦🇬"},{phoneCode:"54",code:"AR",name:"Argentina",pattern:"",emoji:"🇦🇷"},{phoneCode:"374",code:"AM",name:"Armenia",pattern:"374 XX XXX XXX",emoji:"🇦🇲"},{phoneCode:"297",code:"AW",name:"Aruba",pattern:"297 XXX XXXX",emoji:"🇦🇼"},{phoneCode:"247",code:"SH",name:"Ascension",pattern:"290 XX XXX",emoji:"🇸🇭"},{phoneCode:"61",code:"AU",name:"Australia",pattern:"61 XXX XXX XXX",emoji:"🇦🇺"},{phoneCode:"672",code:"AU",name:"Australian External Territories",pattern:"61 XXX XXX XXX",emoji:"🇦🇺"},{phoneCode:"43",code:"AT",name:"Austria",pattern:"",emoji:"🇦🇹"},{phoneCode:"994",code:"AZ",name:"Azerbaijan",pattern:"994 XX XXX XX XX",emoji:"🇦🇿"},{phoneCode:"1 242",code:"BS",name:"Bahamas",pattern:"1242 XXX XXXX",emoji:"🇧🇸"},{phoneCode:"973",code:"BH",name:"Bahrain",pattern:"973 XXXX XXXX",emoji:"🇧🇭"},{phoneCode:"880",code:"BD",name:"Bangladesh",pattern:"",emoji:"🇧🇩"},{phoneCode:"1 246",code:"BB",name:"Barbados",pattern:"1246 XXX XXXX",emoji:"🇧🇧"},{phoneCode:"1 268",code:"AG",name:"Barbuda",pattern:"1268 XXX XXXX",emoji:"🇦🇬"},{phoneCode:"375",code:"BY",name:"Belarus",pattern:"375 XX XXX XXXX",emoji:"🇧🇾"},{phoneCode:"32",code:"BE",name:"Belgium",pattern:"32 XXX XX XX XX",emoji:"🇧🇪"},{phoneCode:"501",code:"BZ",name:"Belize",pattern:"",emoji:"🇧🇿"},{phoneCode:"229",code:"BJ",name:"Benin",pattern:"229 XX XXX XXX",emoji:"🇧🇯"},{phoneCode:"1 441",code:"BM",name:"Bermuda",pattern:"1441 XXX XXXX",emoji:"🇧🇲"},{phoneCode:"975",code:"BT",name:"Bhutan",pattern:"",emoji:"🇧🇹"},{phoneCode:"591",code:"BO",name:"Bolivia",pattern:"591 X XXX XXXX",emoji:"🇧🇴"},{phoneCode:"599 7",code:"BQ",name:"Caribbean Netherlands",pattern:"",emoji:"🇧🇶"},{phoneCode:"387",code:"BA",name:"Bosnia & Herzegovina",pattern:"",emoji:"🇧🇦"},{phoneCode:"267",code:"BW",name:"Botswana",pattern:"267 XX XXX XXX",emoji:"🇧🇼"},{phoneCode:"55",code:"BR",name:"Brazil",pattern:"55 XX XXXXX XXXX",emoji:"🇧🇷"},{phoneCode:"246",code:"IO",name:"British Indian Ocean Territory",pattern:"246 XXX XXXX",emoji:"🇮🇴"},{phoneCode:"1 284",code:"VG",name:"British Virgin Islands",pattern:"1284 XXX XXXX",emoji:"🇻🇬"},{phoneCode:"673",code:"BN",name:"Brunei",pattern:"673 XXX XXXX",emoji:"🇧🇳"},{phoneCode:"359",code:"BG",name:"Bulgaria",pattern:"",emoji:"🇧🇬"},{phoneCode:"226",code:"BF",name:"Burkina Faso",pattern:"226 XX XX XX XX",emoji:"🇧🇫"},{phoneCode:"95",code:"MM",name:"Myanmar (Burma)",pattern:"",emoji:"🇲🇲"},{phoneCode:"257",code:"BI",name:"Burundi",pattern:"257 XX XX XXXX",emoji:"🇧🇮"},{phoneCode:"855",code:"KH",name:"Cambodia",pattern:"",emoji:"🇰🇭"},{phoneCode:"237",code:"CM",name:"Cameroon",pattern:"237 XXXX XXXX",emoji:"🇨🇲"},{phoneCode:"1",code:"CA",name:"Canada",pattern:"1 XXX XXX XXXX",emoji:"🇨🇦"},{phoneCode:"238",code:"CV",name:"Cape Verde",pattern:"238 XXX XXXX",emoji:"🇨🇻"},{phoneCode:"1 345",code:"KY",name:"Cayman Islands",pattern:"1345 XXX XXXX",emoji:"🇰🇾"},{phoneCode:"236",code:"CF",name:"Central African Republic",pattern:"236 XX XX XX XX",emoji:"🇨🇫"},{phoneCode:"235",code:"TD",name:"Chad",pattern:"235 XX XX XX XX",emoji:"🇹🇩"},{phoneCode:"56",code:"CL",name:"Chile",pattern:"56 X XXXX XXXX",emoji:"🇨🇱"},{phoneCode:"86",code:"CN",name:"China",pattern:"86 XXX XXXX XXXX",emoji:"🇨🇳"},{phoneCode:"61",code:"CX",name:"Christmas Island",pattern:"",emoji:"🇨🇽"},{phoneCode:"61",code:"CC",name:"Cocos (Keeling) Islands",pattern:"",emoji:"🇨🇨"},{phoneCode:"57",code:"CO",name:"Colombia",pattern:"57 XXX XXX XXXX",emoji:"🇨🇴"},{phoneCode:"269",code:"KM",name:"Comoros",pattern:"269 XXX XXXX",emoji:"🇰🇲"},{phoneCode:"242",code:"CG",name:"Congo - Brazzaville",pattern:"242 XX XXX XXXX",emoji:"🇨🇬"},{phoneCode:"243",code:"CD",name:"Congo - Kinshasa",pattern:"243 XX XXX XXXX",emoji:"🇨🇩"},{phoneCode:"682",code:"CK",name:"Cook Islands",pattern:"",emoji:"🇨🇰"},{phoneCode:"506",code:"CR",name:"Costa Rica",pattern:"",emoji:"🇨🇷"},{phoneCode:"225",code:"CI",name:"Cote dIvoire",pattern:"225 XX XXX XXX",emoji:"🇨🇮"},{phoneCode:"385",code:"HR",name:"Croatia",pattern:"",emoji:"🇭🇷"},{phoneCode:"53",code:"CU",name:"Cuba",pattern:"53 XXXX XXXX",emoji:"🇨🇺"},{phoneCode:"599 9",code:"CW",name:"Curacao",pattern:"",emoji:"🇨🇼"},{phoneCode:"357",code:"CY",name:"Cyprus",pattern:"357 XXXX XXXX",emoji:"🇨🇾"},{phoneCode:"420",code:"CZ",name:"Czech Republic",pattern:"",emoji:"🇨🇿"},{phoneCode:"45",code:"DK",name:"Denmark",pattern:"45 XXXX XXXX",emoji:"🇩🇰"},{phoneCode:"246",code:"DG",name:"Diego Garcia",pattern:"",emoji:"🇩🇬"},{phoneCode:"253",code:"DJ",name:"Djibouti",pattern:"253 XX XX XX XX",emoji:"🇩🇯"},{phoneCode:"1 767",code:"DM",name:"Dominica",pattern:"1767 XXX XXXX",emoji:"🇩🇲"},{phoneCode:"1 809 and 1 829",code:"DO",name:"Dominican Republic",pattern:"1 XXX XXX XXXX",emoji:"🇩🇴"},{phoneCode:"670",code:"TL",name:"Timor-Leste",pattern:"",emoji:"🇹🇱"},{phoneCode:"593",code:"EC",name:"Ecuador",pattern:"",emoji:"🇪🇨"},{phoneCode:"20",code:"EG",name:"Egypt",pattern:"20 XX XXX XXXX",emoji:"🇪🇬"},{phoneCode:"503",code:"SV",name:"El Salvador",pattern:"503 XXXX XXXX",emoji:"🇸🇻"},{phoneCode:"240",code:"GQ",name:"Equatorial Guinea",pattern:"240 XXX XXX XXX",emoji:"🇬🇶"},{phoneCode:"291",code:"ER",name:"Eritrea",pattern:"291 X XXX XXX",emoji:"🇪🇷"},{phoneCode:"372",code:"EE",name:"Estonia",pattern:"",emoji:"🇪🇪"},{phoneCode:"251",code:"ET",name:"Ethiopia",pattern:"251 XX XXX XXXX",emoji:"🇪🇹"},{phoneCode:"500",code:"FK",name:"Falkland Islands",pattern:"",emoji:"🇫🇰"},{phoneCode:"298",code:"FO",name:"Faroe Islands",pattern:"298 XXX XXX",emoji:"🇫🇴"},{phoneCode:"679",code:"FJ",name:"Fiji",pattern:"",emoji:"🇫🇯"},{phoneCode:"358",code:"FI",name:"Finland",pattern:"",emoji:"🇫🇮"},{phoneCode:"33",code:"FR",name:"France",pattern:"33 X XX XX XX XX",emoji:"🇫🇷"},{phoneCode:"594",code:"GF",name:"French Guiana",pattern:"",emoji:"🇬🇫"},{phoneCode:"689",code:"PF",name:"French Polynesia",pattern:"",emoji:"🇵🇫"},{phoneCode:"241",code:"GA",name:"Gabon",pattern:"241 X XX XX XX",emoji:"🇬🇦"},{phoneCode:"220",code:"GM",name:"Gambia",pattern:"220 XXX XXXX",emoji:"🇬🇲"},{phoneCode:"995",code:"GE",name:"Georgia",pattern:"",emoji:"🇬🇪"},{phoneCode:"49",code:"DE",name:"Germany",pattern:"49 XXX XXXXXXXX",emoji:"🇩🇪"},{phoneCode:"233",code:"GH",name:"Ghana",pattern:"",emoji:"🇬🇭"},{phoneCode:"350",code:"GI",name:"Gibraltar",pattern:"350 XXXX XXXX",emoji:"🇬🇮"},{phoneCode:"30",code:"GR",name:"Greece",pattern:"30 XX XXXX XXXX",emoji:"🇬🇷"},{phoneCode:"299",code:"GL",name:"Greenland",pattern:"299 XXX XXX",emoji:"🇬🇱"},{phoneCode:"1 473",code:"GD",name:"Grenada",pattern:"1473 XXX XXXX",emoji:"🇬🇩"},{phoneCode:"590",code:"GP",name:"Guadeloupe",pattern:"",emoji:"🇬🇵"},{phoneCode:"1 671",code:"GU",name:"Guam",pattern:"1671 XXX XXXX",emoji:"🇬🇺"},{phoneCode:"502",code:"GT",name:"Guatemala",pattern:"502 X XXX XXXX",emoji:"🇬🇹"},{phoneCode:"44",code:"GG",name:"Guernsey",pattern:"",emoji:"🇬🇬"},{phoneCode:"224",code:"GN",name:"Guinea",pattern:"224 XXX XXX XXX",emoji:"🇬🇳"},{phoneCode:"245",code:"GW",name:"Guinea-Bissau",pattern:"245 XXX XXXX",emoji:"🇬🇼"},{phoneCode:"592",code:"GY",name:"Guyana",pattern:"",emoji:"🇬🇾"},{phoneCode:"509",code:"HT",name:"Haiti",pattern:"",emoji:"🇭🇹"},{phoneCode:"504",code:"HN",name:"Honduras",pattern:"504 XXXX XXXX",emoji:"🇭🇳"},{phoneCode:"852",code:"HK",name:"Hong Kong SAR China",pattern:"",emoji:"🇭🇰"},{phoneCode:"36",code:"HU",name:"Hungary",pattern:"36 XX XXX XXXX",emoji:"🇭🇺"},{phoneCode:"354",code:"IS",name:"Iceland",pattern:"354 XXX XXXX",emoji:"🇮🇸"},{phoneCode:"91",code:"IN",name:"India",pattern:"91 XXXXX XXXXX",emoji:"🇮🇳"},{phoneCode:"62",code:"ID",name:"Indonesia",pattern:"",emoji:"🇮🇩"},{phoneCode:"98",code:"IR",name:"Iran",pattern:"98 XXX XXX XXXX",emoji:"🇮🇷"},{phoneCode:"964",code:"IQ",name:"Iraq",pattern:"964 XXX XXX XXXX",emoji:"🇮🇶"},{phoneCode:"353",code:"IE",name:"Ireland",pattern:"353 XX XXX XXXX",emoji:"🇮🇪"},{phoneCode:"972",code:"IL",name:"Israel",pattern:"972 XX XXX XXXX",emoji:"🇮🇱"},{phoneCode:"39",code:"IT",name:"Italy",pattern:"39 XXX XXX XXXX",emoji:"🇮🇹"},{phoneCode:"1 876",code:"JM",name:"Jamaica",pattern:"1876 XXX XXXX",emoji:"🇯🇲"},{phoneCode:"47 79",code:"SJ",name:"Svalbard & Jan Mayen",pattern:"",emoji:"🇸🇯"},{phoneCode:"81",code:"JP",name:"Japan",pattern:"81 XX XXXX XXXX",emoji:"🇯🇵"},{phoneCode:"44",code:"JE",name:"Jersey",pattern:"",emoji:"🇯🇪"},{phoneCode:"962",code:"JO",name:"Jordan",pattern:"962 X XXXX XXXX",emoji:"🇯🇴"},{phoneCode:"7 7",code:"KZ",name:"Kazakhstan",pattern:"7 XXX XXX XX XX",emoji:"🇰🇿"},{phoneCode:"254",code:"KE",name:"Kenya",pattern:"254 XXX XXX XXX",emoji:"🇰🇪"},{phoneCode:"686",code:"KI",name:"Kiribati",pattern:"",emoji:"🇰🇮"},{phoneCode:"850",code:"KP",name:"North Korea",pattern:"",emoji:"🇰🇵"},{phoneCode:"82",code:"KR",name:"South Korea",pattern:"",emoji:"🇰🇷"},{phoneCode:"965",code:"KW",name:"Kuwait",pattern:"965 XXXX XXXX",emoji:"🇰🇼"},{phoneCode:"996",code:"KG",name:"Kyrgyzstan",pattern:"",emoji:"🇰🇬"},{phoneCode:"856",code:"LA",name:"Laos",pattern:"",emoji:"🇱🇦"},{phoneCode:"371",code:"LV",name:"Latvia",pattern:"371 XXX XXXXX",emoji:"🇱🇻"},{phoneCode:"961",code:"LB",name:"Lebanon",pattern:"",emoji:"🇱🇧"},{phoneCode:"266",code:"LS",name:"Lesotho",pattern:"266 XX XXX XXX",emoji:"🇱🇸"},{phoneCode:"231",code:"LR",name:"Liberia",pattern:"",emoji:"🇱🇷"},{phoneCode:"218",code:"LY",name:"Libya",pattern:"218 XX XXX XXXX",emoji:"🇱🇾"},{phoneCode:"423",code:"LI",name:"Liechtenstein",pattern:"",emoji:"🇱🇮"},{phoneCode:"370",code:"LT",name:"Lithuania",pattern:"370 XXX XXXXX",emoji:"🇱🇹"},{phoneCode:"352",code:"LU",name:"Luxembourg",pattern:"",emoji:"🇱🇺"},{phoneCode:"853",code:"MO",name:"Macau SAR China",pattern:"",emoji:"🇲🇴"},{phoneCode:"389",code:"MK",name:"Macedonia",pattern:"",emoji:"🇲🇰"},{phoneCode:"261",code:"MG",name:"Madagascar",pattern:"261 XX XX XXX XX",emoji:"🇲🇬"},{phoneCode:"265",code:"MW",name:"Malawi",pattern:"",emoji:"🇲🇼"},{phoneCode:"60",code:"MY",name:"Malaysia",pattern:"",emoji:"🇲🇾"},{phoneCode:"960",code:"MV",name:"Maldives",pattern:"",emoji:"🇲🇻"},{phoneCode:"223",code:"ML",name:"Mali",pattern:"223 XXXX XXXX",emoji:"🇲🇱"},{phoneCode:"356",code:"MT",name:"Malta",pattern:"356 XX XX XX XX",emoji:"🇲🇹"},{phoneCode:"692",code:"MH",name:"Marshall Islands",pattern:"",emoji:"🇲🇭"},{phoneCode:"596",code:"MQ",name:"Martinique",pattern:"",emoji:"🇲🇶"},{phoneCode:"222",code:"MR",name:"Mauritania",pattern:"222 XXXX XXXX",emoji:"🇲🇷"},{phoneCode:"230",code:"MU",name:"Mauritius",pattern:"",emoji:"🇲🇺"},{phoneCode:"262",code:"YT",name:"Mayotte",pattern:"",emoji:"🇾🇹"},{phoneCode:"52",code:"MX",name:"Mexico",pattern:"",emoji:"🇲🇽"},{phoneCode:"691",code:"FM",name:"Micronesia",pattern:"",emoji:"🇫🇲"},{phoneCode:"373",code:"MD",name:"Moldova",pattern:"373 XX XXX XXX",emoji:"🇲🇩"},{phoneCode:"377",code:"MC",name:"Monaco",pattern:"377 XXXX XXXX",emoji:"🇲🇨"},{phoneCode:"976",code:"MN",name:"Mongolia",pattern:"",emoji:"🇲🇳"},{phoneCode:"382",code:"ME",name:"Montenegro",pattern:"",emoji:"🇲🇪"},{phoneCode:"1 664",code:"MS",name:"Montserrat",pattern:"1664 XXX XXXX",emoji:"🇲🇸"},{phoneCode:"212",code:"MA",name:"Morocco",pattern:"212 XX XXX XXXX",emoji:"🇲🇦"},{phoneCode:"258",code:"MZ",name:"Mozambique",pattern:"258 XX XXX XXXX",emoji:"🇲🇿"},{phoneCode:"264",code:"NA",name:"Namibia",pattern:"264 XX XXX XXXX",emoji:"🇳🇦"},{phoneCode:"674",code:"NR",name:"Nauru",pattern:"",emoji:"🇳🇷"},{phoneCode:"977",code:"NP",name:"Nepal",pattern:"",emoji:"🇳🇵"},{phoneCode:"31",code:"NL",name:"Netherlands",pattern:"31 X XX XX XX XX",emoji:"🇳🇱"},{phoneCode:"687",code:"NC",name:"New Caledonia",pattern:"",emoji:"🇳🇨"},{phoneCode:"64",code:"NZ",name:"New Zealand",pattern:"",emoji:"🇳🇿"},{phoneCode:"505",code:"NI",name:"Nicaragua",pattern:"505 XXXX XXXX",emoji:"🇳🇮"},{phoneCode:"227",code:"NE",name:"Niger",pattern:"227 XX XX XX XX",emoji:"🇳🇪"},{phoneCode:"234",code:"NG",name:"Nigeria",pattern:"",emoji:"🇳🇬"},{phoneCode:"683",code:"NU",name:"Niue",pattern:"",emoji:"🇳🇺"},{phoneCode:"672",code:"NF",name:"Norfolk Island",pattern:"",emoji:"🇳🇫"},{phoneCode:"1 670",code:"MP",name:"Northern Mariana Islands",pattern:"1670 XXX XXXX",emoji:"🇲🇵"},{phoneCode:"47",code:"NO",name:"Norway",pattern:"47 XXXX XXXX",emoji:"🇳🇴"},{phoneCode:"968",code:"OM",name:"Oman",pattern:"968 XXXX XXXX",emoji:"🇴🇲"},{phoneCode:"92",code:"PK",name:"Pakistan",pattern:"92 XXX XXX XXXX",emoji:"🇵🇰"},{phoneCode:"680",code:"PW",name:"Palau",pattern:"",emoji:"🇵🇼"},{phoneCode:"970",code:"PS",name:"Palestinian Territories",pattern:"970 XXX XX XXXX",emoji:"🇵🇸"},{phoneCode:"507",code:"PA",name:"Panama",pattern:"507 XXXX XXXX",emoji:"🇵🇦"},{phoneCode:"675",code:"PG",name:"Papua New Guinea",pattern:"",emoji:"🇵🇬"},{phoneCode:"595",code:"PY",name:"Paraguay",pattern:"595 XXX XXX XXX",emoji:"🇵🇾"},{phoneCode:"51",code:"PE",name:"Peru",pattern:"51 XXX XXX XXX",emoji:"🇵🇪"},{phoneCode:"63",code:"PH",name:"Philippines",pattern:"63 XXX XXX XXXX",emoji:"🇵🇭"},{phoneCode:"64",code:"PN",name:"Pitcairn Islands",pattern:"",emoji:"🇵🇳"},{phoneCode:"48",code:"PL",name:"Poland",pattern:"48 XXX XXX XXX",emoji:"🇵🇱"},{phoneCode:"351",code:"PT",name:"Portugal",pattern:"351 X XXXX XXXX",emoji:"🇵🇹"},{phoneCode:"1 787 and 1 939",code:"PR",name:"Puerto Rico",pattern:"1 XXX XXX XXXX",emoji:"🇵🇷"},{phoneCode:"974",code:"QA",name:"Qatar",pattern:"",emoji:"🇶🇦"},{phoneCode:"262",code:"RE",name:"Reunion",pattern:"262 XXX XXX XXX",emoji:"🇷🇪"},{phoneCode:"40",code:"RO",name:"Romania",pattern:"40 XXX XXX XXX",emoji:"🇷🇴"},{phoneCode:"7",code:"RU",name:"Russia",pattern:"7 XXX XXX XX XX",emoji:"🇷🇺"},{phoneCode:"250",code:"RW",name:"Rwanda",pattern:"250 XXX XXX XXX",emoji:"🇷🇼"},{phoneCode:"590",code:"BL",name:"St. Barthelemy",pattern:"",emoji:"🇧🇱"},{phoneCode:"290",code:"SH",name:"St. Helena",pattern:"290 XX XXX",emoji:"🇸🇭"},{phoneCode:"1 869",code:"KN",name:"St. Kitts & Nevis",pattern:"1869 XXX XXXX",emoji:"🇰🇳"},{phoneCode:"1 758",code:"LC",name:"St. Lucia",pattern:"1758 XXX XXXX",emoji:"🇱🇨"},{phoneCode:"590",code:"MF",name:"St. Martin (France)",pattern:"",emoji:"🇲🇫"},{phoneCode:"508",code:"PM",name:"St. Pierre and Miquelon",pattern:"",emoji:"🇵🇲"},{phoneCode:"1 784",code:"VC",name:"St. Vincent and the Grenadines",pattern:"1784 XXX XXXX",emoji:"🇻🇨"},{phoneCode:"685",code:"WS",name:"Samoa",pattern:"",emoji:"🇼🇸"},{phoneCode:"378",code:"SM",name:"San Marino",pattern:"378 XXX XXX XXXX",emoji:"🇸🇲"},{phoneCode:"239",code:"ST",name:"São Tome & Principe",pattern:"239 XX XXXXX",emoji:"🇸🇹"},{phoneCode:"966",code:"SA",name:"Saudi Arabia",pattern:"",emoji:"🇸🇦"},{phoneCode:"221",code:"SN",name:"Senegal",pattern:"221 XX XXX XXXX",emoji:"🇸🇳"},{phoneCode:"381",code:"RS",name:"Serbia",pattern:"381 XX XXX XXXX",emoji:"🇷🇸"},{phoneCode:"248",code:"SC",name:"Seychelles",pattern:"248 X XX XX XX",emoji:"🇸🇨"},{phoneCode:"232",code:"SL",name:"Sierra Leone",pattern:"232 XX XXX XXX",emoji:"🇸🇱"},{phoneCode:"65",code:"SG",name:"Singapore",pattern:"65 XXXX XXXX",emoji:"🇸🇬"},{phoneCode:"599 3",code:"BQ",name:"Sint Eustatius",pattern:"",emoji:"🇧🇶"},{phoneCode:"1 721",code:"SX",name:"Sint Maarten",pattern:"1721 XXX XXXX",emoji:"🇸🇽"},{phoneCode:"421",code:"SK",name:"Slovakia",pattern:"",emoji:"🇸🇰"},{phoneCode:"386",code:"SI",name:"Slovenia",pattern:"",emoji:"🇸🇮"},{phoneCode:"677",code:"SB",name:"Solomon Islands",pattern:"",emoji:"🇸🇧"},{phoneCode:"252",code:"SO",name:"Somalia",pattern:"252 XX XXX XXX",emoji:"🇸🇴"},{phoneCode:"27",code:"ZA",name:"South Africa",pattern:"27 XX XXX XXXX",emoji:"🇿🇦"},{phoneCode:"500",code:"GS",name:"South Georgia & South Sandwich Islands",pattern:"",emoji:"🇬🇸"},{phoneCode:"995 34",code:"",name:"South Ossetia",pattern:"",emoji:""},{phoneCode:"211",code:"SS",name:"South Sudan",pattern:"211 XX XXX XXXX",emoji:"🇸🇸"},{phoneCode:"34",code:"ES",name:"Spain",pattern:"34 XXX XXX XXX",emoji:"🇪🇸"},{phoneCode:"94",code:"LK",name:"Sri Lanka",pattern:"94 XX XXX XXXX",emoji:"🇱🇰"},{phoneCode:"249",code:"SD",name:"Sudan",pattern:"249 XX XXX XXXX",emoji:"🇸🇩"},{phoneCode:"597",code:"SR",name:"Suriname",pattern:"597 XXX XXXX",emoji:"🇸🇷"},{phoneCode:"47 79",code:"SJ",name:"Svalbard",pattern:"",emoji:"🇸🇯"},{phoneCode:"268",code:"SZ",name:"Swaziland",pattern:"268 XXXX XXXX",emoji:"🇸🇿"},{phoneCode:"46",code:"SE",name:"Sweden",pattern:"46 XX XXX XXXX",emoji:"🇸🇪"},{phoneCode:"41",code:"CH",name:"Switzerland",pattern:"41 XX XXX XXXX",emoji:"🇨🇭"},{phoneCode:"963",code:"SY",name:"Syria",pattern:"",emoji:"🇸🇾"},{phoneCode:"886",code:"TW",name:"Taiwan",pattern:"",emoji:"🇹🇼"},{phoneCode:"992",code:"TJ",name:"Tajikistan",pattern:"",emoji:"🇹🇯"},{phoneCode:"255",code:"TZ",name:"Tanzania",pattern:"255 XX XXX XXXX",emoji:"🇹🇿"},{phoneCode:"66",code:"TH",name:"Thailand",pattern:"66 X XXXX XXXX",emoji:"🇹🇭"},{phoneCode:"228",code:"TG",name:"Togo",pattern:"228 XX XXX XXX",emoji:"🇹🇬"},{phoneCode:"690",code:"TK",name:"Tokelau",pattern:"",emoji:"🇹🇰"},{phoneCode:"676",code:"TO",name:"Tonga",pattern:"",emoji:"🇹🇴"},{phoneCode:"1 868",code:"TT",name:"Trinidad & Tobago",pattern:"1868 XXX XXXX",emoji:"🇹🇹"},{phoneCode:"216",code:"TN",name:"Tunisia",pattern:"216 XX XXX XXX",emoji:"🇹🇳"},{phoneCode:"90",code:"TR",name:"Turkey",pattern:"90 XXX XXX XXXX",emoji:"🇹🇷"},{phoneCode:"993",code:"TM",name:"Turkmenistan",pattern:"993 XX XXXXXX",emoji:"🇹🇲"},{phoneCode:"1 649",code:"TC",name:"Turks & Caicos Islands",pattern:"1649 XXX XXXX",emoji:"🇹🇨"},{phoneCode:"688",code:"TV",name:"Tuvalu",pattern:"",emoji:"🇹🇻"},{phoneCode:"256",code:"UG",name:"Uganda",pattern:"256 XX XXX XXXX",emoji:"🇺🇬"},{phoneCode:"380",code:"UA",name:"Ukraine",pattern:"380 XX XXX XX XX",emoji:"🇺🇦"},{phoneCode:"971",code:"AE",name:"United Arab Emirates",pattern:"971 XX XXX XXXX",emoji:"🇦🇪"},{phoneCode:"44",code:"GB",name:"United Kingdom",pattern:"44 XXXX XXXXXX",emoji:"🇬🇧"},{phoneCode:"1",code:"US",name:"United States",pattern:"1 XXX XXX XXXX",emoji:"🇺🇸"},{phoneCode:"598",code:"UY",name:"Uruguay",pattern:"598 XXXX XXXX",emoji:"🇺🇾"},{phoneCode:"1 340",code:"VI",name:"U.S. Virgin Islands",pattern:"1340 XXX XXXX",emoji:"🇻🇮"},{phoneCode:"998",code:"UZ",name:"Uzbekistan",pattern:"998 XX XXXXXXX",emoji:"🇺🇿"},{phoneCode:"678",code:"VU",name:"Vanuatu",pattern:"",emoji:"🇻🇺"},{phoneCode:"58",code:"VE",name:"Venezuela",pattern:"58 XXX XXX XXXX",emoji:"🇻🇪"},{phoneCode:"39 06 698",code:"VA",name:"Vatican City",pattern:"",emoji:"🇻🇦"},{phoneCode:"84",code:"VN",name:"Vietnam",pattern:"",emoji:"🇻🇳"},{phoneCode:"681",code:"WF",name:"Wallis & Futuna",pattern:"",emoji:"🇼🇫"},{phoneCode:"967",code:"YE",name:"Yemen",pattern:"967 XXX XXX XXX",emoji:"🇾🇪"},{phoneCode:"260",code:"ZM",name:"Zambia",pattern:"260 XX XXX XXXX",emoji:"🇿🇲"},{phoneCode:"255",code:"",name:"Zanzibar",pattern:"",emoji:""},{phoneCode:"263",code:"ZW",name:"Zimbabwe",pattern:"263 XX XXX XXXX",emoji:"🇿🇼"}],n={1:i.find(e=>"United States"===e.name),44:i.find(e=>"United Kingdom"===e.name),61:i.find(e=>"Australia"===e.name),64:i.find(e=>"New Zealand"===e.name),246:i.find(e=>"Diego Garcia"===e.name),255:i.find(e=>"Tanzania"===e.name),262:i.find(e=>"Reunion"===e.name),500:i.find(e=>"Falkland Islands"===e.name),590:i.find(e=>"Guadeloupe"===e.name),672:i.find(e=>"Norfolk Island"===e.name),"1 268":i.find(e=>"Antigua & Barbuda"===e.name)};a.a.Countries=i,t.b=i},function(e,t,s){"use strict";s.d(t,"a",(function(){return a}));const a=1271266957},function(e,t,s){"use strict";s.d(t,"a",(function(){return o}));var a=s(48);const i=new Map,n=new Set,o='Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif';let r;const d=()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(l)},l=()=>{n.forEach(c),n.clear()};window.addEventListener("resize",()=>{for(const[e]of i)n.add(e);d()},{capture:!0,passive:!0});const c=e=>{let t=i.get(e);const s=!t;let{text:n,textLength:r,from:d,multiplier:l,font:c,textWidth:h,elementWidth:g}=t||{};s&&(n=e.textContent,r=n.length,d=50,l=d>0&&d/100,c=`${e.dataset.fontWeight||400} 16px ${o}`,h=u(n,c),g=e.getBoundingClientRect().width,t={text:n,textLength:r,from:d,multiplier:l,font:c,textWidth:h,elementWidth:g},i.set(e,t));const p=e.getBoundingClientRect().width,m=s||g!==p;if(!s&&m&&(t.elementWidth=g=p),m)if(h>g){e.setAttribute("title",n);let s=n,i=g;for(;s.length>3;){let t=s.length;const n=l&&Object(a.a)(l*t<<0,1,t-2)||Math.max(t+d-1,1),o=s.substr(0,n).replace(/\s*$/,""),r=s.substr(n+1).replace(/^\s*/,"");if(s=o+r,i=u(s+"…",c),i<g){e.textContent=o+"…"+r;break}}t.elementWidth=e.getBoundingClientRect().width}else e.removeAttribute("title")};let h;function u(e,t){if(!h){const e=document.createElement("canvas");h=e.getContext("2d"),h.font=t}return h.measureText(e).width}class g extends HTMLElement{constructor(){super()}connectedCallback(){i.set(this,null),n.add(this),d()}disconnectedCallback(){i.delete(this)}}customElements.define("middle-ellipsis-element",g)},,function(e,t,s){"use strict";var a=s(9),i=s(24),n=s(21),o=s(51),r=s(11),d=s(63),l=s(13),c=s(31),h=s(15),u=s(14),g=(s(60),0),p=0;for(g=0;1<<g+1>1<<g;g++);p=(1<<(g>>=1))-1;m(1,1,1),m(0,1,1),new Array(0);function m(e,t,s){var a;a=s>(a=Math.ceil(t/g)+1)?s:a;var i=new Array(a);return f(i,e),i}function f(e,t){var s,a,i=e.length;for(a=t,s=0;s<i;s++)e[s]=a&p,a>>=g}s(42);var _=s(10),v=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};const X=new class{constructor(){this.drafts={},this.getAllDraftPromise=null,u.default.getState().then(e=>{this.drafts=e.drafts,u.default.addEventListener("save",()=>v(this,void 0,void 0,(function*(){u.default.pushToState("drafts",this.drafts)})))}),a.default.addMultipleEventsListeners({updateDraftMessage:e=>{const t=i.a.getPeerId(e.peer);this.saveDraft(t,e.threadId,e.draft,{notify:!0})}})}getKey(e,t){return e+(t?"_"+t:"")}getDraft(e,t){return this.drafts[this.getKey(e,t)]}addMissedDialogs(){return this.getAllDrafts().then(()=>{for(const e in this.drafts){if(-1!==e.indexOf("_"))continue;const t=+e;n.a.getDialogByPeerId(t)[0]||n.a.reloadConversation(t)}})}getAllDrafts(){return this.getAllDraftPromise||(this.getAllDraftPromise=new Promise(e=>{l.a.invokeApi("messages.getAllDrafts").then(t=>{(o.a.updatesState.syncLoading||Promise.resolve()).then(()=>{o.a.processUpdateMessage(t)}),e()})}))}saveDraft(e,t,s,i={}){const n=this.processApiDraft(s),o=this.getKey(e,t);return n?this.drafts[o]=n:delete this.drafts[o],i.notify&&a.default.broadcast("draft_updated",{peerId:e,threadId:t,draft:n}),n}draftsAreEqual(e,t){if(typeof e!=typeof t)return!1;if(!function(e){return"object"==typeof e&&null!==e}(e))return!0;if(e._!==t._)return!1;if("draftMessage"===e._&&t._===e._){if(e.reply_to_msg_id!==t.reply_to_msg_id)return!1;if(!Object(h.b)(e.entities,t.entities))return!1;if(e.message!==t.message)return!1;if(e.pFlags.no_webpage!==t.pFlags.no_webpage)return!1}return!0}isEmptyDraft(e){return!e||"draftMessageEmpty"===e._||!(e.reply_to_msg_id>0)&&!e.message.length}processApiDraft(e){if(!e||"draftMessage"!==e._)return;const t=r.b.parseEntities(e.message),s=e.entities||[],a=r.b.mergeEntities(s,t);return e.rMessage=r.b.wrapDraftText(e.message,{entities:a}),e.reply_to_msg_id&&(e.reply_to_msg_id=n.a.generateMessageId(e.reply_to_msg_id)),e}syncDraft(e,t,s,a=!0){return v(this,void 0,void 0,(function*(){const o=this.getDraft(e,t);if(this.draftsAreEqual(o,s))return!0;let r,h={peer:i.a.getInputPeerById(e),message:""};if(this.isEmptyDraft(s))r={_:"draftMessageEmpty"};else{let e=s.message,t=s.entities;s.reply_to_msg_id&&(h.reply_to_msg_id=n.a.getServerMessageId(s.reply_to_msg_id)),(null==t?void 0:t.length)&&(h.entities=t),s.pFlags.no_webpage&&(h.no_webpage=s.pFlags.no_webpage),h.message=e}const u=r||s;return u.date=Object(c.g)(!0)+d.a.serverTimeOffset,this.saveDraft(e,t,u,{notify:!0}),!(a&&!t)||l.a.invokeApi("messages.saveDraft",h)}))}};_.a.appDraftsManager=X;t.a=X},function(e,t,s){"use strict";s.d(t,"a",(function(){return d}));var a=s(50),i=s(69),n=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};var o=new class{constructor(){this.blobSupported=!0;try{Object(i.a)([],"")}catch(e){this.blobSupported=!1}}isAvailable(){return this.blobSupported}write(e,t){return t instanceof Blob?new Promise((s,a)=>{let i=new FileReader;i.onload=function(t){let i=t.target.result,n=new Uint8Array(i);e.write(n).then(s,a)},i.readAsArrayBuffer(t)}):e.write(t)}getFakeFileWriter(e,t){const s=[];return{write:e=>n(this,void 0,void 0,(function*(){if(!this.blobSupported)throw!1;s.push(e)})),truncate:()=>{s.length=0},finalize:(a=!0)=>{const n=Object(i.a)(s,e);return a&&t&&t(n),n}}}},r=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};class d{constructor(e){this.dbName=e,this.useStorage=!0,a.a.test&&(this.dbName+="_test"),this.openDatabase(),d.STORAGES.push(this)}openDatabase(){return this.openDbPromise?this.openDbPromise:this.openDbPromise=caches.open(this.dbName)}delete(e){return this.timeoutOperation(t=>t.delete("/"+e))}deleteAll(){return caches.delete(this.dbName)}save(e,t){return this.useStorage?this.timeoutOperation(s=>s.put("/"+e,t)):Promise.reject("STORAGE_OFFLINE")}saveFile(e,t){return this.useStorage?(t instanceof Blob||(t=Object(i.a)(t)),this.save(e,new Response(t)).then(()=>t)):Promise.reject("STORAGE_OFFLINE")}getFile(e,t="blob"){return this.useStorage?this.timeoutOperation(s=>r(this,void 0,void 0,(function*(){const a=yield s.match("/"+e);if(!a||!s)throw"NO_ENTRY_FOUND";return a[t]()}))):Promise.reject("STORAGE_OFFLINE")}timeoutOperation(e){return new Promise((t,s)=>r(this,void 0,void 0,(function*(){let a=!1;const i=setTimeout(()=>{s(),a=!0},15e3);try{const s=yield this.openDatabase();if(!s)throw"no cache?";const i=yield e(s);if(a)return;t(i)}catch(e){s(e)}clearTimeout(i)})))}getFileWriter(e,t){const s=o.getFakeFileWriter(t,t=>this.saveFile(e,t));return Promise.resolve(s)}static toggleStorage(e){return Promise.all(this.STORAGES.map(t=>{if(t.useStorage=e,!e)return t.deleteAll()}))}}d.STORAGES=[]},function(e,t,s){"use strict";s.d(t,"a",(function(){return c}));var a=s(10);const i=[1,57,41,21,203,34,97,73,227,91,149,62,105,45,39,137,241,107,3,173,39,71,65,238,219,101,187,87,81,151,141,133,249,117,221,209,197,187,177,169,5,153,73,139,133,127,243,233,223,107,103,99,191,23,177,171,165,159,77,149,9,139,135,131,253,245,119,231,224,109,211,103,25,195,189,23,45,175,171,83,81,79,155,151,147,9,141,137,67,131,129,251,123,30,235,115,113,221,217,53,13,51,50,49,193,189,185,91,179,175,43,169,83,163,5,79,155,19,75,147,145,143,35,69,17,67,33,65,255,251,247,243,239,59,29,229,113,111,219,27,213,105,207,51,201,199,49,193,191,47,93,183,181,179,11,87,43,85,167,165,163,161,159,157,155,77,19,75,37,73,145,143,141,35,138,137,135,67,33,131,129,255,63,250,247,61,121,239,237,117,29,229,227,225,111,55,109,216,213,211,209,207,205,203,201,199,197,195,193,48,190,47,93,185,183,181,179,178,176,175,173,171,85,21,167,165,41,163,161,5,79,157,78,154,153,19,75,149,74,147,73,144,143,71,141,140,139,137,17,135,134,133,66,131,65,129,1],n=[0,9,10,10,14,12,14,14,16,15,16,15,16,15,15,17,18,17,12,18,16,17,17,19,19,18,19,18,18,19,19,19,20,19,20,20,20,20,20,20,15,20,19,20,20,20,21,21,21,20,20,20,21,18,21,21,21,21,20,21,17,21,21,21,22,22,21,22,22,21,22,21,19,22,22,19,20,22,22,21,21,21,22,22,22,18,22,22,21,22,22,23,22,20,23,22,22,23,23,21,19,21,21,21,23,23,23,22,23,23,21,23,22,23,18,22,23,20,22,23,23,23,21,22,20,22,21,22,24,24,24,24,24,22,21,24,23,23,24,21,24,23,24,22,24,24,22,24,24,22,23,24,24,24,20,23,22,23,24,24,24,24,24,24,24,23,21,23,22,23,24,24,24,22,24,24,24,23,22,24,24,25,23,25,25,23,24,25,25,24,22,25,25,25,24,23,24,25,25,25,25,25,25,25,25,25,25,25,25,23,25,23,24,25,25,25,25,25,25,25,25,25,24,22,25,25,23,25,25,20,24,25,24,25,25,22,24,25,24,25,24,25,25,24,25,25,25,25,22,25,25,25,24,25,24,25,18];var o=s(91);const r=a.b&&!1;function d(e,t,s){return new Promise(a=>{const o=new Image,d=performance.now();r&&console.log("[blur] start"),o.onload=()=>{const e=document.createElement("canvas");e.width=o.width,e.height=o.height;const l=e.getContext("2d");l.drawImage(o,0,0),function(e,t,s,a,o,r,d){if(Number.isNaN(r)||r<1)return;r|=0,Number.isNaN(d)&&(d=1),(d|=0)>3&&(d=3),d<1&&(d=1);const l=e.getImageData(t,s,a,o),c=l.data;let h,u,g,p,m,f,_,v,X,b,y,C,P=a-1,M=o-1,I=r+1,w=[],S=[],k=[],A=i[r],D=n[r],F=[],T=[];for(;d-- >0;){for(C=y=0,m=0;m<o;m++){for(h=c[C]*I,u=c[C+1]*I,g=c[C+2]*I,f=1;f<=r;f++)_=C+((f>P?P:f)<<2),h+=c[_++],u+=c[_++],g+=c[_++];for(p=0;p<a;p++)w[y]=h,S[y]=u,k[y]=g,0==m&&(F[p]=((_=p+I)<P?_:P)<<2,T[p]=(_=p-r)>0?_<<2:0),v=C+F[p],X=C+T[p],h+=c[v++]-c[X++],u+=c[v++]-c[X++],g+=c[v++]-c[X++],y++;C+=a<<2}for(p=0;p<a;p++){for(b=p,h=w[b]*I,u=S[b]*I,g=k[b]*I,f=1;f<=r;f++)b+=f>M?0:a,h+=w[b],u+=S[b],g+=k[b];for(y=p<<2,m=0;m<o;m++)c[y]=h*A>>>D,c[y+1]=u*A>>>D,c[y+2]=g*A>>>D,0==p&&(F[m]=((_=m+I)<M?_:M)*a,T[m]=(_=m-r)>0?_*a:0),v=p+F[m],X=p+T[m],h+=w[v]-w[X],u+=S[v]-S[X],g+=k[v]-k[X],y+=a<<2}}e.putImageData(l,t,s)}(l,0,0,e.width,e.height,t,s),e.toBlob(e=>{a(URL.createObjectURL(e)),r&&console.log(`[blur] end, radius: ${t}, iterations: ${s}, time: ${performance.now()-d}`)})},o.src=e})}const l={};function c(e,t=2,s=2){return l[e]?l[e]:l[e]=new Promise(a=>{Object(o.a)({items:[[e,t,s]],context:null,process:d}).then(e=>{a(e[0])})})}},,function(e,t,s){"use strict";s.d(t,"a",(function(){return l}));var a=s(30),i=s(43),n=s(16),o=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};const r=[];let d=!1;function l(e){return e.items.length?(e.promise=Object(a.a)(),r.push(e),function e(){if(!d){(function(e){if(!e.items.length)return e.promise.resolve([]),Promise.resolve([]);const t=e.items.slice(),s=[];return new Promise((a,r)=>{const d=()=>o(this,void 0,void 0,(function*(){const o=performance.now();do{yield Object(i.c)();const a=e.process.apply(e.context,t.shift());let n;if(a instanceof Promise)try{n=yield a}catch(e){return void r(e)}else n=a;s.push(n)}while(t.length>0&&performance.now()-o<6);t.length>0?Object(n.c)(d):a(s)}));Object(n.c)(d)}).then(e.promise.resolve,e.promise.reject)})(r.shift()).finally(()=>{d=!1,r.length&&e()})}}(),e.promise):Promise.resolve([])}},function(e,t,s){"use strict";var a=s(10),i=s(1),n=s(26),o=function(e,t,s,a){return new(s||(s=Promise))((function(i,n){function o(e){try{d(a.next(e))}catch(e){n(e)}}function r(e){try{d(a.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((a=a.apply(e,t||[])).next())}))};const r=new class{constructor(){this.sampleRate=48e3,this.tasks=[],this.keepAlive=!1,this.log=Object(n.b)("OPUS",n.a.error)}isPlaySupported(){if(void 0!==this.isPlaySupportedResult)return this.isPlaySupportedResult;const e=document.createElement("audio");return this.isPlaySupportedResult=!(!e.canPlayType||!e.canPlayType("audio/ogg;").replace(/no/,""))}loadWavWorker(){this.wavWorker||(this.wavWorker=new Worker("waveWorker.min.js"),this.wavWorker.addEventListener("message",e=>{const t=e.data;if(this.log("[WAV] got message:",t),t&&t.page){const e=t.page;this.onTaskEnd(this.tasks.shift(),e)}}))}loadWorker(){this.worker||(this.worker=new Worker("decoderWorker.min.js"),this.worker.addEventListener("message",e=>{const t=e.data;this.log("[DECODER] got message",t),"done"===t.type?(this.wavWorker.postMessage({command:"done"}),t.waveform&&(this.tasks[0].waveform=t.waveform)):this.wavWorker.postMessage({command:"encode",buffers:e.data},i.isSafari?void 0:t.map(e=>e.buffer))}))}setKeepAlive(e){this.keepAlive=e,this.keepAlive?(this.loadWorker(),this.loadWavWorker()):this.tasks.length||this.terminateWorkers()}onTaskEnd(e,t){t?(clearTimeout(e.timeout),e.callback.resolve({bytes:t,waveform:e.waveform})):e.callback.reject("timeout"),this.tasks.length&&this.executeNewTask(this.tasks[0]),this.terminateWorkers()}terminateWorkers(e=!1){(!this.keepAlive&&!this.tasks.length||e)&&(this.worker&&(this.worker.terminate(),this.worker=null),this.wavWorker&&(this.wavWorker.terminate(),this.wavWorker=null))}executeNewTask(e){this.worker.postMessage({command:"init",decoderSampleRate:this.sampleRate,outputBufferSampleRate:this.sampleRate}),this.wavWorker.postMessage({command:"init",wavBitDepth:16,wavSampleRate:this.sampleRate}),this.log("[DECODER] send decode"),this.worker.postMessage({command:"decode",pages:e.pages,waveform:e.withWaveform},i.isSafari?void 0:[e.pages.buffer]),e.timeout=window.setTimeout(()=>{this.log.error("decode timeout"),this.terminateWorkers(!0),this.tasks.length&&(this.loadWorker(),this.loadWavWorker()),this.onTaskEnd(this.tasks.shift())},1e4)}pushDecodeTask(e,t){return new Promise((s,a)=>{const i={pages:e,withWaveform:t,callback:{resolve:s,reject:a},timeout:0};this.loadWorker(),this.loadWavWorker(),1===this.tasks.push(i)&&this.executeNewTask(i)})}decode(e,t=!1){return o(this,void 0,void 0,(function*(){return this.pushDecodeTask(e,t).then(e=>{const t=new Blob([e.bytes],{type:"audio/wav"});return{url:URL.createObjectURL(t),waveform:e.waveform}})}))}};a.a.opusDecodeController=r,t.a=r},function(e,t,s){"use strict";var a=s(35),i=s(38),n=s(11),o=s(9),r=s(15),d=s(33);t.a=new class{constructor(){this.webpages={},this.pendingWebPages={},o.default.addMultipleEventsListeners({updateWebPage:e=>{this.saveWebPage(e.webpage)}})}saveWebPage(e,t,s){e.photo&&"photo"===e.photo._?e.photo=a.a.savePhoto(e.photo,s):delete e.photo,e.document&&"document"===e.document._?e.document=i.a.saveDoc(e.document,s):("document"===e.type&&delete e.type,delete e.document);const l=e.site_name;let c=e.title||e.author||l||"";l&&c===l&&delete e.site_name,c=Object(d.g)(c,80,100),e.rTitle=n.a.wrapRichText(c,{noLinks:!0,noLinebreaks:!0});let h="";if("GitHub"===l){const t=e.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/);t&&(h=t[0]+"/issues/{1}")}const u=Object(d.g)(e.description||"",150,180);if(e.rDescription=n.a.wrapRichText(u,{contextSite:l||"external",contextHashtag:h}),"photo"!==e.type&&"video"!==e.type&&"gif"!==e.type&&"document"!==e.type&&!e.description&&e.photo&&(e.type="photo"),t&&(void 0===this.pendingWebPages[e.id]&&(this.pendingWebPages[e.id]={}),this.pendingWebPages[e.id][t]=!0),void 0===this.webpages[e.id]?this.webpages[e.id]=e:Object(r.i)(this.webpages[e.id],e),!t&&void 0!==this.pendingWebPages[e.id]){const t=[];for(const s in this.pendingWebPages[e.id])t.push(+s);o.default.broadcast("webpage_updated",{id:e.id,msgs:t})}return e}deleteWebPageFromPending(e,t){const s=e.id;this.pendingWebPages[s]&&this.pendingWebPages[s][t]&&(delete this.pendingWebPages[s][t],Object.keys(this.pendingWebPages[s]).length||delete this.pendingWebPages[s])}getWebPage(e){return this.webpages[e]}}},function(e,t,s){"use strict";var a;s.d(t,"a",(function(){return a})),s.d(t,"b",(function(){return i})),function(e){e[e.None=0]="None",e[e.Top=1]="Top",e[e.Bottom=2]="Bottom",e[e.Both=4]="Both"}(a||(a={}));class i{constructor(){const e=this;this.sliceConstructor=class extends Array{constructor(...t){super(...t),this.end=a.None,this.slicedArray=e}isEnd(t){if(this.end&t)return!0;if(t===a.Top){const s=e.last;return!!(s.end&t)&&(this.includes(s[s.length-1])||!s.length)}if(t===a.Bottom){const s=e.first;return!!(s.end&t)&&(this.includes(s[0])||!s.length)}return!1}setEnd(e){this.end|=e,e!==a.Both&&this.end&a.Top&&this.end&a.Bottom&&(this.end|=a.Both)}};const t=this.constructSlice();t.setEnd(a.Bottom),this.slices=[t]}constructSlice(...e){return new this.sliceConstructor(...e)}insertSlice(e){if(!e.length)return;const t=this.slices[0];if(!t.length)return void t.push(...e);const s=e[e.length-1],a=e[0];let i,n=-1,o=-1;for(let e=0;e<this.slices.length&&(i=this.slices[e],n=i.indexOf(s),o=i.indexOf(a),-1===o||-1===n)&&(-1===o&&-1===n);++e);if(-1!==o&&-1!==n);else if(-1!==o){const t=e.slice(i.length-o);i.push(...t)}else if(-1!==n){const t=e.slice(0,e.length-n-1);i.unshift(...t)}else{let t=0;for(const s=this.slices.length;t<s;++t){const s=this.slices[t];if(e[0]>s[0])break}this.slices.splice(t,0,this.constructSlice(...e))}this.flatten()}flatten(){if(!(this.slices.length<2))for(let e=0,t=this.slices.length;e<t-1;++e){const s=this.slices[e],a=this.slices[e+1];-1!==s.indexOf(a[0])&&(s.setEnd(a.end),this.slices.splice(e+1,1),t--,this.insertSlice(a))}}get first(){return this.slices[0]}get last(){return this.slices[this.slices.length-1]}get slice(){return this.first}get length(){return this.slice.length}findSlice(e){for(let t=0;t<this.slices.length;++t){const s=this.slices[t],a=s.indexOf(e);if(-1!==a)return{slice:s,index:a}}}findSliceOffset(e){let t;for(let s=0;s<this.slices.length;++s){let a=0;if(t=this.slices[s],!(t.length<2))for(;a<t.length;a++)if(e>=t[a])return{slice:t,offset:e===t[a]?a:a-1}}if(t&&t.isEnd(a.Top))return{slice:t,offset:t.length}}sliceMe(e,t,s){let i=this.slice,n=0,o=0;if(e){const t=this.findSliceOffset(e);if(!t)return;i=t.slice,n=o=t.offset,i.includes(e)&&(o+=1)}let r=Math.max(o+t,0),d=o+t+s;const l=i.slice(r,d),c=t<0?s+t:s,h=Math.abs(t),u=i.length-o>=c||!!i.isEnd(a.Top)&&(l.setEnd(a.Top),!0),g=o-h>=0||!!i.isEnd(a.Bottom)&&(l.setEnd(a.Bottom),!0);return{slice:l,offsetIdOffset:n,fulfilled:a.None|(u&&g?a.Both:(u?a.Top:a.None)|(g?a.Bottom:a.None))}}unshift(...e){this.first.unshift(...e)}push(...e){this.last.push(...e)}delete(e){const t=this.findSlice(e);t&&t.slice.splice(t.index,1)}}window.slicedArray=new i},,,,,function(e,t,s){e.exports=function(){return new Worker(s.p+"bdc9916fcf69ae974927.worker.js")}},function(e,t,s){e.exports=function(){return new Worker(s.p+"24db672b71bab921b1b3.worker.js")}}]]);
//# sourceMappingURL=2.1e035baa608111b048ce.chunk.js.map