tweb/public/6.ef3cabd15c6b19833f3d.chunk.js
Eduard Kuzmenko 183b0a9a31 Build
2021-07-19 18:29:09 +03:00

2 lines
150 KiB
JavaScript

(this.webpackJsonp=this.webpackJsonp||[]).push([[6],{109:function(e,t,s){"use strict";s.d(t,"a",(function(){return i})),s.d(t,"b",(function(){return n}));var i,a=s(26);!function(e){e[e.None=0]="None",e[e.Top=1]="Top",e[e.Bottom=2]="Bottom",e[e.Both=3]="Both"}(i||(i={}));class n{constructor(){this.sliceConstructor=n.getSliceConstructor(this);const e=this.constructSlice();this.slices=[e]}static getSliceConstructor(e){return class extends Array{constructor(){super(...arguments),this.end=i.None}isEnd(t){if((this.end&t)===t)return!0;let s=!1;if(t===i.Top){const i=e.last;s=!!(i.end&t)&&this.includes(i[i.length-1])}else if(t===i.Bottom){const i=e.first;s=!!(i.end&t)&&this.includes(i[0])}else if(t===i.Both)return this.isEnd(i.Top)&&this.isEnd(i.Bottom);return s&&this.setEnd(t),s}setEnd(e){this.end|=e}unsetEnd(e){this.end^=e}splice(t,s,...a){const n=super.splice(t,s,...a);if(!this.length){const t=e.slices,s=t.indexOf(this);-1!==s&&(1===t.length?this.unsetEnd(i.Both):t.splice(s,1))}return n}}}constructSlice(...e){const t=new this.sliceConstructor(e.length);for(let s=0,i=e.length;s<i;++s)t[s]=e[s];return t}insertSlice(e,t=!0){if(!e.length)return;const s=this.slices[0];if(!s.length)return s.push(...e),s;const i=e[e.length-1],a=e[0];let n,o=-1,r=-1,d=0;for(;d<this.slices.length&&(n=this.slices[d],o=n.indexOf(i),r=n.indexOf(a),-1===r||-1===o)&&(-1===r&&-1===o);++d);if(-1!==r&&-1!==o);else if(-1!==r){const t=e.slice(n.length-r);n.push(...t)}else if(-1!==o){const t=e.slice(0,e.length-o-1);n.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)),d=t}return t?this.flatten(d):void 0}flatten(e){if(this.slices.length>=2)for(let t=0,s=this.slices.length;t<s-1;++t){const i=this.slices[t],a=this.slices[t+1];-1!==i.indexOf(a[0])&&(i.setEnd(a.end),this.slices.splice(t+1,1),t<e&&--e,--s,--t,this.insertSlice(a,!1))}return this.slices[e]}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,s=this.slices.length;t<s;++t){const s=this.slices[t],i=s.indexOf(e);if(-1!==i)return{slice:s,index:i}}}findSliceOffset(e){let t;for(let s=0;s<this.slices.length;++s){let i=0;if(t=this.slices[s],!(t.length<2))for(;i<t.length;i++)if(e>=t[i])return{slice:t,offset:e===t[i]?i:i-1}}if(t&&t.isEnd(i.Top))return{slice:t,offset:t.length}}sliceMe(e,t,s){let a=this.slice,n=0,o=0;if(e){const t=this.findSliceOffset(e);if(!t)return;a=t.slice,n=o=t.offset,a.includes(e)&&(o+=1)}let r=Math.max(o+t,0),d=o+t+s;const l=a.slice(r,d),h=t<0?s+t:s,c=Math.abs(t),g=a.length-o>=h||!!a.isEnd(i.Top)&&(l.setEnd(i.Top),!0),p=o-c>=0||!!a.isEnd(i.Bottom)&&(l.setEnd(i.Bottom),!0);return{slice:l,offsetIdOffset:n,fulfilled:i.None|(g&&p?i.Both:(g?i.Top:i.None)|(p?i.Bottom:i.None))}}unshift(...e){let t=this.first;t.length?t.isEnd(i.Bottom)||(t=this.constructSlice(),t.setEnd(i.Bottom),this.slices.unshift(t)):t.setEnd(i.Bottom),t.unshift(...e)}push(...e){let t=this.last;t.length?t.isEnd(i.Top)||(t=this.constructSlice(),t.setEnd(i.Top),this.slices.push(t)):t.setEnd(i.Top),t.push(...e)}delete(e){const t=this.findSlice(e);return!!t&&(t.slice.splice(t.index,1),!0)}}a.a&&(a.a.SlicedArray=n)},110:function(e,t,s){"use strict";var i=s(26),a=s(30),n=s(41),o=s(27),r=s(28),d=s(13),l=s(58),h=s(39),c=s(38),g=s(34);const p=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.dispatchEvent("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 i;(null===(i=t.pFlags)||void 0===i?void 0:i.chosen)&&e.chosenIndexes.push(s)}))}getPoll(e){return{poll:this.polls[e],results:this.results[e]}}getInputMediaPoll(e,t,s,i){return s?(i||(i=[]),s=r.a.parseMarkdown(s,i)):s=void 0,{_:"inputMediaPoll",poll:e,correct_answers:t,solution:s,solution_entities:s?i:void 0}}sendVote(e,t){const s=e.media.poll,i=t.map(e=>s.answers[e].option),a=e.mid,n=e.peerId,r=c.a.getInputPeerById(n);return e.pFlags.is_outgoing?h.a.invokeAfterMessageIsSent(a,"sendVote",e=>(this.log("invoke sendVote callback"),this.sendVote(e,t))):o.a.invokeApi("messages.sendVote",{peer:r,msg_id:h.a.getServerMessageId(e.mid),options:i}).then(e=>{this.log("sendVote updates:",e),l.a.processUpdateMessage(e)})}getResults(e){const t=c.a.getInputPeerById(e.peerId);return o.a.invokeApi("messages.getPollResults",{peer:t,msg_id:h.a.getServerMessageId(e.mid)}).then(e=>{l.a.processUpdateMessage(e),this.log("getResults updates:",e)})}getVotes(e,t,s,i=20){return o.a.invokeApi("messages.getPollVotes",{peer:c.a.getInputPeerById(e.peerId),id:h.a.getServerMessageId(e.mid),option:t,offset:s,limit:i}).then(e=>(this.log("getPollVotes messages:",e),g.a.saveApiUsers(e.users),e))}stopPoll(e){const t=e.media.poll;if(t.pFlags.closed)return Promise.resolve();const s=Object(a.a)(t);return s.pFlags.closed=!0,h.a.editMessage(e,void 0,{newMedia:this.getInputMediaPoll(s)}).then(()=>{},e=>{this.log.error("stopPoll error:",e)})}};i.a.appPollsManager=p,t.a=p},111:function(e,t,s){"use strict";var i=s(13),a=s(38),n=s(39),o=s(58),r=s(28),d=s(55),l=s(27),h=s(47),c=s(30),g=s(129),p=s(26),u=s(88),f=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.apply(e,t||[])).next())}))};const m=new class{constructor(){this.drafts={},this.getAllDraftPromise=null,u.a.get("drafts").then(e=>{this.drafts=e||{}}),i.default.addMultipleEventsListeners({updateDraftMessage:e=>{const t=a.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.getDialogOnly(t)||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,a={}){const n=this.processApiDraft(s),o=this.getKey(e,t);return n?this.drafts[o]=n:delete this.drafts[o],u.a.set({drafts:this.drafts}),a.notify&&i.default.dispatchEvent("draft_updated",{peerId:e,threadId:t,draft:n}),n}draftsAreEqual(e,t){if(typeof e!=typeof t)return!1;if(!Object(g.a)(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(c.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||[],i=r.b.mergeEntities(s.slice(),t);return e.rMessage=r.b.wrapDraftText(e.message,{entities:i}),e.reply_to_msg_id&&(e.reply_to_msg_id=n.a.generateMessageId(e.reply_to_msg_id)),e}syncDraft(e,t,s,i=!0){return f(this,void 0,void 0,(function*(){const o=this.getDraft(e,t);if(this.draftsAreEqual(o,s))return!0;let r,c={peer:a.a.getInputPeerById(e),message:""};if(this.isEmptyDraft(s))r={_:"draftMessageEmpty"};else{let e=s.message,t=s.entities;s.reply_to_msg_id&&(c.reply_to_msg_id=n.a.getServerMessageId(s.reply_to_msg_id)),(null==t?void 0:t.length)&&(c.entities=n.a.getInputEntities(t)),s.pFlags.no_webpage&&(c.no_webpage=s.pFlags.no_webpage),c.message=e}const g=r||s;return g.date=Object(h.h)(!0)+d.a.serverTimeOffset,this.saveDraft(e,t,g,{notify:!0}),!(i&&!t)||l.a.invokeApi("messages.saveDraft",c)}))}clearAllDrafts(){return l.a.invokeApi("messages.clearAllDrafts").then(e=>{if(e)for(const e in this.drafts){const t=e.split("_"),s=t[1];i.default.dispatchEvent("draft_updated",{peerId:+t[0],threadId:s?+s:void 0,draft:void 0})}})}};p.a.appDraftsManager=m,t.a=m},112:function(e,t,s){"use strict";var i=s(77),a=s(33),n=s(92),o=s(28),r=s(13),d=s(49),l=s(38),h=s(51),c=s(34);const g=new class{constructor(){this.savedAvatarURLs={}}removeFromAvatarsCache(e){this.savedAvatarURLs[e]&&delete this.savedAvatarURLs[e]}loadAvatar(e,t,s){const i=l.a.getInputPeerById(e);let a,n=!1,o=this.savedAvatarURLs[e];if(o&&o[s])"string"!=typeof o[s]?a=o[s]:(a=Promise.resolve(o[s]),n=!0);else{o||(o=this.savedAvatarURLs[e]={});const n={_:"inputPeerPhotoFileLocation",pFlags:{},peer:i,photo_id:t.photo_id};"photo_big"===s&&(n.pFlags.big=!0);const r={dcId:t.dc_id,location:n},l=d.a.download(r);a=o[s]=l.then(e=>o[s]=URL.createObjectURL(e))}return{cached:n,loadPromise:a}}putAvatar(e,t,s,o,d=new Image,l=!1){let c,g,{cached:p,loadPromise:u}=this.loadAvatar(t,s,o);if(p)g=()=>{Object(a.a)(e,d),e.dataset.color=""};else{const t=r.default.settings.animationsEnabled;let o;if(t&&d.classList.add("fade-in"),s.stripped_thumb){o=new Image,e.classList.add("avatar-relative"),o.classList.add("avatar-photo","avatar-photo-thumbnail"),d.classList.add("avatar-photo");const t=h.a.getPreviewURLFromBytes(s.stripped_thumb);c=Object(i.b)(o,t).then(()=>{Object(a.a)(e,o)})}g=()=>{s.stripped_thumb?e.append(d):Object(a.a)(e,d),setTimeout(()=>{e.childElementCount&&n.a.mutateElement(d,()=>{e.dataset.color="",t&&d.classList.remove("fade-in"),o&&o.remove()})},t?200:0)}}const f=u.then(e=>Object(i.b)(d,e)).then(()=>g());return{cached:p,loadPromise:c||f}}putPhoto(e,t,s=!1,i="",a=!1){var n;const d=l.a.getPeerPhoto(t),h=!!d,g=e.firstElementChild&&!e.firstElementChild.classList.contains("emoji"),p=r.default.myId;if(t===p&&s)return e.innerText="",e.dataset.color="",e.classList.add("tgico-saved"),void e.classList.remove("tgico-deletedaccount");if(t>0){const s=c.a.getUser(t);if(s&&s.pFlags&&s.pFlags.deleted)return e.innerText="",e.dataset.color=l.a.getPeerColorById(t),e.classList.add("tgico-deletedaccount"),void e.classList.remove("tgico-saved")}if(!h||!g||!this.savedAvatarURLs[t]){let a,r="";if(!t||t===p&&s||(r=l.a.getPeerColorById(t)),e.innerText="",e.classList.remove("tgico-saved","tgico-deletedaccount"),e.dataset.color=r,i)a=o.b.getAbbreviation(i);else{a=null!==(n=l.a.getPeer(t).initials)&&void 0!==n?n:""}e.innerHTML=a}return h?this.putAvatar(e,t,d,"photo_small",void 0,a):void 0}};t.a=g},113:function(e,t,s){"use strict";s.d(t,"a",(function(){return i}));const i=()=>{let e={cleaned:!1};return{clean:()=>{e.cleaned=!0,e={cleaned:!1}},get:()=>{const t=e;return()=>!t.cleaned}}}},114:function(e,t,s){"use strict";function i(e){}s.d(t,"a",(function(){return i}))},118:function(e,t,s){"use strict";s.d(t,"a",(function(){return o}));var i=s(73);const a=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(h),n.clear()};window.addEventListener("resize",()=>{for(const[e]of a)n.add(e);d()},{capture:!0,passive:!0});const h=e=>{let t=a.get(e);const s=!t;let{text:n,textLength:r,from:d,multiplier:l,font:h,textWidth:c,elementWidth:p}=t||{};s&&(n=e.textContent,r=n.length,d=50,l=d>0&&d/100,h=`${e.dataset.fontWeight||400} 16px ${o}`,c=g(n,h),p=e.getBoundingClientRect().width,t={text:n,textLength:r,from:d,multiplier:l,font:h,textWidth:c,elementWidth:p},a.set(e,t));const u=e.getBoundingClientRect().width,f=s||p!==u;if(!s&&f&&(t.elementWidth=p=u),f)if(c>p){e.setAttribute("title",n);let s=n,a=p;for(;s.length>3;){let t=s.length;const n=l&&Object(i.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,a=g(s+"…",h),a<p){e.textContent=o+"…"+r;break}}t.elementWidth=e.getBoundingClientRect().width}else e.removeAttribute("title")};let c;function g(e,t){if(!c){const e=document.createElement("canvas");c=e.getContext("2d"),c.font=t}return c.measureText(e).width}class p extends HTMLElement{constructor(){super()}connectedCallback(){a.set(this,null),n.add(this),d()}disconnectedCallback(){a.delete(this)}}customElements.define("middle-ellipsis-element",p)},119:function(e,t,s){"use strict";var i=s(39),a=s(70),n=s(30),o=s(26),r=s(27),d=s(114);const l=new class{constructor(){this.contexts=new Map,this.links={},r.a.addTaskListener("refreshReference",e=>{const t=e.payload;Object(d.a)(e),e.originalPayload=t,this.refreshReference(t).then(()=>{e.payload=this.getReferenceByLink(t),r.a.postMessage(e)},t=>{e.error=t,r.a.postMessage(e)})})}saveContext(e,t,s){[s,e]=this.getContexts(e),s||(s=new Set,this.contexts.set(e,s)),this.links[Object(a.e)(e)]=e;for(const e of s)if(Object(n.b)(e,t))return;s.add(t)}getReferenceByLink(e){return this.links[Object(a.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[0]?[t[0].values().next().value,t[1]]:void 0}deleteContext(e,t,s){if([s,e]=this.getContexts(e),s)for(const i of s)if(Object(n.b)(i,t))return s.delete(i),s.size||(this.contexts.delete(e),delete this.links[Object(a.e)(e)]),!0;return!1}refreshReference(e,t){if(!t){const s=this.getContext(e);if(!s)return Promise.reject("NO_CONTEXT");[t,e]=s}let s;switch(null==t?void 0:t.type){case"message":s=i.a.wrapSingleMessage(t.peerId,t.messageId,!0);break;default:return console.warn("FILE_REFERENCE_EXPIRED: not implemented context",t),Promise.reject()}const n=Object(a.e)(e);return s.then(()=>{const s=Object(a.e)(e);if(n!==s)return;this.deleteContext(e,t);const i=this.getContext(e);if(i)return this.refreshReference(e,i[0]);throw"NO_NEW_CONTEXT"})}};o.a.referenceDatabase=l,t.a=l},121:function(e,t,s){"use strict";s.d(t,"a",(function(){return f}));var i=s(43),a=s(72),n=s(32),o=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.apply(e,t||[])).next())}))};const r=[];let d=!1;function l(e,t="push"){return e.items.length?(e.promise=Object(i.a)(),r[t](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((i,r)=>{const d=()=>o(this,void 0,void 0,(function*(){const o=performance.now();do{yield Object(a.c)();const i=e.process.apply(e.context,t.shift());let n;if(i instanceof Promise)try{n=yield i}catch(e){return void r(e)}else n=i;s.push(n)}while(t.length>0&&performance.now()-o<6);t.length>0?Object(n.c)(d):i(s)}));Object(n.c)(d)}).then(e.promise.resolve,e.promise.reject)})(r.shift()).finally(()=>{d=!1,r.length&&e()})}}(),e.promise):Promise.resolve([])}const h="filter"in(document.createElement("canvas").getContext("2d")||{});let c,g;function p(e,t,s){return new Promise(i=>{const a=document.createElement("canvas");a.width=e.width,a.height=e.height;const n=a.getContext("2d",{alpha:!1});h?(n.filter=`blur(${t}px)`,n.drawImage(e,2*-t,2*-t,a.width+4*t,a.height+4*t)):(n.drawImage(e,0,0),g(n,0,0,a.width,a.height,t,s)),i(a.toDataURL())})}c=h?Promise.resolve():s.e(30).then(s.bind(null,132)).then(e=>{g=e.default});const u=new Map;function f(e,t=2,s=2){if(!e)return console.error("no dataUri for blur",e),Promise.resolve(e);if(u.size>1e3&&u.clear(),u.has(e))return u.get(e);const i=new Promise(i=>{c.then(()=>{const a=new Image;a.onload=()=>{h?p(a,t,s).then(i):l({items:[[a,t,s]],context:null,process:p},"unshift").then(e=>{i(e[0])})},a.src=e})});return u.set(e,i),i}},125:function(e,t,s){"use strict";var i=s(26),a=s(0),n=s(41),o=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.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},a.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},a.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,i)=>{const a={pages:e,withWaveform:t,callback:{resolve:s,reject:i},timeout:0};this.loadWorker(),this.loadWavWorker(),1===this.tasks.push(a)&&this.executeNewTask(a)})}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}})}))}};i.a.opusDecodeController=r,t.a=r},126:function(e,t,s){"use strict";var i=s(51),a=s(68),n=s(28),o=s(13),r=s(30),d=s(76);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=i.a.savePhoto(e.photo,s):delete e.photo,e.document&&"document"===e.document._?e.document=a.a.saveDoc(e.document,s):("document"===e.type&&delete e.type,delete e.document);const l=e.site_name;let h=e.title||e.author||l||"";l&&h===l&&delete e.site_name,h=Object(d.f)(h,80,100),e.rTitle=n.a.wrapRichText(h,{noLinks:!0,noLinebreaks:!0});let c="";if("GitHub"===l){const t=e.url.match(/(https?:\/\/github\.com\/[^\/]+\/[^\/]+)/);t&&(c=t[0]+"/issues/{1}")}const g=Object(d.f)(e.description||"",150,180);if(e.rDescription=n.a.wrapRichText(g,{contextSite:l||"external",contextHashtag:c}),"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.dispatchEvent("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]}}},127:function(e,t,s){"use strict";function i(e){var t=document.createElement("template");return e=e.trim(),t.innerHTML=e,t.content}s.d(t,"a",(function(){return i}))},129:function(e,t,s){"use strict";s.d(t,"a",(function(){return r}));s(70);var i=0,a=0;for(i=0;1<<i+1>1<<i;i++);a=(1<<(i>>=1))-1;n(1,1,1),n(0,1,1),new Array(0);function n(e,t,s){var a;a=s>(a=Math.ceil(t/i)+1)?s:a;var n=new Array(a);return o(n,e),n}function o(e,t){var s,n,o=e.length;for(n=t,s=0;s<o;s++)e[s]=n&a,n>>=i}s(56);function r(e){return"object"==typeof e&&null!==e}},39:function(e,t,s){"use strict";var i=s(75),a=s(91),n=s(43),o=s(47),r=s(95),d=s(30),l=s(56),h=s(76),c=s(12),g=s(41),p=s(27),u=s(119),f=s(55),m=s(28),_=s(13),v=s(89),M=s(57),y=s(109);class I{constructor(e,t,s,i,a,n,o,r,d){this.appMessagesManager=e,this.appChatsManager=t,this.appPeersManager=s,this.appUsersManager=i,this.appDraftsManager=a,this.appNotificationsManager=n,this.appStateManager=o,this.apiUpdatesManager=r,this.serverTimeManager=d,this.onUpdateFolderPeers=e=>{e.folder_peers.forEach(e=>{var t;const{folder_id:s,peer:i}=e,a=this.appPeersManager.getPeerId(i),n=this.dropDialog(a)[0];n&&((null===(t=n.pFlags)||void 0===t?void 0:t.pinned)&&(delete n.pFlags.pinned,this.pinnedOrders[s].findAndSplice(e=>e===n.peerId),this.appStateManager.pushToState("pinnedOrders",this.pinnedOrders)),n.folder_id=s,this.generateIndexForDialog(n),this.pushDialog(n)),this.appMessagesManager.scheduleHandleNewDialogs(a,n)})},this.onUpdateDialogPinned=e=>{var t;const s=null!==(t=e.folder_id)&&void 0!==t?t:0,i=this.appPeersManager.getPeerId(e.peer.peer),a=this.getDialogOnly(i);a&&(e.pFlags.pinned?a.pFlags.pinned=!0:(delete a.pFlags.pinned,this.pinnedOrders[s].findAndSplice(e=>e===a.peerId),this.appStateManager.pushToState("pinnedOrders",this.pinnedOrders)),this.generateIndexForDialog(a)),this.appMessagesManager.scheduleHandleNewDialogs(i,a)},this.onUpdatePinnedDialogs=e=>{var t;const s=null!==(t=e.folder_id)&&void 0!==t?t:0,i=e=>{this.pinnedOrders[s].length=0,e.reverse(),e.forEach(e=>{a[e]=!0;const t=this.getDialogOnly(e);this.appMessagesManager.scheduleHandleNewDialogs(e,t),t&&(t.pFlags.pinned=!0,this.generateIndexForDialog(t))}),this.getFolder(s,!1).forEach(e=>{const t=e.peerId;e.pFlags.pinned&&!a[t]&&this.appMessagesManager.scheduleHandleNewDialogs(t)})},a={};e.order?i(e.order.map(e=>this.appPeersManager.getPeerId(e.peer))):p.a.invokeApi("messages.getPinnedDialogs",{folder_id:s}).then(e=>{this.applyDialogs(e),i(e.dialogs.map(e=>e.peerId))})},this.storage=this.appStateManager.storages.dialogs,this.dialogs=this.storage.getCache(),this.clear(!0),_.default.addEventListener("language_change",e=>{const t=i.getSelf().id;if(this.getDialogOnly(t)){const e=s.getPeerSearchText(t);this.dialogsIndex.indexObject(t,e)}}),_.default.addMultipleEventsListeners({updateFolderPeers:this.onUpdateFolderPeers,updateDialogPinned:this.onUpdateDialogPinned,updatePinnedDialogs:this.onUpdatePinnedDialogs}),o.getState().then(e=>{this.pinnedOrders=e.pinnedOrders||{},this.pinnedOrders[0]||(this.pinnedOrders[0]=[]),this.pinnedOrders[1]||(this.pinnedOrders[1]=[]);const t=o.storagesResults.dialogs;if(t.length)for(let e=0,s=t.length;e<s;++e){const s=t[e];if(s){s.top_message=this.appMessagesManager.getServerMessageId(s.top_message),s.topMessage&&this.appMessagesManager.saveMessages([s.topMessage]),this.saveDialog(s,void 0,!0);this.appMessagesManager.getMessageByPeer(s.peerId,s.top_message).deleted&&this.appMessagesManager.reloadConversation(s.peerId)}}this.allDialogsLoaded=e.allDialogsLoaded||{}})}isDialogsLoaded(e){return!!this.allDialogsLoaded[e]}setDialogsLoaded(e,t){this.allDialogsLoaded[e]=t,this.appStateManager.pushToState("allDialogsLoaded",this.allDialogsLoaded)}clear(e=!1){if(!e){this.appStateManager.storagesResults.dialogs.length=0,this.storage.clear()}this.byFolders={},this.allDialogsLoaded={},this.dialogsOffsetDate={},this.pinnedOrders={0:[],1:[]},this.dialogsNum=0,this.dialogsIndex=new v.a,this.cachedResults={query:"",count:0,dialogs:[],folderId:0}}resetPinnedOrder(e){this.pinnedOrders[e]=[]}getPinnedOrders(e){return this.pinnedOrders[e]}getOffsetDate(e){return this.dialogsOffsetDate[e]||0}getFolder(e,t=!0){var s,i;if(e<=1){const i=null!==(s=this.byFolders[e])&&void 0!==s?s:this.byFolders[e]=[];return t?i.filter(e=>void 0===e.migratedTo):i}const a=[],n=this.appMessagesManager.filtersStorage.filters[e];for(const e in this.dialogs){const s=this.dialogs[e];if(this.appMessagesManager.filtersStorage.testDialogForFilter(s,n)&&(!t||void 0===s.migratedTo)){let e;const t=n.pinned_peers.indexOf(s.peerId);e=-1!==t?this.generateDialogIndex(this.generateDialogPinnedDateByIndex(n.pinned_peers.length-1-t)):(null===(i=s.pFlags)||void 0===i?void 0:i.pinned)?this.generateIndexForDialog(s,!0):s.index,a.push({dialog:s,index:e})}}return a.sort((e,t)=>t.index-e.index),a.map(e=>e.dialog)}getDialog(e,t,s=!0){const i=[];if(void 0===t){const e=this.byFolders;for(const t in e)i.push(e[t])}else i.push(this.getFolder(t,s));for(let t of i){let i=0,a=0;for(let n=t.length;i<n;++i){const n=t[i];if(n.peerId===e)return[n,i-a];s&&void 0!==n.migratedTo&&++a}}return[]}getDialogOnly(e){return this.dialogs[e]}generateDialogIndex(e){return void 0===e&&(e=Object(o.h)(!0)+this.serverTimeManager.serverTimeOffset),65536*e+(65535&++this.dialogsNum)}generateIndexForDialog(e,t=!1,s){var i;const a=this.appPeersManager.isChannel(e.peerId)?-e.peerId:0;let n=0;if(e.pFlags.pinned&&!t)n=this.generateDialogPinnedDate(e);else{if(s||(s=this.appMessagesManager.getMessageByPeer(e.peerId,e.top_message)),n=s.date||n,a){const e=this.appChatsManager.getChat(a);(!n||e.date&&e.date>n)&&(n=e.date)}"draftMessage"===(null===(i=e.draft)||void 0===i?void 0:i._)&&e.draft.date>n&&(n=e.draft.date)}n||(n=Date.now()/1e3);const o=this.generateDialogIndex(n);if(t)return o;e.index=o}generateDialogPinnedDateByIndex(e){return 2147418112+(65535&e)}generateDialogPinnedDate(e){const t=this.pinnedOrders[e.folder_id],s=t.indexOf(e.peerId);let i=s;return-1===s&&(i=t.push(e.peerId)-1,this.appStateManager.pushToState("pinnedOrders",this.pinnedOrders)),this.generateDialogPinnedDateByIndex(i)}setDialogToState(e){const t=this.appMessagesManager.getHistoryStorage(e.peerId),s=[].concat(t.history.slice);let i;for(let t=0,a=s.length;t<a;++t){const a=s[t],n=this.appMessagesManager.getMessageByPeer(e.peerId,a);if(!n.pFlags.is_outgoing){i=n;const t=n.viaBotId||n.fromId;t!==e.peerId&&this.appStateManager.requestPeer(t,"topMessage_"+e.peerId,1);break}}if(e.topMessage=i,e.peerId<0&&e.pts){const t=this.apiUpdatesManager.getChannelState(-e.peerId,e.pts).pts;e.pts=t}this.storage.set({[e.peerId]:e}),this.appStateManager.requestPeer(e.peerId,"dialog_"+e.peerId,1)}pushDialog(e,t){const s=this.getFolder(e.folder_id,!1),i=s.findIndex(t=>t.peerId===e.peerId);if(-1!==i&&s.splice(i,1),this.dialogs[e.peerId]=e,this.setDialogToState(e),t&&!e.pFlags.pinned&&(!this.dialogsOffsetDate[e.folder_id]||t<this.dialogsOffsetDate[e.folder_id])){if(-1!==i)return!1;this.dialogsOffsetDate[e.folder_id]=t}Object(M.e)(s,e,"index",i)}dropDialog(e){const t=this.getDialog(e,void 0,!1);return t[0]&&(this.byFolders[t[0].folder_id].splice(t[1],1),this.pinnedOrders[t[0].folder_id].findAndSplice(t=>e===t),this.dialogsIndex.indexObject(e,""),delete this.dialogs[e],this.appStateManager.keepPeerSingle(0,"topMessage_"+e),this.appStateManager.keepPeerSingle(0,"dialog_"+e),this.storage.delete(e)),t}applyDialogs(e){Object(M.d)(e.dialogs,(t,s)=>{"dialogFolder"===t._&&e.dialogs.splice(s,1)}),this.appUsersManager.saveApiUsers(e.users),this.appChatsManager.saveApiChats(e.chats),this.appMessagesManager.saveMessages(e.messages),this.appMessagesManager.log("applyConversation",e);const t={};e.dialogs.forEach(e=>{const s=this.appPeersManager.getPeerId(e.peer);let i=e.top_message;const a=this.appMessagesManager.pendingTopMsgs[s];if(a&&(!i||this.appMessagesManager.getMessageByPeer(s,a).date>this.appMessagesManager.getMessageByPeer(s,i).date)&&(e.top_message=i=a,this.appMessagesManager.getHistoryStorage(s).maxId=a),i||e.draft&&"draftMessage"===e.draft._)this.saveDialog(e),t[s]=e;else{const e=this.dropDialog(s);e.length&&_.default.dispatchEvent("dialog_drop",{peerId:s,dialog:e[0]})}const n=this.appMessagesManager.newUpdatesAfterReloadToHandle[s];if(void 0!==n){for(const e of n)this.apiUpdatesManager.saveUpdate(e);delete this.appMessagesManager.newUpdatesAfterReloadToHandle[s]}}),Object.keys(t).length&&_.default.dispatchEvent("dialogs_multiupdate",t)}saveDialog(e,t=0,s=!1){const i=this.appPeersManager.getPeerId(e.peer);if(!i)return void console.error("saveConversation no peerId???",e,t);"dialog"!==e._&&console.error("saveConversation not regular dialog",e,Object.assign({},e));const a=this.appPeersManager.isChannel(i)?-i:0;if(i<0){const e=this.appChatsManager.getChat(-i);if("channelForbidden"===e._||e.pFlags.left||e.pFlags.kicked)return}const n=this.appPeersManager.getPeerSearchText(i);let o,r;if(this.dialogsIndex.indexObject(i,n),e.top_message?(o=this.appMessagesManager.generateMessageId(e.top_message),r=this.appMessagesManager.getMessageByPeer(i,o)):(o=this.appMessagesManager.generateTempMessageId(i),r={_:"message",id:o,mid:o,from_id:this.appPeersManager.getOutputPeer(this.appUsersManager.getSelf().id),peer_id:this.appPeersManager.getOutputPeer(i),deleted:!0,pFlags:{out:!0},date:0,message:""},this.appMessagesManager.saveMessages([r],{isOutgoing:!0})),(null==r?void 0:r.pFlags)||this.appMessagesManager.log.error("saveConversation no message:",e,r),!a&&i<0){const t=this.appChatsManager.getChat(-i);if(t&&t.migrated_to&&t.pFlags.deactivated){const s=this.appPeersManager.getPeerId(t.migrated_to);this.appMessagesManager.migratedFromTo[i]=s,this.appMessagesManager.migratedToFrom[s]=i,e.migratedTo=s}}const l=this.getDialogOnly(i);e.top_message=o,e.read_inbox_max_id=this.appMessagesManager.generateMessageId(l&&!e.read_inbox_max_id?l.read_inbox_max_id:e.read_inbox_max_id),e.read_outbox_max_id=this.appMessagesManager.generateMessageId(l&&!e.read_outbox_max_id?l.read_outbox_max_id:e.read_outbox_max_id),e.hasOwnProperty("folder_id")||"dialog"===e._&&(e.folder_id=l?l.folder_id:t),e.draft=this.appDraftsManager.saveDraft(i,0,e.draft),e.peerId=i,r.pFlags.is_outgoing&&(o>e[r.pFlags.out?"read_outbox_max_id":"read_inbox_max_id"]?r.pFlags.unread=!0:delete r.pFlags.unread);const h=this.appMessagesManager.getHistoryStorage(i),c=h.history.slice;if(c.length){if(!c.isEnd(y.a.Bottom)){h.history.insertSlice([o]).setEnd(y.a.Bottom),this.appMessagesManager.mergeReplyKeyboard(h,r)&&_.default.dispatchEvent("history_reply_markup",{peerId:i})}}else h.history.unshift(o),this.appMessagesManager.mergeReplyKeyboard(h,r)&&_.default.dispatchEvent("history_reply_markup",{peerId:i});h.maxId=o,h.readMaxId=e.read_inbox_max_id,h.readOutboxMaxId=e.read_outbox_max_id,this.appNotificationsManager.savePeerSettings(i,e.notify_settings),a&&e.pts&&this.apiUpdatesManager.addChannelState(a,e.pts),this.generateIndexForDialog(e),l&&Object(d.i)(l,e),this.pushDialog(e,s&&r.date)}getDialogs(e="",t,s=20,i=0){const a=i>1?0:i;let n=this.getFolder(i,!1);if(e){if(!s||this.cachedResults.query!==e||this.cachedResults.folderId!==i){this.cachedResults.query=e,this.cachedResults.folderId=i;const t=this.dialogsIndex.search(e);this.cachedResults.dialogs=[];for(const e in this.dialogs){const s=this.dialogs[e];t.has(s.peerId)&&s.folder_id===i&&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++);const r=this.isDialogsLoaded(a);return e||r||n.length>=o+s?Promise.resolve({dialogs:n.slice(o,o+s),count:r?n.length:null,isEnd:r&&o+s>=n.length}):this.appMessagesManager.getTopMessages(s,a).then(e=>{if(o=0,t>0)for(;o<n.length&&!(t>n[o].index);o++);return{dialogs:n.slice(o,o+s),count:void 0===e.count?n.length:e.count,isEnd:e.isEnd}})}}var b=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.apply(e,t||[])).next())}))};class P{constructor(e,t,s,i,a,n,o){this.appMessagesManager=e,this.appPeersManager=t,this.appUsersManager=s,this.appNotificationsManager=i,this.appStateManager=a,this.apiUpdatesManager=n,this.rootScope=o,this.onUpdateDialogFilter=e=>{e.filter?this.saveDialogFilter(e.filter):this.filters[e.id]&&(this.rootScope.dispatchEvent("filter_delete",this.filters[e.id]),delete this.filters[e.id]),this.appStateManager.pushToState("filters",this.filters)},this.onUpdateDialogFilterOrder=e=>{this.orderIndex=1,e.order.forEach((e,t)=>{const s=this.filters[e];delete s.orderIndex,this.setOrderIndex(s)}),this.rootScope.dispatchEvent("filter_order",e.order),this.appStateManager.pushToState("filters",this.filters)},this.clear(),this.filters={},this.appStateManager.getState().then(e=>{Object(d.i)(this.filters,e.filters);for(const e in this.filters){const t=this.filters[e];t.hasOwnProperty("orderIndex")&&t.orderIndex>=this.orderIndex&&(this.orderIndex=t.orderIndex+1)}}),o.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})}clear(e=!1){e||Object(d.i)(this.filters,{}),this.orderIndex=1}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&&!e.pFlags.unread_mark)return!1;if(s.exclude_muted){if(this.appNotificationsManager.isPeerLocalMuted(e.peerId))return!1}const i=e.peerId;if(i<0){if(s.broadcasts&&this.appPeersManager.isBroadcast(i))return!0;if(s.groups&&this.appPeersManager.isAnyGroup(i))return!0}else{if(this.appPeersManager.isBot(i))return!!s.bots;if(s.non_contacts&&!this.appUsersManager.isContact(i))return!0;if(s.contacts&&this.appUsersManager.isContact(i))return!0}return!1}toggleDialogPin(e,t){const s=this.filters[t];if(!s.pinned_peers.findAndSplice(t=>t===e)){if(s.pinned_peers.length>=this.rootScope.config.pinned_infolder_count_max)return Promise.reject({type:"PINNED_DIALOGS_TOO_MUCH"});s.pinned_peers.unshift(e)}return 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 p.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(M.d)(t.include_peers,(e,s)=>{t.pinned_peers.includes(e)&&t.include_peers.splice(s,1)}),t}getDialogFilters(e=!1){return b(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 p.a.invokeApiSingle("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(M.d)(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.dispatchEvent("filter_update",e)}setOrderIndex(e){e.hasOwnProperty("orderIndex")?e.orderIndex>=this.orderIndex&&(this.orderIndex=e.orderIndex+1):e.orderIndex=this.orderIndex++,this.appStateManager.pushToState("filters",this.filters)}}var S=s(58),w=s(37),E=s(68),D=s(49),k=s(38),C=s(51),x=s(110),A=s(14),F=s(34),O=s(126),T=s(111),U=s(84),L=s(69),R=s(26),j=s(85),B=s(52),N=s(127),H=s(98),z=s(94);const W={s:"Seconds",m:"Minutes",h:"Hours",d:"Days",w:"Weeks"};function V(e){const t=function(e,t=2){e||(e=1);let s=[];const i=[{m:1,t:"s"},{m:60,t:"m"},{m:60,t:"h"},{m:24,t:"d"},{m:7,t:"w"}];let a=1;i.forEach((t,n)=>{if(a*=t.m,e<a)return;const o=i[n===i.length-1?n:n+1].m;s.push({duration:e/a%o|0,type:t.t})});const n=s.slice(-t).reverse();for(let e=n.length-1;e>=0;--e)0===n[e].duration&&n.splice(e,1);return n}(e,2).map(e=>Object(c.i18n)(W[e.type],[e.duration])),s=document.createElement("span");return s.append(...Object(c.join)(t,!1)),s}var q=s(112),G=s(24),Q=s(113),K=s(114),$=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.apply(e,t||[])).next())}))};class Y{constructor(){this.pendingByRandomId={},this.pendingByMessageId={},this.pendingAfterMsgs={},this.pendingTopMsgs={},this.tempNum=0,this.tempFinalizeCallbacks={},this.sendSmthLazyLoadQueue=new i.a(1),this.needSingleMessages={},this.fetchSingleMessagesPromise=null,this.maxSeenId=0,this.migratedFromTo={},this.migratedToFrom={},this.newMessagesHandleTimeout=0,this.newMessagesToHandle={},this.newDialogsToHandle={},this.newUpdatesAfterReloadToHandle={},this.notificationsHandlePromise=0,this.notificationsToHandle={},this.reloadConversationsPeers=new Set,this.log=Object(g.b)("MESSAGES",g.a.Error|g.a.Debug|g.a.Log|g.a.Warn),this.groupedTempId=0,this.typings={},this.handleNewMessages=()=>{clearTimeout(this.newMessagesHandleTimeout),this.newMessagesHandleTimeout=0,_.default.dispatchEvent("history_multiappend",this.newMessagesToHandle),this.newMessagesToHandle={}},this.handleNewDialogs=()=>{let e=0;const t=this.newDialogsToHandle;for(const s in t){const i=t[s];i?(this.dialogsStorage.pushDialog(i),k.a.isChannel(+s)||(e=Math.max(e,i.top_message||0))):(this.reloadConversation(+s),delete t[s])}0!==e&&this.incrementMaxSeenId(e),_.default.dispatchEvent("dialogs_multiupdate",t),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([j.a.getNotifyPeerTypeSettings(),j.a.getNotifySettings(k.a.getInputNotifyPeerById(t,!0))]).then(([e,i])=>{const a=s.topMessage;!j.a.isPeerLocalMuted(t,!0)&&a.pFlags.unread&&a.pFlags.unread&&this.notifyAboutMessage(a,{fwdCount:s.fwdCount,peerTypeNotifySettings:i})})}this.notificationsToHandle={}},this.onUpdateMessageId=e=>{const t=e.random_id,s=this.pendingByRandomId[t];if(s){const{peerId:i,tempId:a,threadId:n,storage:o}=s,r=this.generateMessageId(e.id);this.getMessageFromStorage(o,r).deleted?this.pendingByMessageId[r]=t:([this.getHistoryStorage(i),n?this.getHistoryStorage(i,n):void 0].filter(Boolean).forEach(e=>{e.history.delete(a)}),this.finalizePendingMessageCallbacks(o,a,r))}},this.onUpdateNewMessage=e=>{var t;const s=e.message,i=this.getMessagePeer(s),a=this.getMessagesStorage(i),n=this.getDialogOnly(i),o="updateNewDiscussionMessage"===e._;this.saveMessages([s],{storage:{}});const r=this.getThreadKey(s),d=r?+r.split("_")[1]:void 0;if(d&&!o&&this.threadsStorage[i]&&this.threadsStorage[i][d]){const e={_:"updateNewDiscussionMessage",message:s};this.onUpdateNewMessage(e)}if(!n&&!o){let s=!0;if(i<0&&(s=w.a.isInChat(-i)),s){const s=null!==(t=this.newUpdatesAfterReloadToHandle[i])&&void 0!==t?t:this.newUpdatesAfterReloadToHandle[i]=new Set;if(s.has(e))return void this.log.error("here we go again",i);this.scheduleHandleNewDialogs(i),s.add(e)}return}this.saveMessages([s],{storage:a});const l=this.checkPendingMessage(s),h=this.getHistoryStorage(i,o?d:void 0);if(o||this.updateMessageRepliesIfNeeded(s),h.history.findSlice(s.mid))return!1;const c=h.history.first;if(c.isEnd(y.a.Bottom)){let e=0;for(const t=c.length;e<t&&!(s.mid>c[e]);++e);c.splice(e,0,s.mid)}else h.history.unshift(s.mid);null!==h.count&&h.count++,this.mergeReplyKeyboard(h,s)&&_.default.dispatchEvent("history_reply_markup",{peerId:i});const g=s.fromId;if(g>0&&!s.pFlags.out&&s.from_id){F.a.forceUserOnline(g,s.date);const e={_:"sendMessageCancelAction"};let t;t=i>0?{_:"updateUserTyping",action:e,user_id:g}:k.a.isChannel(i)?{_:"updateChannelUserTyping",action:e,channel_id:-i,from_id:k.a.getOutputPeer(g),top_msg_id:d?this.getServerMessageId(d):void 0}:{_:"updateChatUserTyping",action:e,chat_id:-i,from_id:k.a.getOutputPeer(g)},S.a.processLocalUpdate(t)}if(l||this.handleNewMessage(i,s.mid),o)return;const p=!s.pFlags.out&&s.pFlags.unread;if(n&&(this.setDialogTopMessage(s,n),p&&n.unread_count++),p){const e=i;let t=this.notificationsToHandle[e];void 0===t&&(t=this.notificationsToHandle[e]={fwdCount:0,fromId:0}),t.fromId!==g&&(t.fromId=g,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=k.a.getPeerId(e.peer.peer),s=this.getDialogOnly(t);s?(e.pFlags.unread?s.pFlags.unread_mark=!0:delete s.pFlags.unread_mark,_.default.dispatchEvent("dialogs_multiupdate",{[t]:s}),this.dialogsStorage.setDialogToState(s)):this.scheduleHandleNewDialogs(t)},this.onUpdateEditMessage=e=>{const t=e.message,s=this.getMessagePeer(t),i=this.generateMessageId(t.id),a=this.getMessagesStorage(s);if(void 0===a[i])return;const n=this.getMessageFromStorage(a,i);this.saveMessages([t],{storage:a});const o=this.getMessageFromStorage(a,i);this.handleEditedMessage(n,o);const r=this.getDialogOnly(s),d=r&&r.top_message===i;if(t.clear_history)d&&_.default.dispatchEvent("dialog_flush",{peerId:s});else if(_.default.dispatchEvent("message_edit",{storage:a,peerId:s,mid:i}),d||t.grouped_id){const e={};e[s]=r,_.default.dispatchEvent("dialogs_multiupdate",e),this.dialogsStorage.setDialogToState(r)}},this.onUpdateReadHistory=e=>{const t=e.channel_id,s=this.generateMessageId(e.max_id||e.read_max_id),i=this.generateMessageId(e.top_msg_id),a=t?-t:k.a.getPeerId(e.peer),n="updateReadHistoryOutbox"===e._||"updateReadChannelOutbox"===e._||"updateReadChannelDiscussionOutbox"===e._||void 0,o=this.getMessagesStorage(a),r=Object(d.e)(o,"desc"),l=this.getDialogOnly(a),h=e.still_unread_count;let c=0,g=!1;const p=this.getHistoryStorage(a,i);if(a>0&&n&&F.a.forceUserOnline(a),i){const e=this.threadsToReplies[a+"_"+i];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 a=o[t];if(a.pFlags.out===n){if(!a.pFlags.unread)break;if(i){const e=a.reply_to;if(!e||(e.reply_to_top_id||e.reply_to_msg_id)!==i)continue}a.pFlags.unread&&(delete a.pFlags.unread,g||(g=!0),a.pFlags.out||i||!l||void 0!==h||(c=--l.unread_count),j.a.cancel("msg"+t))}}if(n?p.readOutboxMaxId=s:p.readMaxId=s,!i&&l&&(n?l.read_outbox_max_id=s:l.read_inbox_max_id=s,n||(c<0||!this.getReadMaxIdIfUnread(a)?l.unread_count=0:c&&l.top_message>s&&(l.unread_count=c)),_.default.dispatchEvent("dialog_unread",{peerId:a}),this.dialogsStorage.setDialogToState(l)),g&&_.default.dispatchEvent("messages_read"),!i&&t){const e=a+"_";for(const t in this.threadsToReplies)if(0===t.indexOf(e)){const[e,s]=this.threadsToReplies[t].split("_").map(e=>+e);_.default.dispatchEvent("replies_updated",this.getMessageByPeer(e,s))}}},this.onUpdateReadMessagesContents=e=>{const t=e.channel_id,s=e.messages.map(e=>this.generateMessageId(e)),i=t?-t:this.getMessageById(s[0]).peerId;for(const e of s){const t=this.getMessageByPeer(i,e);t.deleted||(delete t.pFlags.media_unread,this.setDialogToStateIfMessageIsTop(t))}_.default.dispatchEvent("messages_media_read",{peerId:i,mids:s})},this.onUpdateChannelAvailableMessages=e=>{const t=e.channel_id,s=[],i=-t,a=this.getHistoryStorage(i).history.slice;a.length&&a.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)),i=t?-t:this.getMessageById(s[0]).peerId;if(!i)return;p.a.clearCache("messages.getSearchCounters",e=>k.a.getPeerId(e.peer)===i);const a=new Set;for(const e of s){const t=this.getMessageByPeer(i,e),s=this.getThreadKey(t);s&&this.threadsStorage[i]&&this.threadsStorage[i][+s.split("_")[1]]&&a.add(s)}const n=this.handleDeletedMessages(i,this.getMessagesStorage(i),s),o=Array.from(a).map(e=>{const t=e.split("_");return this.getHistoryStorage(+t[0],+t[1])});[this.getHistoryStorage(i)].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.dispatchEvent("history_delete",{peerId:i,msgs:n.msgs});const r=this.getDialogOnly(i);r&&(n.unread&&(r.unread_count-=n.unread,_.default.dispatchEvent("dialog_unread",{peerId:i})),n.msgs[r.top_message]&&this.reloadConversation(i))},this.onUpdateChannel=e=>{const t=e.channel_id,s=-t,i=w.a.getChat(t),a=w.a.isInChat(t);(!!i.username||!i.pFlags.left)!==(void 0!==this.historiesStorage[s])&&(delete this.historiesStorage[s],_.default.dispatchEvent("history_forbidden",s));const n=this.getDialogOnly(s);!!n!==a&&(a?this.reloadConversation(-t):n&&(this.dialogsStorage.dropDialog(s),_.default.dispatchEvent("dialog_drop",{peerId:s,dialog:n})))},this.onUpdateChannelReload=e=>{const t=e.channel_id,s=-t;this.dialogsStorage.dropDialog(s),delete this.historiesStorage[s],this.reloadConversation(-t).then(()=>{_.default.dispatchEvent("history_reload",s)})},this.onUpdateChannelMessageViews=e=>{const t=e.views,s=this.generateMessageId(e.id),i=this.getMessageByPeer(-e.channel_id,s);!i.deleted&&i.views&&i.views<t&&(i.views=t,_.default.dispatchEvent("message_views",{mid:s,views:t}))},this.onUpdateServiceNotification=e=>{const t=this.generateTempMessageId(777e3),s={_:"message",id:t,from_id:k.a.getOutputPeer(777e3),peer_id:k.a.getOutputPeer(777e3),pFlags:{unread:!0},date:(e.inbox_date||Object(o.h)(!0))+f.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:k.a.getPeerId(e.peer),i=e.messages.map(e=>this.generateMessageId(e)),a=this.getMessagesStorage(s),n=i.filter(e=>!a[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 i){a[e].pFlags.pinned=!0}else for(const e of i){delete a[e].pFlags.pinned}delete this.pinnedMessages[s],A.default.getState().then(e=>{delete e.hiddenPinnedMessages[s],_.default.dispatchEvent("peer_pinned_messages",{peerId:s,mids:i,pinned:n})})})},this.onUpdateNotifySettings=e=>{const{peer:t,notify_settings:s}=e;if("notifyPeer"===t._){const e=k.a.getPeerId(t.peer),i=this.getDialogOnly(e);i&&(i.notify_settings=s,_.default.dispatchEvent("dialog_notify_settings",i),this.dialogsStorage.setDialogToState(i))}},this.onUpdateNewScheduledMessage=e=>{const t=e.message,s=this.getMessagePeer(t),i=this.scheduledMessagesStorage[s];if(i){const e=this.generateMessageId(t.id),a=this.getMessageFromStorage(i,e);this.saveMessages([t],{storage:i,isScheduled:!0});const n=this.getMessageFromStorage(i,e);if(a.deleted){this.checkPendingMessage(t)||_.default.dispatchEvent("scheduled_new",{peerId:s,mid:t.mid})}else this.handleEditedMessage(a,n),_.default.dispatchEvent("message_edit",{storage:i,peerId:s,mid:t.mid})}},this.onUpdateDeleteScheduledMessages=e=>{const t=k.a.getPeerId(e.peer),s=this.scheduledMessagesStorage[t];if(s){const i=e.messages.map(e=>this.generateMessageId(e));this.handleDeletedMessages(t,s,i),_.default.dispatchEvent("scheduled_delete",{peerId:t,mids:i})}},this.clear(),_.default.addMultipleEventsListeners({updateMessageID:this.onUpdateMessageId,updateNewDiscussionMessage:this.onUpdateNewMessage,updateNewMessage:this.onUpdateNewMessage,updateNewChannelMessage:this.onUpdateNewMessage,updateDialogUnreadMark:this.onUpdateDialogUnreadMark,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.addEventListener("notify_peer_type_settings",({key:e,settings:t})=>{this.getConversationsAll().then(t=>{let s;s="notifyUsers"===e?e=>e.peerId>0:"notifyBroadcasts"===e?e=>w.a.isBroadcast(-e.peerId):e=>k.a.isAnyGroup(e.peerId),t.filter(s).forEach(e=>{_.default.dispatchEvent("dialog_notify_settings",e)})})}),_.default.addEventListener("webpage_updated",e=>{const t=e;t.msgs.forEach(e=>{const s=this.getMessageById(e);if(!s)return;s.media={_:"messageMediaWebPage",webpage:O.a.getWebPage(t.id)};const i=this.getMessagePeer(s),a=this.getMessagesStorage(i);_.default.dispatchEvent("message_edit",{storage:a,peerId:i,mid:e})})}),_.default.addEventListener("draft_updated",e=>{const{peerId:t,threadId:s,draft:i}=e;if(s)return;const a=this.getDialogOnly(t);a&&!s?(a.draft=i,this.dialogsStorage.generateIndexForDialog(a),this.dialogsStorage.pushDialog(a),_.default.dispatchEvent("dialog_draft",{peerId:t,draft:i,index:a.index})):this.reloadConversation(t)}),A.default.getState().then(e=>{e.maxSeenMsgId&&(this.maxSeenId=e.maxSeenMsgId)})}clear(){this.middleware?this.middleware.clean():this.middleware=Object(Q.a)(),this.messagesStorageByPeerId={},this.groupedMessagesStorage={},this.scheduledMessagesStorage={},this.historiesStorage={},this.threadsStorage={},this.searchesStorage={},this.pinnedMessages={},this.threadsServiceMessagesIdsStorage={},this.threadsToReplies={},this.dialogsStorage&&this.dialogsStorage.clear(),this.filtersStorage&&this.filtersStorage.clear()}construct(){this.filtersStorage=new P(this,k.a,F.a,j.a,A.default,S.a,_.default),this.dialogsStorage=new I(this,w.a,k.a,F.a,T.a,j.a,A.default,S.a,f.a)}getInputEntities(e){const 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 i,a;const o=null!==(i=this.tempFinalizeCallbacks[e])&&void 0!==i?i:this.tempFinalizeCallbacks[e]={},r=null!==(a=o[t])&&void 0!==a?a:o[t]={deferred:Object(n.a)()};return r.callback=s,r.deferred}editMessage(e,t,s={}){const{mid:i,peerId:a}=e;if(e.pFlags.is_outgoing)return this.invokeAfterMessageIsSent(i,"edit",e=>this.editMessage(e,t,s));let n=s.entities||[];t&&(t=m.a.parseMarkdown(t,n));const o=s.scheduleDate||(e.pFlags.is_scheduled?e.date:void 0);return p.a.invokeApi("messages.editMessage",{peer:k.a.getInputPeerById(a),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=>{S.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);const i=_.default.config.message_length_max;if(t.length>i){const a=Object(h.g)(t,i);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=k.a.getPeerMigratedTo(e)||e;let a=s.entities||[];s.viaBotId||(t=m.a.parseMarkdown(t,a));let n=this.getInputEntities(a);n.length||(n=void 0);const o=this.generateOutgoingMessage(e,s);o.entities=a,o.message=t;const r=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0,d=k.a.isChannel(e);s.webPage&&(o.media={_:"messageMediaWebPage",webpage:s.webPage});const l=e=>{e?o.error=!0:delete o.error,_.default.dispatchEvent("messages_pending")};o.send=()=>{l(!1);const i={};let a;this.pendingAfterMsgs[e]&&(i.afterMessageId=this.pendingAfterMsgs[e].messageId),a=s.viaBotId?p.a.invokeApiAfter("messages.sendInlineBotResult",{peer:k.a.getInputPeerById(e),random_id:o.random_id,reply_to_msg_id:r||void 0,query_id:s.queryId,id:s.resultId,clear_draft:s.clearDraft},i):p.a.invokeApiAfter("messages.sendMessage",{no_webpage:s.noWebPage,peer:k.a.getInputPeerById(e),message:t,random_id:o.random_id,reply_to_msg_id:r||void 0,entities:n,clear_draft:s.clearDraft,schedule_date:s.scheduleDate||void 0,silent:s.silent},i),a.then(e=>{"updateShortSentMessage"===e._?(o.date=e.date,o.id=e.id,o.media=e.media,o.entities=e.entities,this.wrapMessageEntities(o),e.pFlags.out&&(o.pFlags.out=!0),e={_:"updates",users:[],chats:[],seq:0,updates:[{_:"updateMessageID",random_id:o.random_id,id:e.id},{_:s.scheduleDate?"updateNewScheduledMessage":d?"updateNewChannelMessage":"updateNewMessage",message:o,pts:e.pts,pts_count:e.pts_count}]}):e.updates&&e.updates.forEach(e=>{"updateDraftMessage"===e._&&(e.local=!0)}),S.a.processUpdateMessage(e)},()=>{l(!0)}).finally(()=>{this.pendingAfterMsgs[e]===i&&delete this.pendingAfterMsgs[e]}),this.pendingAfterMsgs[e]=i},this.beforeMessageSending(o,{isScheduled:!!s.scheduleDate||void 0,threadId:s.threadId,clearDraft:s.clearDraft})}sendFile(e,t,s={}){e=k.a.getPeerMigratedTo(e)||e;const i=this.generateOutgoingMessage(e,s),o=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0;let d,l;const h="mime_type"in t?t.mime_type:t.type,c=t instanceof File?t.name:"",g=!(t instanceof File||t instanceof Blob);let u=s.caption||"";this.log("sendFile",t,h);const f=s.entities||[];u&&(u=m.a.parseMarkdown(u,f));const v=[],M=["image/jpeg","image/png","image/bmp"].indexOf(h)>=0;let y,I,b;if(g)d="document",l="";else if(0===h.indexOf("audio/")||["video/ogg"].indexOf(h)>=0){d="audio",l="audio."+("ogg"===h.split("/")[1]?"ogg":"mp3"),b="sendMessageUploadAudioAction",s.isVoiceMessage&&(d="voice",i.pFlags.media_unread=!0);let e={_:"documentAttributeAudio",pFlags:{voice:s.isVoiceMessage},waveform:s.waveform,duration:s.duration||0};v.push(e)}else if(s.isMedia)if(M){d="photo",l="photo."+h.split("/")[1],b="sendMessageUploadPhotoAction";const e={_:"photoSize",w:s.width,h:s.height,type:"full",location:null,size:t.size};y={_:"photo",id:""+i.id,sizes:[e],w:s.width,h:s.height};const a=D.a.getCacheContext(y,e.type);a.downloaded=t.size,a.url=s.objectURL||"",y=C.a.savePhoto(y)}else if(0===h.indexOf("video/")){d="video",l="video.mp4",b="sendMessageUploadVideoAction";let e={_:"documentAttributeVideo",pFlags:{round_message:s.isRoundMessage},duration:s.duration,w:s.width,h:s.height};v.push(e)}else d="document",l="document."+h.split("/")[1],b="sendMessageUploadDocumentAction";else d="document",l="document."+h.split("/")[1],b="sendMessageUploadDocumentAction";if(v.push({_:"documentAttributeFilename",file_name:c||l}),-1!==["document","video","audio","voice"].indexOf(d)&&!g){const e=[];I={_:"document",id:""+i.id,duration:s.duration,attributes:v,w:s.width,h:s.height,thumbs:e,mime_type:h,size:t.size};const a=D.a.getCacheContext(I);let n;if(a.downloaded=t.size,a.url=s.objectURL||"",M)v.push({_:"documentAttributeImageSize",w:s.width,h:s.height}),n={_:"photoSize",w:s.width,h:s.height,type:"full",size:t.size};else if("video"===d&&s.thumbURL){n={_:"photoSize",w:s.width,h:s.height,type:"full",size:s.thumbBlob.size};const e=D.a.getCacheContext(I,n.type);e.downloaded=n.size,e.url=s.thumbURL}n&&e.push(n),I=E.a.saveDoc(I)}this.log("sendFile",d,l,t.type,s);const P=g?void 0:new a.a({attachMethod:"prepend",tryAgainOnFail:!1,isUpload:!0}),w=Object(n.a)();P&&(P.attachPromise(w),w.cancel=()=>{const e=new Error("Download canceled");e.name="AbortError",w.reject(e)},w.catch(t=>{"AbortError"!==t.name||F||(this.log("cancelling upload",x),w.reject(t),this.cancelPendingMessage(i.random_id),this.setTyping(e,{_:"sendMessageCancelAction"}),(null==O?void 0:O.cancel)&&O.cancel())}));const x=g?void 0:{_:y?"messageMediaPhoto":"messageMediaDocument",pFlags:{},preloader:P,photo:y,document:I,promise:w};i.entities=f,i.message=u,i.media=g?{_:"messageMediaDocument",pFlags:{},document:t}:x;const A=e=>{e?i.error=!0:delete i.error,_.default.dispatchEvent("messages_pending")};let F=!1,O=null;return i.send=()=>{if(g){const{id:e,access_hash:s,file_reference:i}=t,a={_:"inputMediaDocument",id:{_:"inputDocument",id:e,access_hash:s,file_reference:i}};w.resolve(a)}else if(t instanceof File||t instanceof Blob){const a=()=>{let a;return F&&!i.error||(F=!1,O=D.a.upload(t),w.notifyAll({done:0,total:t.size})),"video"===d&&s.objectURL&&(a=new Promise((e,t)=>{(s.thumbBlob?Promise.resolve(s.thumbBlob):Object(r.a)(s.objectURL)).then(s=>{s?D.a.upload(s).then(e,t):e(null)},t)})),O&&O.then(e=>$(this,void 0,void 0,(function*(){let t;switch(delete i.media.preloader,e.name=l,F=!0,d){case"photo":t={_:"inputMediaUploadedPhoto",file:e};break;default:t={_:"inputMediaUploadedDocument",file:e,mime_type:h,attributes:v}}if(a)try{const e=yield a;t.thumb=e}catch(e){this.log.error("sendFile thumb upload error:",e)}w.resolve(t)})),()=>{A(!0)}),O.addNotifyListener(t=>{const s=Math.max(1,Math.floor(100*t.done/t.total));b&&this.setTyping(e,{_:b,progress:0|s}),w.notifyAll(t)}),w};s.isGroupedItem?a():this.sendSmthLazyLoadQueue.push({load:a})}return w},this.beforeMessageSending(i,{isGroupedItem:s.isGroupedItem,isScheduled:!!s.scheduleDate||void 0,threadId:s.threadId,clearDraft:s.clearDraft}),s.isGroupedItem||w.then(t=>(this.setTyping(e,{_:"sendMessageCancelAction"}),p.a.invokeApi("messages.sendMedia",{background:s.background,peer:k.a.getInputPeerById(e),media:t,message:u,random_id:i.random_id,reply_to_msg_id:o,schedule_date:s.scheduleDate,silent:s.silent,entities:f,clear_draft:s.clearDraft}).then(e=>{S.a.processUpdateMessage(e)},e=>{if("photo"===d&&400===e.code&&("PHOTO_INVALID_DIMENSIONS"===e.type||"PHOTO_SAVE_FILE_INVALID"===e.type))return e.handled=!0,d="document",void i.send();A(!0)}))),{message:i,promise:w}}sendAlbum(e,t,s={}){return $(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=k.a.getPeerMigratedTo(e)||e;const i=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0;let a=s.caption||"",n=s.entities||[];a&&(a=m.a.parseMarkdown(a,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:i,threadId:s.threadId,groupId:o},d);return 0===r&&(l.caption=a,l.entities=n),this.sendFile(e,t,l).message});s.threadId?T.a.syncDraft(e,s.threadId):T.a.saveDraft(e,s.threadId,null,{notify:!0});const d=(e,t)=>{t?e.error=!0:delete e.error,_.default.dispatchEvent("messages_pending")},l=k.a.getInputPeerById(e),h=t=>{this.setTyping(e,{_:"sendMessageCancelAction"}),this.sendSmthLazyLoadQueue.push({load:()=>p.a.invokeApi("messages.sendMultiMedia",{peer:l,multi_media:t,reply_to_msg_id:i,schedule_date:s.scheduleDate,silent:s.silent,clear_draft:s.clearDraft}).then(e=>{S.a.processUpdateMessage(e)},e=>{r.forEach(e=>d(e,!0))})})},c=r.map((e,t)=>e.send().then(e=>p.a.invokeApi("messages.uploadMedia",{peer:l,media:e})).then(t=>{let s;if("messageMediaPhoto"===t._){const e=C.a.savePhoto(t.photo);s=C.a.getInput(e)}else if("messageMediaDocument"===t._){const e=E.a.saveDoc(t.document);s=E.a.getMediaInput(e)}const i={_:"inputSingleMedia",media:s,random_id:e.random_id,message:a,entities:n};return a&&(a="",n=[]),i}).catch(t=>{if("AbortError"===t.name)return null;throw this.log.error("sendAlbum upload item error:",t,e),d(e,!0),t}));Promise.all(c).then(e=>{h(e.filter(Boolean))})}))}sendOther(e,t,s={}){e=k.a.getPeerMigratedTo(e)||e;const i=this.generateOutgoingMessage(e,s),a=s.replyToMsgId?this.getServerMessageId(s.replyToMsgId):void 0;let n;switch(t._){case"inputMediaPoll":{t.poll.id=i.id,x.a.savePoll(t.poll,{_:"pollResults",flags:4,total_voters:0,pFlags:{}});const{poll:e,results:s}=x.a.getPoll(""+i.id);n={_:"messageMediaPoll",poll:e,results:s};break}}i.media=n;i.send=()=>{const n={};let o;this.pendingAfterMsgs[e]&&(n.afterMessageId=this.pendingAfterMsgs[e].messageId),o=s.viaBotId?p.a.invokeApiAfter("messages.sendInlineBotResult",{peer:k.a.getInputPeerById(e),random_id:i.random_id,reply_to_msg_id:a||void 0,query_id:s.queryId,id:s.resultId,clear_draft:s.clearDraft},n):p.a.invokeApiAfter("messages.sendMedia",{peer:k.a.getInputPeerById(e),media:t,random_id:i.random_id,reply_to_msg_id:a||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)}),S.a.processUpdateMessage(e)},e=>{_.default.dispatchEvent("messages_pending")}).finally(()=>{this.pendingAfterMsgs[e]===n&&delete this.pendingAfterMsgs[e]}),this.pendingAfterMsgs[e]=n},this.beforeMessageSending(i,{isScheduled:!!s.scheduleDate||void 0,threadId:s.threadId,clearDraft:s.clearDraft})}beforeMessageSending(e,t={}){const s=e.id,i=this.getMessagePeer(e),a=t.isScheduled?this.getScheduledMessagesStorage(i):this.getMessagesStorage(i);if(t.isScheduled)this.saveMessages([e],{storage:a,isScheduled:!0,isOutgoing:!0}),setTimeout(()=>{_.default.dispatchEvent("scheduled_new",{peerId:i,mid:s})},0);else{const n=[this.getHistoryStorage(i),t.threadId?this.getHistoryStorage(i,t.threadId):void 0];for(const e of n)e&&e.history.unshift(s);this.saveMessages([e],{storage:a,isOutgoing:!0}),setTimeout(()=>{this.setDialogTopMessage(e),_.default.dispatchEvent("history_append",{storage:a,peerId:i,mid:s})},0)}!t.isGroupedItem&&t.clearDraft&&(t.threadId?T.a.syncDraft(i,t.threadId):T.a.saveDraft(i,t.threadId,null,{notify:!0})),this.pendingByRandomId[e.random_id]={peerId:i,tempId:s,threadId:t.threadId,storage:a},!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:k.a.getOutputPeer(e),pFlags:this.generateFlags(e),date:t.scheduleDate||Object(o.h)(!0)+f.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:k.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(k.a.isBroadcast(e)){const s=L.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&&(k.a.isBroadcast(e)||(null===(s=null===(t=k.a.getPeer(e).admin_rights)||void 0===t?void 0:t.pFlags)||void 0===s?void 0:s.anonymous))?void 0:k.a.getOutputPeer(F.a.getSelf().id)}generateFlags(e){const t={};return e!==F.a.getSelf().id&&(t.out=!0,k.a.isChannel(e)||F.a.isBot(e)||(t.unread=!0)),k.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 i={_:"messageFwdHeader",flags:0,date:t.date};return t.fwd_from?(i.from_id=t.fwd_from.from_id,i.from_name=t.fwd_from.from_name,i.post_author=t.fwd_from.post_author):(i.from_id=k.a.getOutputPeer(t.fromId),i.post_author=t.post_author),k.a.isBroadcast(t.peerId)&&(t.post_author&&(i.post_author=t.post_author),i.channel_post=t.id),e===s&&(i.saved_from_msg_id=t.id,i.saved_from_peer=k.a.getOutputPeer(t.peerId)),i}generateFakeAvatarMessage(e,t){const s=Number.MAX_SAFE_INTEGER,i={_:"messageService",action:{_:"messageActionChannelEditPhoto",photo:t},mid:s,peerId:e,date:t.date,fromId:e};return this.getMessagesStorage(e)[s]=i,i}setDialogTopMessage(e,t=this.getDialogOnly(e.peerId)){if(t){t.top_message=e.mid;this.getHistoryStorage(e.peerId).maxId=e.mid,this.dialogsStorage.generateIndexForDialog(t,!1,e),this.scheduleHandleNewDialogs(e.peerId,t)}}cancelPendingMessage(e){const t=this.pendingByRandomId[e];if(t){const{peerId:s,tempId:i,storage:a}=t,n=this.getHistoryStorage(s);return S.a.processLocalUpdate({_:"updateDeleteMessages",messages:[i],pts:void 0,pts_count:void 0}),n.history.delete(i),delete this.pendingByRandomId[e],delete a[i],!0}return!1}refreshConversations(){return $(this,void 0,void 0,(function*(){const e=[];for(let t=0;t<2;++t){let s=0;for(;;){const{dialogs:i,isEnd:a}=yield this.getTopMessages(200,t,s);if(i.length){e.push(...i);const t=i[i.length-1],a=k.a.getPeerId(t.peer),n=this.generateMessageId(t.top_message);if(s=this.getMessageByPeer(a,n).date,!s){console.error("refreshConversations: got no offsetDate",t);break}}if(a)break}}let t={};return e.forEach(e=>{t[e.peerId]=e}),_.default.dispatchEvent("dialogs_multiupdate",t),e}))}getConversationsAll(e="",t=0){return $(this,void 0,void 0,(function*(){const s=[];for(;t<2;++t){let i=0;for(;;){const{dialogs:a}=yield J.getConversations(e,i,200,t);if(!a.length)break;s.push(...a),i=a[a.length-1].index||0}}return s}))}getConversations(e="",t,s=20,i=0){return this.dialogsStorage.getDialogs(e,t,s,i)}getReadMaxIdIfUnread(e,t){var s;const i=this.getHistoryStorage(e,t);if(t){const t=this.getHistoryStorage(e),a=Math.max(null!==(s=t.readMaxId)&&void 0!==s?s:0,i.readMaxId);return!this.getMessageByPeer(e,i.maxId).pFlags.out&&a<i.maxId?a:0}{const t=this.getMessageByPeer(e,i.maxId),s=e>0?Math.max(i.readMaxId,i.readOutboxMaxId):i.readMaxId;return!t.pFlags.out&&s<i.maxId?s:0}}getTopMessages(e,t,s){let i=0;void 0===s&&(s=this.dialogsStorage.getOffsetDate(t)),s&&(i=65536*s,s+=f.a.serverTimeOffset);const a=this.middleware.get();return p.a.invokeApiSingle("messages.getDialogs",{folder_id:t,offset_date:s,offset_id:0,offset_peer:k.a.getInputPeerById(0),limit:e,hash:0},{noErrorBox:!0}).then(e=>{if(!a()||"messages.dialogsNotModified"===e._)return null;R.b&&this.log("messages.getDialogs result:",e.dialogs,Object.assign({},e.dialogs[0])),s||this.dialogsStorage.resetPinnedOrder(t),s||G.default.setAuthorized(!0),F.a.saveApiUsers(e.users),w.a.saveApiChats(e.chats),this.saveMessages(e.messages);let n=!!s,o=!1;const r={};Object(M.d)(e.dialogs,e=>{var s;this.dialogsStorage.saveDialog(e,null!==(s=e.folder_id)&&void 0!==s?s:t,!0),n||k.a.isChannel(e.peerId||k.a.getPeerId(e.peer))||(this.incrementMaxSeenId(e.top_message),n=!0),void 0!==e.peerId&&(i&&e.index>i&&(this.scheduleHandleNewDialogs(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)))}),Object.keys(r).length&&this.reloadConversation(Object.keys(r).map(e=>+e)).then(()=>{_.default.dispatchEvent("dialogs_multiupdate",r);for(let e in r)_.default.dispatchEvent("dialog_unread",{peerId:+e})});const d=e.count,l=this.dialogsStorage.getFolder(t,!1);let h=0;for(let e=0,t=l.length;e<t;++e)this.getServerMessageId(l[e].top_message)&&++h;const c=!d||h>=d||!e.dialogs.length;return c&&this.dialogsStorage.setDialogsLoaded(t,!0),o?this.scheduleHandleNewDialogs():_.default.dispatchEvent("dialogs_multiupdate",{}),{isEnd:c,count:d,dialogs:e.dialogs}})}forwardMessages(e,t,s,i={}){e=k.a.getPeerMigratedTo(e)||e,s=s.slice().sort((e,t)=>e-t);const a={},n=s.map(s=>{var n,o;const r=this.getMessageByPeer(t,s),d=this.generateOutgoingMessage(e,i);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=a[r.grouped_id])&&void 0!==o?o:a[r.grouped_id]={tempId:""+ ++this.groupedTempId,messages:[]}).messages.push(d)}return d});for(const e in a){const t=a[e];t.messages.length>1&&t.messages.forEach(e=>{e.grouped_id=t.tempId})}n.forEach(e=>{this.beforeMessageSending(e,{isScheduled:!!i.scheduleDate||void 0})});const o={};this.pendingAfterMsgs[e]&&(o.afterMessageId=this.pendingAfterMsgs[e].messageId);const r=p.a.invokeApiAfter("messages.forwardMessages",{from_peer:k.a.getInputPeerById(t),id:s.map(e=>this.getServerMessageId(e)),random_id:n.map(e=>e.random_id),to_peer:k.a.getInputPeerById(e),with_my_score:i.withMyScore,silent:i.silent,schedule_date:i.scheduleDate},o).then(e=>{this.log("forwardMessages updates:",e),S.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(k.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&&k.a.getPeerId(e.peer_id)||0}getDialogByPeerId(e){return this.dialogsStorage.getDialog(e)}getDialogOnly(e){return this.dialogsStorage.getDialogOnly(e)}reloadConversation(e){return void 0!==e&&[].concat(e).forEach(e=>{this.reloadConversationsPeers.has(e)||this.reloadConversationsPeers.add(e)}),this.reloadConversationsPromise?this.reloadConversationsPromise:this.reloadConversationsPromise=new Promise((e,t)=>{setTimeout(()=>{const s=Array.from(this.reloadConversationsPeers).map(e=>k.a.getInputDialogPeerById(e));this.reloadConversationsPeers.clear(),p.a.invokeApi("messages.getPeerDialogs",{peers:s}).then(t=>{this.dialogsStorage.applyDialogs(t),e()},t).finally(()=>{this.reloadConversationsPromise=null,this.reloadConversationsPeers.size&&this.reloadConversation()})},0)})}doFlushHistory(e,t,s){return p.a.invokeApiSingle("messages.deleteHistory",{just_clear:t,revoke:s,peer:e,max_id:0}).then(i=>(S.a.processUpdateMessage({_:"updateShort",update:{_:"updatePts",pts:i.pts,pts_count:i.pts_count}}),!i.offset||this.doFlushHistory(e,t,s)))}flushHistory(e,t,s){return $(this,void 0,void 0,(function*(){if(k.a.isChannel(e)){const t=this.getHistory(e,0,1),s=t instanceof Promise?yield t:t,i=-e,a=s.history[0]||0;return p.a.invokeApiSingle("channels.deleteHistory",{channel:w.a.getChannelInput(i),max_id:this.getServerMessageId(a)}).then(()=>(S.a.processLocalUpdate({_:"updateChannelAvailableMessages",channel_id:i,available_min_id:a}),!0))}return this.doFlushHistory(k.a.getInputPeerById(e),t,s).then(()=>{delete this.historiesStorage[e],delete this.messagesStorageByPeerId[e],delete this.scheduledMessagesStorage[e],delete this.threadsStorage[e],delete this.searchesStorage[e],delete this.pinnedMessages[e],delete this.pendingAfterMsgs[e],delete this.pendingTopMsgs[e],delete this.needSingleMessages[e],t?_.default.dispatchEvent("dialog_flush",{peerId:e}):(delete this.notificationsToHandle[e],delete this.typings[e],this.reloadConversationsPeers.delete(e),this.dialogsStorage.dropDialog(e),_.default.dispatchEvent("dialog_drop",{peerId:e}))})}))}hidePinnedMessages(e){return Promise.all([A.default.getState(),this.getPinnedMessage(e)]).then(([t,s])=>{t.hiddenPinnedMessages[e]=s.maxId,_.default.dispatchEvent("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,i,a){return p.a.invokeApi("messages.updatePinnedMessage",{peer:k.a.getInputPeerById(e),unpin:s,silent:i,pm_oneside:a,id:this.getServerMessageId(t)}).then(e=>{S.a.processUpdateMessage(e)})}unpinAllMessages(e){return p.a.invokeApiSingle("messages.unpinAllMessages",{peer:k.a.getInputPeerById(e)}).then(t=>{if(S.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.dispatchEvent("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,i,a,n=0;for(const e in t){const o=t[e];if(o.message){if(++n>1)break;s=o.message,i=o.totalEntities,a=o.entities}}return n>1&&(s=void 0,i=void 0,a=void 0),{message:s,entities:a,totalEntities:i}}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 i=this.groupedMessagesStorage[e.grouped_id];for(const e in i){const a=i[e];t(a)&&s.push(a)}}else t(e)&&s.push(e);return s}generateTempMessageId(e){const t=this.getDialogOnly(e);return this.generateMessageId((null==t?void 0:t.top_message)||0,!0)}generateMessageId(e,t=!1){const s=Y.MESSAGE_ID_OFFSET,i=t?++this.tempNum:0;return e>=s?t?e+(i&Y.MESSAGE_ID_INCREMENT-1):e:s+(e*Y.MESSAGE_ID_INCREMENT+(i&Y.MESSAGE_ID_INCREMENT-1))}getServerMessageId(e){const t=Y.MESSAGE_ID_OFFSET;if(e<t)return e;const s=Y.MESSAGE_ID_INCREMENT-1,i=e&s;return i!==s&&(e-=i+1),(e-t)/Y.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 i=this.getMessagePeer(e),a=t.storage||this.getMessagesStorage(i),n="peerChannel"===e.peer_id._,o=n?-i:0,r=n&&w.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.getDialogOnly(i);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 h=!!i;h||(e.date-=f.a.serverTimeOffset);const c=F.a.getSelf().id;e.peerId=i,e.fromId=i===c?e.fwd_from?e.fwd_from.from_id?k.a.getPeerId(e.fwd_from.from_id):0:c:e.pFlags.post||!e.from_id?i:k.a.getPeerId(e.from_id);const g=e.fwd_from;if(g){g.saved_from_msg_id&&(g.saved_from_msg_id=this.generateMessageId(g.saved_from_msg_id)),g.channel_post&&(g.channel_post=this.generateMessageId(g.channel_post));const t=g.saved_from_peer||g.from_id,s=g.saved_from_msg_id||g.channel_post;if(t&&s){const i=k.a.getPeerId(t),a=this.generateMessageId(s);e.savedFrom=i+"_"+a}e.fwdFromId=k.a.getPeerId(g.from_id),h||(g.date-=f.a.serverTimeOffset)}e.via_bot_id>0&&(e.viaBotId=e.via_bot_id);const p={type:"message",peerId:i,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=C.a.savePhoto(e.media.photo,p),e.media.photo||delete e.media;break;case"messageMediaPoll":e.media.poll=x.a.savePoll(e.media.poll,e.media.results);break;case"messageMediaDocument":e.media.ttl_seconds?e.media={_:"messageMediaUnsupportedWeb"}:e.media.document=E.a.saveDoc(e.media.document,p);break;case"messageMediaWebPage":e.media.webpage=O.a.saveWebPage(e.media.webpage,e.mid,p);break;case"messageMediaInvoice":e.media={_:"messageMediaUnsupportedWeb"}}if(e.action){const t=e.action;let s,a;const d=e.fromId===F.a.getSelf().id?"You":"";switch(t._){case"messageActionChatEditPhoto":t.photo=C.a.savePhoto(t.photo,p),t.photo.video_sizes?t._=r?"messageActionChannelEditVideo":"messageActionChatEditVideo":r&&(t._="messageActionChannelEditPhoto");break;case"messageActionGroupCall":{let s;void 0===t.duration?(s="started",i!==e.fromId&&(s+="_by"+d)):s="ended_by"+d,t.type=s;break}case"messageActionChatEditTitle":r&&(t._="messageActionChannelEditTitle");break;case"messageActionChatDeletePhoto":r&&(t._="messageActionChannelDeletePhoto");break;case"messageActionChatAddUser":1===t.users.length?(t.user_id=t.users[0],e.fromId===t.user_id&&(t._=n?"messageActionChatJoined"+d:"messageActionChatReturn"+d)):t.users.length>1&&(t._="messageActionChatAddUsers");break;case"messageActionChatDeleteUser":e.fromId===t.user_id&&(t._="messageActionChatLeave"+d);break;case"messageActionChannelMigrateFrom":s=-t.chat_id,a=-o;break;case"messageActionChatMigrateTo":s=-o,a=-t.channel_id;break;case"messageActionHistoryClear":e.clear_history=!0,delete e.pFlags.out,delete e.pFlags.unread;break;case"messageActionPhoneCall":t.type=(e.pFlags.out?"out_":"in_")+("phoneCallDiscardReasonMissed"===t.reason._||"phoneCallDiscardReasonBusy"===t.reason._?"missed":"ok")}s&&a&&!this.migratedFromTo[s]&&!this.migratedToFrom[a]&&this.migrateChecks(s,a)}e.message&&e.message.length&&!e.totalEntities&&this.wrapMessageEntities(e),a[d]=e})}wrapMessageEntities(e){const t=e.entities?e.entities.slice():[];e.message=m.a.fixEmoji(e.message,t);const s=m.a.parseEntities(e.message);e.totalEntities=m.a.mergeEntities(t,s)}wrapMessageForReply(e,t=e.message,s,i,a){const n=[],o=(e,t,s)=>{if(e&&(t=i?c.default.format(e,!0):Object(c.i18n)(e)),i)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 a=!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)){a=!1;break}}else a=!1}a&&o("AttachAlbum",void 0,t=this.getAlbumText(e.grouped_id).message)}else a=!1;if(!a){const s=e.media;switch(s._){case"messageMediaPhoto":o("AttachPhoto",void 0,e.message);break;case"messageMediaDice":o(void 0,i?s.emoticon:m.a.wrapEmojiText(s.emoticon));break;case"messageMediaVenue":{const e=i?s.title:m.a.wrapEmojiText(s.title);o("AttachLocation",void 0,e),n.push(Object(N.a)(e));break}case"messageMediaGeo":o("AttachLocation");break;case"messageMediaGeoLive":o("AttachLiveLocation");break;case"messageMediaPoll":o(void 0,i?"📊 "+(s.poll.question||"poll"):s.poll.rReply);break;case"messageMediaContact":o("AttachContact");break;case"messageMediaGame":{const e="🎮 ";o(void 0,i?e+s.game.title:m.a.wrapEmojiText(e+s.game.title));break}case"messageMediaDocument":let a=s.document;"video"===a.type?o("AttachVideo",void 0,e.message):"voice"===a.type?o("AttachAudio",void 0,e.message):"gif"===a.type?o("AttachGif",void 0,e.message):"round"===a.type?o("AttachRound",void 0,e.message):"sticker"===a.type?(o(void 0,((i?a.stickerEmojiRaw:a.stickerEmoji)||"")+"Sticker"),t=""):o(a.file_name,void 0,e.message)}}}if(e.action){const t=this.wrapMessageActionTextNew(e,i);t&&o(void 0,t)}if(t)if(t=Object(h.f)(t,100),i)n.push(t);else{let e=m.a.parseEntities(t.replace(/\n/g," "));if(a){a=a.trim(),e||(e=[]);let s,i=!1,n=new RegExp(Object(h.e)(a),"gi");for(;null!==(s=n.exec(t));)e.push({_:"messageEntityHighlight",length:a.length,offset:s.index}),i=!0;i&&e.sort((e,t)=>e.offset-t.offset)}const s=m.a.wrapRichText(t,{noLinebreaks:!0,entities:e,noLinks:!0,noTextFormat:!0});n.push(Object(N.a)(s))}if(i)return n.join("");{const e=document.createDocumentFragment();return e.append(...n),e}}getSenderToPeerText(e){let t,s="";return s=e.pFlags.out?"You":k.a.getPeerTitle(e.fromId,!1,!1),t=k.a.isAnyGroup(e.peerId)||e.pFlags.out&&e.peerId!==_.default.myId?k.a.getPeerTitle(e.peerId,!1,!1):"",t&&(s+=" ➝ "+t),s}wrapMessageActionTextNew(e,t){const s=t?void 0:document.createElement("span"),i=e.action;if(i.message)return t?m.a.wrapPlainText(e.message):(s.innerHTML=m.a.wrapRichText(i.message,{noLinebreaks:!0}),s);{let a,n,r=i._;const d=(e,t)=>t?k.a.getPeerTitle(e,t)+" ":new B.a({peerId:e}).element;switch(i._){case"messageActionPhoneCall":r+="."+i.type,n=[V(i.duration)];break;case"messageActionGroupCall":r+="."+i.type,n=[],r.endsWith("You")||n.push(d(e.fromId,t)),n.push(V(i.duration));break;case"messageActionInviteToGroupCall":{const s=[e.fromId,i.users[0]];let o="ActionGroupCall";const r=F.a.getSelf().id;s[0]===r&&(o+="You"),o+="Invited",s[1]===r&&(o+="You"),s.findAndSplice(e=>e===r),a=o,n=s.map(e=>d(e,t));break}case"messageActionGroupCallScheduled":{const t=new Date,s=new Date(1e3*i.schedule_date),r=(s.getTime()-t.getTime())/864e5,d=new Date(t);d.setDate(d.getDate()+1),a="ChatList.Service.VoiceChatScheduled";const l=F.a.getSelf().id;e.fromId===l&&(a+="You");let h,g=[];r<1&&s.getDate()===t.getDate()?h="TodayAtFormattedWithToday":r<2&&s.getDate()===d.getDate()?h="Time.TomorrowAt":(h="formatDateAtTime",g.push(new c.default.IntlDateElement({date:s,options:{day:"2-digit",month:"2-digit",year:"2-digit"}}).element)),g.push(Object(o.e)(s));n=[Object(c.i18n)(h,g)];break}case"messageActionChatCreate":{const s=F.a.getSelf().id;e.fromId===s?r+="You":n=[d(e.fromId,t)];break}case"messageActionPinMessage":case"messageActionContactSignUp":case"messageActionChatReturn":case"messageActionChatLeave":case"messageActionChatJoined":case"messageActionChatEditPhoto":case"messageActionChatDeletePhoto":case"messageActionChatEditVideo":case"messageActionChatJoinedByLink":case"messageActionChannelEditVideo":case"messageActionChannelDeletePhoto":n=[d(e.fromId,t)];break;case"messageActionChannelEditTitle":case"messageActionChatEditTitle":n=[],"messageActionChatEditTitle"===i._&&n.push(d(e.fromId,t)),n.push(t?i.title:Object(H.a)(m.a.wrapEmojiText(i.title)));break;case"messageActionChatDeleteUser":case"messageActionChatAddUsers":case"messageActionChatAddUser":{const s=i.users||[i.user_id];if(n=[d(e.fromId,t)],s.length>1)if(t)n.push(...s.map(e=>d(e,!0).trim()).join(", "));else{const e=document.createElement("span");e.append(...Object(c.join)(s.map(e=>d(e,!1)),!1)),n.push(e)}else n.push(d(s[0],t));break}case"messageActionBotAllowed":{const e=m.a.wrapRichText(i.domain,{entities:[{_:"messageEntityUrl",length:i.domain.length,offset:0}]});n=[Object(H.a)(e)];break}default:a=c.langPack[r]||`[${i._}]`}return a||(a=c.langPack[r],void 0===a&&(a="["+r+"]")),t?c.default.format(a,!0,n):Object(c._i18n)(s,a,n)}}editPeerFolders(e,t){p.a.invokeApi("folders.editPeerFolders",{folder_peers:e.map(e=>({_:"inputFolderPeer",peer:k.a.getInputPeerById(e),folder_id:t}))}).then(e=>{S.a.processUpdateMessage(e)})}toggleDialogPin(e,t){var s;if(t>1)return this.filtersStorage.toggleDialogPin(e,t);const i=this.getDialogOnly(e);if(!i)return Promise.reject();const a=!(null===(s=i.pFlags)||void 0===s?void 0:s.pinned)||void 0;if(a){const e=1===t?_.default.config.pinned_infolder_count_max:_.default.config.pinned_dialogs_count_max;if(this.dialogsStorage.getPinnedOrders(t).length>=e)return Promise.reject({type:"PINNED_DIALOGS_TOO_MUCH"})}return p.a.invokeApi("messages.toggleDialogPin",{peer:k.a.getInputDialogPeerById(e),pinned:a}).then(s=>{if(s){const s=a?{pinned:a}:{};S.a.saveUpdate({_:"updateDialogPinned",peer:k.a.getDialogPeer(e),folder_id:t,pFlags:s})}})}markDialogUnread(e,t){var s;const i=this.getDialogOnly(e);if(!i)return Promise.reject();const a=!t&&!(null===(s=i.pFlags)||void 0===s?void 0:s.unread_mark)||void 0;return p.a.invokeApi("messages.markDialogUnread",{peer:k.a.getInputDialogPeerById(e),unread:a}).then(t=>{if(t){const t=a?{unread:a}:{};this.onUpdateDialogUnreadMark({_:"updateDialogUnreadMark",peer:k.a.getDialogPeer(e),pFlags:t})}})}migrateChecks(e,t){if(!this.migratedFromTo[e]&&!this.migratedToFrom[t]&&w.a.hasChat(-t)){const s=w.a.getChat(-e);if(s&&s.migrated_to&&s.migrated_to.channel_id===-t){this.migratedFromTo[e]=t,this.migratedToFrom[t]=e,_.default.dispatchEvent("dialog_migrate",{migrateFrom:e,migrateTo:t});const s=this.dialogsStorage.dropDialog(e);s.length&&_.default.dispatchEvent("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))&&(this.getMessagePeer(e)===F.a.getSelf().id||!(e.date<Object(o.h)(!0)-_.default.config.edit_time_limit&&"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"===w.a.getChat(e.peerId)._||w.a.hasRights(e.peerId,"delete_messages"))&&!e.pFlags.is_outgoing}getReplyKeyboard(e){return this.getHistoryStorage(e).reply_markup}mergeReplyKeyboard(e,t){var s,i;let a=t.reply_markup;if(!a&&!(null===(s=t.pFlags)||void 0===s?void 0:s.out)&&!t.action)return!1;if("replyInlineMarkup"===(null==a?void 0:a._))return!1;const n=e.reply_markup;if(a)return!(n&&n.mid>=t.mid)&&(!a.pFlags.selective&&(e.maxOutId&&t.mid<e.maxOutId&&a.pFlags.single_use&&(a.pFlags.hidden=!0),a.mid=t.mid,"replyKeyboardHide"!==a._&&(a.fromId=k.a.getPeerId(t.from_id)),e.reply_markup=a,!0));if(t.pFlags.out)if(n){if(Object(K.a)(n),n.pFlags.single_use&&!n.pFlags.hidden&&(t.mid>n.mid||t.pFlags.is_outgoing)&&t.message)return n.pFlags.hidden=!0,!0}else(!e.maxOutId||t.mid>e.maxOutId)&&(e.maxOutId=t.mid);return Object(K.a)(t),!("messageActionChatDeleteUser"!==(null===(i=t.action)||void 0===i?void 0:i._)||!(n?t.action.user_id===n.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?p.a.invokeApiCacheable:p.a.invokeApi).bind(p.a)("messages.getSearchCounters",{peer:k.a.getInputPeerById(e),filters:t})}getSearch({peerId:e,query:t,inputFilter:s,maxId:i,limit:a,nextRate:n,backLimit:o,threadId:r,folderId:d,minDate:l,maxDate:h}){e||(e=0),t||(t=""),s||(s={_:"inputMessagesFilterEmpty"}),void 0===a&&(a=20),n||(n=0),o||(o=0),l=l?l/1e3|0:0,h=h?h/1e3|0:0;const c=[];o&&(a+=o);let g;if(e&&!o&&!i&&!t&&1!==a&&!r){g=this.getHistoryStorage(e);let t=!0;const i=g.history;if(void 0!==g&&i.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=i.length;e<s;e++){const s=t[i.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._))||m.a.matchUrl(s.message))&&(d=!0)}else n.avatar&&s.action&&["messageActionChannelEditPhoto","messageActionChatEditPhoto","messageActionChannelEditVideo","messageActionChatEditVideo"].includes(s.action._)&&(d=!0);if(d&&(c.push(s),c.length>=a))break}}}}if(c.length){if(!(c.length<a))return Promise.resolve({count:0,next_rate:0,offset_id_offset:0,history:c});i=c[c.length-1].mid,a-=c.length}else 0;const u=p.a.invokeApi.bind(p.a);let f;if(e&&!n&&void 0===d)f=u("messages.search",{peer:k.a.getInputPeerById(e),q:t||"",filter:s,min_date:l,max_date:h,limit:a,offset_id:this.getServerMessageId(i)||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,c=i&&this.getMessageByPeer(e,i);c&&c.date&&(r=c.id,o=this.getMessagePeer(c)),f=u("messages.searchGlobal",{q:t,filter:s,min_date:l,max_date:h,offset_rate:n,offset_peer:k.a.getInputPeerById(o),offset_id:r,limit:a,folder_id:d},{noErrorBox:!0})}return f.then(e=>{F.a.saveApiUsers(e.users),w.a.saveApiChats(e.chats),this.saveMessages(e.messages),R.b&&this.log("getSearch result:",s,e);const t=e.count||c.length+e.messages.length;return e.messages.forEach(e=>{const t=this.getMessagePeer(e);if(t<0){const e=w.a.getChat(-t);e.migrated_to&&this.migrateChecks(t,-e.migrated_to.channel_id)}c.push(e)}),{count:t,offset_id_offset:e.offset_id_offset||0,next_rate:e.next_rate,history:c}})}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))),i={_:"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([i],{isOutgoing:!0}),this.threadsServiceMessagesIdsStorage[t]=i.mid}getDiscussionMessage(e,t){return p.a.invokeApiSingle("messages.getDiscussionMessage",{peer:k.a.getInputPeerById(e),msg_id:this.getServerMessageId(t)}).then(s=>{var i;w.a.saveApiChats(s.chats),F.a.saveApiUsers(s.users),this.saveMessages(s.messages);const a=this.filterMessages(s.messages[0],e=>!!e.replies)[0],n=a.peerId+"_"+a.mid;this.generateThreadServiceStartMessage(a);const o=this.getHistoryStorage(a.peerId,a.mid);return s.max_id=o.maxId=this.generateMessageId(s.max_id)||0,s.read_inbox_max_id=o.readMaxId=this.generateMessageId(null!==(i=s.read_inbox_max_id)&&void 0!==i?i:a.mid),s.read_outbox_max_id=o.readOutboxMaxId=this.generateMessageId(s.read_outbox_max_id)||0,this.threadsToReplies[n]=e+"_"+t,a})}handleNewMessage(e,t){void 0===this.newMessagesToHandle[e]&&(this.newMessagesToHandle[e]=new Set),this.newMessagesToHandle[e].add(t),this.newMessagesHandleTimeout||(this.newMessagesHandleTimeout=window.setTimeout(this.handleNewMessages,0))}scheduleHandleNewDialogs(e,t){return void 0!==e&&(this.newDialogsToHandle[e]=t),this.newDialogsHandlePromise?this.newDialogsHandlePromise:this.newDialogsHandlePromise=new Promise(e=>{setTimeout(()=>{this.newDialogsHandlePromise=void 0,this.handleNewDialogs()},0)})}deleteMessages(e,t,s){let i;const a=t.map(e=>this.getServerMessageId(e));if(e<0&&k.a.isChannel(e)){const s=-e,n=w.a.getChat(s);if(!(n.pFlags.creator||n.pFlags.editor&&n.pFlags.megagroup)){const s=[];if((n.pFlags.editor||n.pFlags.megagroup)&&t.forEach((i,a)=>{this.getMessageByPeer(e,t[a]).pFlags.out&&s.push(i)}),!s.length)return;t=s}i=p.a.invokeApi("channels.deleteMessages",{channel:w.a.getChannelInput(s),id:a}).then(e=>{S.a.processLocalUpdate({_:"updateDeleteChannelMessages",channel_id:s,messages:t,pts:e.pts,pts_count:e.pts_count})})}else i=p.a.invokeApi("messages.deleteMessages",{revoke:s,id:a}).then(e=>{S.a.processLocalUpdate({_:"updateDeleteMessages",messages:t,pts:e.pts,pts_count:e.pts_count})});return i}readHistory(e,t=0,s,i=!1){if(this.log("readHistory:",e,t,s),!this.getReadMaxIdIfUnread(e,s)&&!i)return this.log("readHistory: isn't unread"),Promise.resolve();const a=this.getHistoryStorage(e,s);if(a.triedToReadMaxId>=t)return Promise.resolve();let n;return s?(a.readPromise||(n=p.a.invokeApi("messages.readDiscussion",{peer:k.a.getInputPeerById(e),msg_id:this.getServerMessageId(s),read_max_id:this.getServerMessageId(t)})),S.a.processLocalUpdate({_:"updateReadChannelDiscussionInbox",channel_id:-e,top_msg_id:s,read_max_id:t})):k.a.isChannel(e)?(a.readPromise||(n=p.a.invokeApi("channels.readHistory",{channel:w.a.getChannelInput(-e),max_id:this.getServerMessageId(t)})),S.a.processLocalUpdate({_:"updateReadChannelInbox",max_id:t,channel_id:-e,still_unread_count:void 0,pts:void 0})):(a.readPromise||(n=p.a.invokeApi("messages.readHistory",{peer:k.a.getInputPeerById(e),max_id:this.getServerMessageId(t)}).then(e=>{S.a.processUpdateMessage({_:"updateShort",update:{_:"updatePts",pts:e.pts,pts_count:e.pts_count}})})),S.a.processLocalUpdate({_:"updateReadHistoryInbox",max_id:t,peer:k.a.getOutputPeer(e),still_unread_count:void 0,pts:void 0,pts_count:void 0})),j.a.soundReset(k.a.getPeerString(e)),a.readPromise?a.readPromise:(a.triedToReadMaxId=t,n.finally(()=>{delete a.readPromise,this.log("readHistory: promise finally",t,a.readMaxId),a.readMaxId>t&&this.readHistory(e,a.readMaxId,s,!0)}),a.readPromise=n)}readAllHistory(e,t,s=!1){const i=this.getHistoryStorage(e,t);i.maxId&&this.readHistory(e,i.maxId,t,s)}readMessages(e,t){if(t=t.map(e=>this.getServerMessageId(e)),e<0&&k.a.isChannel(e)){const s=-e;p.a.invokeApi("channels.readMessageContents",{channel:w.a.getChannelInput(s),id:t}).then(()=>{S.a.processLocalUpdate({_:"updateChannelReadMessagesContents",channel_id:s,messages:t})})}else p.a.invokeApi("messages.readMessageContents",{id:t}).then(e=>{S.a.processLocalUpdate({_:"updateReadMessagesContents",messages:t,pts:e.pts,pts_count:e.pts_count})})}getHistoryStorage(e,t){var s,i;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 y.b}):null!==(i=this.historiesStorage[e])&&void 0!==i?i:this.historiesStorage[e]={count:null,history:new y.b}}setDialogToStateIfMessageIsTop(e){const t=this.getDialogOnly(e.peerId);t&&t.top_message===e.mid&&this.dialogsStorage.setDialogToState(t)}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 i=this.getMessageByPeer(e,t);return s&&_.default.dispatchEvent(s,i),i})}checkPendingMessage(e){const t=this.pendingByMessageId[e.mid];let s;if(t){const i=this.pendingByRandomId[t];(s=this.finalizePendingMessage(t,e))&&_.default.dispatchEvent("history_update",{storage:i.storage,peerId:e.peerId,mid:e.mid}),delete this.pendingByMessageId[e.mid]}return s}mutePeer(e,t){const s={_:"inputPeerNotifySettings"};return void 0===t&&(t=!j.a.isPeerLocalMuted(e,!1)),s.mute_until=t?2147483647:0,j.a.updateNotifySettings({_:"inputNotifyPeer",peer:k.a.getInputPeerById(e)},s)}canWriteToPeer(e,t){if(e<0){return w.a.hasRights(-e,"send_messages",void 0,!!t)}return F.a.canSendToUser(e)}finalizePendingMessage(e,t){const s=this.pendingByRandomId[e];if(s){const{peerId:i,tempId:a,threadId:n,storage:o}=s;[this.getHistoryStorage(i),n?this.getHistoryStorage(i,n):void 0].filter(Boolean).forEach(e=>{e.history.delete(a)});const r=this.getMessageFromStorage(o,a);return r.deleted||(delete r.pFlags.is_outgoing,delete r.pending,delete r.error,delete r.random_id,delete r.send,_.default.dispatchEvent("messages_pending")),delete this.pendingByRandomId[e],this.finalizePendingMessageCallbacks(o,a,t.mid),r}return!1}finalizePendingMessageCallbacks(e,t,s){const i=this.getMessageFromStorage(e,s),a=this.tempFinalizeCallbacks[t];if(void 0!==a){for(const e in a){const{deferred:t,callback:s}=a[e];s(i).then(t.resolve,t.reject)}delete this.tempFinalizeCallbacks[t]}if(i.media)if(i.media.photo){const e=C.a.getPhoto(""+t);if(e){const t=i.media.photo,s=t.sizes[t.sizes.length-1],a=D.a.getCacheContext(t,s.type),n=D.a.getCacheContext(e,"full");Object.assign(a,n);const o=t.sizes[t.sizes.length-1],r=C.a.getPhotoDownloadOptions(t,o),d=Object(U.a)(r.location);D.a.fakeDownload(d,n.url)}}else if(i.media.document){const e=E.a.getDoc(""+t);if(e&&e.type&&"sticker"!==e.type){const t=i.media.document,s=D.a.getCacheContext(t),a=D.a.getCacheContext(e);Object.assign(s,a);const n=E.a.getInputFileName(t);D.a.fakeDownload(n,a.url)}}else i.media.poll&&(delete x.a.polls[t],delete x.a.results[t]);const n=this.getMessageFromStorage(e,t);delete e[t],this.handleReleasingMessage(n),_.default.dispatchEvent("message_sent",{storage:e,tempId:t,tempMessage:n,mid:s})}incrementMaxSeenId(e){if(!e||this.maxSeenId&&!(e>this.maxSeenId))return!1;this.maxSeenId=e,A.default.pushToState("maxSeenMsgId",e),p.a.invokeApi("messages.receivedMessages",{max_id:this.getServerMessageId(e)})}notifyAboutMessage(e,t={}){const s=this.getMessagePeer(e),i={},a=k.a.getPeerString(s);let n;n=t.peerTypeNotifySettings.show_previews?"message"===e._&&e.fwd_from&&t.fwdCount?c.default.format("Notifications.Forwarded",!0,[t.fwdCount]):this.wrapMessageForReply(e,void 0,void 0,!0):c.default.format("Notifications.New",!0),i.title=k.a.getPeerTitle(s,!0),s<0&&e.fromId!==e.peerId&&(i.title=k.a.getPeerTitle(e.fromId,!0)+" @ "+i.title),i.title=m.a.wrapPlainText(i.title),i.onclick=()=>{_.default.dispatchEvent("history_focus",{peerId:s,mid:e.mid})},i.message=n,i.key="msg"+e.mid,i.tag=a,i.silent=!0;const o=k.a.getPeerPhoto(s);o?q.a.loadAvatar(s,o,"photo_small").loadPromise.then(t=>{e.pFlags.unread&&(i.image=t,j.a.notify(i))}):j.a.notify(i)}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)):p.a.invokeApiSingle("messages.getScheduledHistory",{peer:k.a.getInputPeerById(e),hash:0}).then(t=>{if("messages.messagesNotModified"!==t._){F.a.saveApiUsers(t.users),w.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 p.a.invokeApi("messages.sendScheduledMessages",{peer:k.a.getInputPeerById(e),id:t.map(e=>this.getServerMessageId(e))}).then(e=>{S.a.processUpdateMessage(e)})}deleteScheduledMessages(e,t){return p.a.invokeApi("messages.deleteScheduledMessages",{peer:k.a.getInputPeerById(e),id:t.map(e=>this.getServerMessageId(e))}).then(e=>{S.a.processUpdateMessage(e)})}getMessageWithReplies(e){if(e.peerId===z.a||(e=this.filterMessages(e,e=>!!e.replies)[0])&&e.replies&&e.replies.pFlags.comments&&777!==e.replies.channel_id)return e}isFetchIntervalNeeded(e){return e<0&&!w.a.isInChat(e)}getNewHistory(e,t){var s;return $(this,void 0,void 0,(function*(){if(!this.isFetchIntervalNeeded(e))return;const i=this.getHistoryStorage(e,t),a=i.history.slice;if(!a.isEnd(y.a.Bottom))return;delete i.maxId,a.unsetEnd(y.a.Bottom);let n=this.getHistory(e,null!==(s=a[0])&&void 0!==s?s:1,0,50,t);n instanceof Promise&&(n=yield n);for(let t=0,s=n.history.length;t<s;++t)this.handleNewMessage(e,n.history[t]);return i}))}getHistory(e,t=0,s,i,a){const n=this.getHistoryStorage(e,a);let o=0;i&&(o=-i,s+=i);const r=n.history.sliceMe(t,o,s);return!r||r.slice.length!==s&&(r.fulfilled&y.a.Both)!==y.a.Both?this.fillHistoryStorage(e,t,s,o,n,a).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}}):{count:n.count,history:r.slice,offsetIdOffset:r.offsetIdOffset}}fillHistoryStorage(e,t,s,i,a,n){return this.requestHistory(e,t,s,i,void 0,n).then(n=>{const{offset_id_offset:o,count:r,messages:d}=n;a.count=r||d.length;const l=o||0,h=i<0?s+i:s,c=l>=a.count-h||a.count<h,g=!l||i<0&&l+i<=0,p=d.map(t=>(this.mergeReplyKeyboard(a,t)&&_.default.dispatchEvent("history_reply_markup",{peerId:e}),t.mid));if(t&&!p.includes(t)&&l<a.count){let e=0;for(const s=p.length;e<s&&!(t>p[e]);++e);p.splice(e,0,t)}const u=a.history.insertSlice(p)||a.history.slice;c&&u.setEnd(y.a.Top),g&&(u.setEnd(y.a.Bottom),a.maxId=u[0])})}requestHistory(e,t,s=0,i=0,a=0,n=0){const o={peer:k.a.getInputPeerById(e),offset_id:this.getServerMessageId(t)||0,offset_date:a,add_offset:i,limit:s,max_id:0,min_id:0,hash:0};n&&(o.msg_id=this.getServerMessageId(n)||0);return p.a.invokeApiSingle(n?"messages.getReplies":"messages.getHistory",o,{noErrorBox:!0}).then(o=>{R.b&&this.log("requestHistory result:",e,o,t,s,i),F.a.saveApiUsers(o.users),w.a.saveApiChats(o.chats),this.saveMessages(o.messages),k.a.isChannel(e)&&S.a.addChannelState(-e,o.pts);let r=o.messages.length,d=o.count;r&&o.messages[r-1].deleted&&(o.messages.splice(r-1,1),r--,d--);const l=this.getHistoryStorage(e,n),h=o.messages[r-1];if(r&&h.grouped_id){const t=l.history.findSlice(h.mid);if(t&&t.slice.length+o.messages.length<d)return this.requestHistory(e,h.mid,10,0,a,n).then(e=>o)}return o},t=>{switch(t.type){case"CHANNEL_PRIVATE":let t=w.a.getChat(-e);t={_:"channelForbidden",access_hash:t.access_hash,title:t.title},S.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 i=s.map(e=>({_:"inputMessageID",id:this.getServerMessageId(e)}));let a;a=+e<0&&k.a.isChannel(+e)?p.a.invokeApiSingle("channels.getMessages",{channel:w.a.getChannelInput(-+e),id:i}):p.a.invokeApiSingle("messages.getMessages",{id:i}),t.push(a.then(t=>{"messages.messagesNotModified"!==t._&&(F.a.saveApiUsers(t.users),w.a.saveApiChats(t.chats),this.saveMessages(t.messages)),_.default.dispatchEvent("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 i;return this.getMessageByPeer(e,t).deleted||s?this.needSingleMessages[e]&&-1!==this.needSingleMessages[e].indexOf(t)?this.fetchSingleMessagesPromise?this.fetchSingleMessagesPromise:void 0:((null!==(i=this.needSingleMessages[e])&&void 0!==i?i:this.needSingleMessages[e]=[]).push(t),this.fetchSingleMessages()):(_.default.dispatchEvent("messages_downloaded",{peerId:e,mids:[t]}),Promise.resolve())}setTyping(e,t){let s=this.typings[e];return _.default.myId&&e&&this.canWriteToPeer(e)&&e!==_.default.myId&&(null==s?void 0:s.type)!==t._?((null==s?void 0:s.timeout)&&clearTimeout(s.timeout),s=this.typings[e]={type:t._},p.a.invokeApi("messages.setTyping",{peer:k.a.getInputPeerById(e),action:t}).finally(()=>{s===this.typings[e]&&(s.timeout=window.setTimeout(()=>{delete this.typings[e]},6e3))})):Promise.resolve(!1)}handleReleasingMessage(e){if("media"in e){const t=e.media.webpage||e.media,s=t.photo||t.document;(null==s?void 0:s.file_reference)&&u.a.deleteContext(s.file_reference,{type:"message",peerId:e.peerId,messageId:e.mid}),"webpage"in e.media&&O.a.deleteWebPageFromPending(e.media.webpage,e.mid)}}handleDeletedMessages(e,t,s){const i={count:0,unread:0,msgs:{}};for(const a of s){const s=this.getMessageFromStorage(t,a);if(s.deleted)continue;if(this.handleReleasingMessage(s),this.updateMessageRepliesIfNeeded(s),s.pFlags.out||s.pFlags.is_outgoing||!s.pFlags.unread||(i.unread++,j.a.cancel("msg"+a)),i.count++,i.msgs[a]=!0,s.deleted=!0,"messageService"!==s._&&s.grouped_id){const e=this.groupedMessagesStorage[s.grouped_id];e&&(delete e[a],i.albums||(i.albums={}),(i.albums[s.grouped_id]||(i.albums[s.grouped_id]=new Set)).add(a),Object.keys(e).length||(delete i.albums,delete this.groupedMessagesStorage[s.grouped_id]))}delete t[a];const n=this.newMessagesToHandle[e];n&&n.has(a)&&n.delete(a)}if(i.albums)for(const t in i.albums)_.default.dispatchEvent("album_edit",{peerId:e,groupId:t,deletedMids:[...i.albums[t]]});return i}handleEditedMessage(e,t){var s;(null===(s=e.media)||void 0===s?void 0:s.webpage)&&O.a.deleteWebPageFromPending(e.media.webpage,e.mid)}}Y.MESSAGE_ID_INCREMENT=65536,Y.MESSAGE_ID_OFFSET=4294967295;const J=new Y;R.a.appMessagesManager=J;t.a=J},51:function(e,t,s){"use strict";var i=s(70),a=s(84),n=s(30),o=s(0),r=s(27),d=s(119),l=s(49),h=s(34),c=s(121),g=s(26),p=s(77),u=s(103),f=s(40);class m{constructor(){this.photos={},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 i=this.photos[e.id];if(e.file_reference&&(Object(n.h)("file_reference",i,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 i?Object.assign(i,e):this.photos[e.id]=e}choosePhotoSize(e,t=0,s=0,i=!1){window.devicePixelRatio>1&&(t*=2,s*=2);let a={_:"photoSizeEmpty",type:""};const n=e.sizes||e.thumbs;if(null==n?void 0:n.length){for(let e=0,i=n.length;e<i;++e){const i=n[e];if(!("w"in i)&&!("h"in i))continue;a=i;const o=Object(u.a)(i.w,i.h,t,s);if(o.width>=t||o.height>=s)break}i&&"photoSizeEmpty"===a._&&"photoStrippedSize"===n[0]._&&(a=n[0])}return a}getUserPhotos(e,t="0",s=20){const i=h.a.getUserInput(e);return r.a.invokeApiCacheable("photos.getUserPhotos",{user_id:i,offset:0,limit:s,max_id:t},{cacheSeconds:60}).then(t=>{h.a.saveApiUsers(t.users);const s=t.photos.map((s,i)=>(t.photos[i]=this.savePhoto(s,{type:"profilePhoto",peerId:e}),s.id));return{count:t.count||t.photos.length,photos:s}})}getPreviewURLFromBytes(e,t=!1){let s,i;t?s=e instanceof Uint8Array?e:new Uint8Array(e):(s=new Uint8Array(m.jpegHeader.concat(Array.from(e.slice(3)),m.jpegTail)),s[164]=e[1],s[166]=e[2]),i=t?o.isSafari?"image/png":"image/webp":"image/jpeg";const a=new Blob([s],{type:i});return URL.createObjectURL(a)}getPathFromPhotoPathSize(e){const t=e.bytes;let s="M";for(let e=0,i=t.length;e<i;++e){const i=t[e];i>=192?s+="AACAAAAHAAALMAAAQASTAVAAAZaacaaaahaaalmaaaqastava.az0123456789-,"[i-128-64]:(i>=128?s+=",":i>=64&&(s+="-"),s+=""+(63&i))}return s+="z",s}getPreviewURLFromThumb(e,t,s=!1){const i=l.a.getCacheContext(e,t.type);return i.url||(i.url=this.getPreviewURLFromBytes(t.bytes,s))}getImageFromStrippedThumb(e,t,s){const i=this.getPreviewURLFromThumb(e,t,!1),a=new Image;a.classList.add("thumbnail");const n=(s?Object(c.a)(i):Promise.resolve(i)).then(e=>Object(p.b)(a,e));return{image:a,loadPromise:n}}setAttachmentSize(e,t,s,i,a=!0,n){const o=this.choosePhotoSize(e,s,i);let r;r="document"===e._?Object(f.c)(e.w||512,e.h||512):Object(f.c)("w"in o?o.w:100,"h"in o?o.h:100);let d=Object(f.c)(s,i);d=r=r.aspect(d,a);let l=!0;return("photo"===e._||["video","gif"].includes(e.type))&&(d.width<200&&d.height<200&&(d=r=r.aspectCovered(Object(f.c)(200,200))),n&&(n.message||n.reply_to_mid||n.media.webpage||n.replies&&n.replies.pFlags.comments&&777!==n.replies.channel_id)&&d.width<320&&(d=Object(f.c)(320,d.height),l=!1),l&&d.width<120&&(d=Object(f.c)(120,d.height),l=!1)),t.style.width=d.width+"px",t.style.height=d.height+"px",{photoSize:o,size:r,isFit:l}}getStrippedThumbIfNeeded(e,t,s,i=!1){if(!t.downloaded||["video","gif"].includes(e.type)||i){if("document"===e._&&t.downloaded&&!i)return null;const a=e.sizes||e.thumbs,n=(null==a?void 0:a.length)?a.find(e=>"photoStrippedSize"===e._):null;if(n&&"bytes"in n)return this.getImageFromStrippedThumb(e,n,s)}return null}getPhotoDownloadOptions(e,t,s,i){const a="document"===e._;if(!t||"photoSizeEmpty"===t._)throw new Error("photoSizeEmpty!");const n=("photoSize"===t._||"photoSizeProgressive"===t._)&&e.access_hash&&e.file_reference,o={_:a?"inputDocumentFileLocation":"inputPhotoFileLocation",id:e.id,access_hash:e.access_hash,file_reference:e.file_reference,thumb_size:t.type};return{dcId:e.dc_id,location:o,size:n?t.size:void 0,queueId:s,onlyCache:i}}preloadPhoto(e,t,s,i){const n=this.getPhoto(e);if(!n||"photoEmpty"===n._)throw new Error("preloadPhoto photoEmpty!");if(!t){const e=this.windowW,s=this.windowH;t=this.choosePhotoSize(n,e,s)}const o=l.a.getCacheContext(n,t.type);if(o.downloaded>=("size"in t?t.size:0)&&o.url)return Promise.resolve();const r=this.getPhotoDownloadOptions(n,t,s,i),d=Object(a.a)(r.location);let h=l.a.getDownload(d);return h||(h=l.a.download(r),h.then(e=>{if(!o.downloaded||o.downloaded<e.size){const t=URL.createObjectURL(e);o.downloaded=e.size,o.url=t}return e}).catch(()=>{}),h)}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 i=this.getPhotoDownloadOptions(e,s,t);i.fileName="photo"+e.id+".jpg",l.a.downloadToDisc(i,i.fileName)}}m.jpegHeader=Object(i.c)("ffd8ffe000104a46494600010100000100010000ffdb004300281c1e231e19282321232d2b28303c64413c37373c7b585d4964918099968f808c8aa0b4e6c3a0aadaad8a8cc8ffcbdaeef5ffffff9bc1fffffffaffe6fdfff8ffdb0043012b2d2d3c353c76414176f8a58ca5f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8f8ffc00011080000000003012200021101031101ffc4001f0000010501010101010100000000000000000102030405060708090a0bffc400b5100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9faffc4001f0100030101010101010101010000000000000102030405060708090a0bffc400b51100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00"),m.jpegTail=Object(i.c)("ffd9");const _=new m;g.a&&(g.a.appPhotosManager=_),t.a=_},52:function(e,t,s){"use strict";s.d(t,"a",(function(){return h}));var i=s(26),a=s(38),n=s(13),o=s(12),r=s(33),d=s(34);const l=new WeakMap;i.a.peerTitleWeakMap=l,n.default.addEventListener("peer_title_edit",e=>{Array.from(document.querySelectorAll(`.peer-title[data-peer-id="${e}"]`)).forEach(e=>{const t=l.get(e);t&&t.update()})});class h{constructor(e){this.plainText=!1,this.onlyFirstName=!1,this.dialog=!1,this.element=document.createElement("span"),this.element.classList.add("peer-title"),this.element.setAttribute("dir","auto"),this.update(e),l.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(r.a)(this.element,Object(o.i18n)(this.onlyFirstName?"Saved":"SavedMessages")):this.peerId>0&&d.a.getUser(this.peerId).pFlags.deleted?Object(r.a)(this.element,Object(o.i18n)(this.onlyFirstName?"Deleted":"HiddenName")):this.element.innerHTML=a.a.getPeerTitle(this.peerId,this.plainText,this.onlyFirstName)}}},55:function(e,t,s){"use strict";var i=s(26),a=s(59),n=s(27);const o=new class{constructor(){this.serverTimeOffset=0,a.a.get("server_time_offset").then(e=>{e&&(this.serverTimeOffset=e)}),n.a.addTaskListener("applyServerTimeOffset",e=>{this.serverTimeOffset=e.payload})}};i.a&&(i.a.serverTimeManager=o),t.a=o},68:function(e,t,s){"use strict";var i=s(84),a=s(30),n=s(119),o=s(125),r=s(28),d=s(120),l=s(49),h=s(51),c=s(121),g=s(27),p=s(26),u=s(47),f=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.apply(e,t||[])).next())}))};const m=new class{constructor(){this.docs={},this.savingLottiePreview={},this.onServiceWorkerFail=()=>{for(const e in this.docs){const t=this.docs[e];if(t.supportsStreaming){delete t.supportsStreaming;delete l.a.getCacheContext(t).url}}},g.a.onServiceWorkerFail=this.onServiceWorkerFail}saveDoc(e,t){if("documentEmpty"===e._)return;const s=this.docs[e.id];if(e.file_reference&&(Object(a.h)("file_reference",s,e),n.a.saveContext(e.file_reference,t)),s||(this.docs[e.id]=e),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"}if("application/pdf"===e.mime_type&&(e.type="pdf"),"voice"!==e.type&&"round"!==e.type||(e.file_name=e.type+"_"+Object(u.f)(new Date(1e3*e.date),{monthAsNumber:!0,leadingZero:!0}).replace(/[:\.]/g,"-").replace(", ","_")),g.a.isServiceWorkerOnline()&&("gif"===e.type&&e.size>8e6||"audio"===e.type||"video"===e.type)){e.supportsStreaming=!0;const t=l.a.getCacheContext(e);t.url||(t.url=this.getFileURL(e))}return 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),s?Object.assign(s,e):e}getDoc(e){return Object(a.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,i){const a=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:a,size:t?t.size:e.size,mimeType:n,fileName:e.file_name,queueId:s,onlyCache:i}}getFileURL(e,t=!1,s){let a;return a=t?"download":s?"thumb":e.supportsStreaming?"stream":"document",Object(i.b)(a,this.getFileDownloadOptions(e,s))}getThumbURL(e,t){let s=Promise.resolve();const i=l.a.getCacheContext(e,t.type);return i.url||(s="bytes"in t?Object(c.a)(h.a.getPreviewURLFromBytes(t.bytes,!!e.sticker)).then(e=>{i.url=e}):h.a.preloadPhoto(e,t)),{thumb:t,cacheContext:i,promise:s}}getThumb(e,t=!0){const s=h.a.choosePhotoSize(e,0,0,!t);return"photoSizeEmpty"===s._?null:this.getThumbURL(e,s)}getInputFileName(e,t){return Object(i.a)(this.getInput(e,t),{fileName:e.file_name})}downloadDoc(e,t,s){const i=this.getInputFileName(e);let a=l.a.getDownload(i);if(a)return a;const n=this.getFileDownloadOptions(e,void 0,t,s);a=l.a.download(n);const r=l.a.getCacheContext(e),d=a;return d.then(e=>{r.url=URL.createObjectURL(e),r.downloaded=e.size},()=>{}),"voice"!==e.type||o.a.isPlaySupported()||(a=d.then(e=>f(this,void 0,void 0,(function*(){const t=new FileReader;return yield new Promise((s,i)=>{t.onloadend=e=>{const t=new Uint8Array(e.target.result);o.a.decode(t).then(e=>{r.url=e.url,s()},e=>{delete r.downloaded,i(e)})},t.readAsArrayBuffer(e)}),e})))),a}saveLottiePreview(e,t,s){const i=e.id+"-"+s;if(this.savingLottiePreview[i])return;e.stickerCachedThumbs||(Object(a.c)(e,["stickerCachedThumbs"]),e.stickerCachedThumbs={});const n=e.stickerCachedThumbs[s];n&&n.w>=t.width&&n.h>=t.height||(this.savingLottiePreview[i]=!0,t.toBlob(a=>{const n={url:URL.createObjectURL(a),w:t.width,h:t.height};e.stickerCachedThumbs[s]=n,delete this.savingLottiePreview[i]}))}saveDocFile(e,t){const s=this.downloadDoc(e,t);return s.then(()=>{const t=l.a.getCacheContext(e);l.a.createDownloadAnchor(t.url,e.file_name)}),s}};p.a.appDocsManager=m,t.a=m},69:function(e,t,s){"use strict";s.r(t),s.d(t,"AppProfileManager",(function(){return v}));var i=s(26),a=s(47),n=s(73),o=s(12),r=s(27),d=s(28),l=s(13),h=s(89),c=s(58),g=s(37),p=s(85),u=s(38),f=s(51),m=s(34),_=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.apply(e,t||[])).next())}))};class v{constructor(){this.usersFull={},this.chatsFull={},this.fullPromises={},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 i="updateUserTyping"===e._?s:-(e.chat_id||e.channel_id),a=null!==(t=this.typingsInPeer[i])&&void 0!==t?t:this.typingsInPeer[i]=[];let n=a.find(e=>e.userId===s);const o=()=>{delete n.timeout;const e=a.indexOf(n);-1!==e&&a.splice(e,1),l.default.dispatchEvent("peer_typings",{peerId:i,typings:a}),a.length||delete this.typingsInPeer[i]};if(n&&void 0!==n.timeout&&clearTimeout(n.timeout),"sendMessageCancelAction"===e.action._){if(!n)return;return void o()}n||(n={userId:s},a.push(n)),n.action=e.action;const r=m.a.hasUser(s);r?m.a.forceUserOnline(s):"updateChatUserTyping"===e._&&e.chat_id&&g.a.hasChat(e.chat_id)&&!g.a.isChannel(e.chat_id)&&M.getChatFull(e.chat_id).then(()=>{void 0!==n.timeout&&m.a.hasUser(s)&&l.default.dispatchEvent("peer_typings",{peerId:i,typings:a})}),n.timeout=window.setTimeout(o,6e3),r&&l.default.dispatchEvent("peer_typings",{peerId:i,typings:a})},l.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,l.default.dispatchEvent("chat_full_update",e))}},updateChatParticipantAdd:e=>{const t=this.chatsFull[e.chat_id];if(void 0!==t){const s=t.participants,i=s.participants||[];for(let t=0,s=i.length;t<s;t++)if(i[t].user_id===e.user_id)return;i.push({_:"chatParticipant",user_id:e.user_id,inviter_id:e.inviter_id,date:Object(a.h)(!0)}),s.version=e.version,l.default.dispatchEvent("chat_full_update",e.chat_id)}},updateChatParticipantDelete:e=>{const t=this.chatsFull[e.chat_id];if(void 0!==t){const s=t.participants,i=s.participants||[];for(let t=0,a=i.length;t<a;t++)if(i[t].user_id===e.user_id)return i.splice(t,1),s.version=e.version,void l.default.dispatchEvent("chat_full_update",e.chat_id)}},updateUserTyping:this.onUpdateUserTyping,updateChatUserTyping:this.onUpdateUserTyping,updateChannelUserTyping:this.onUpdateUserTyping}),l.default.addEventListener("chat_update",e=>{var t;const s=this.chatsFull[e],i=g.a.getChat(e);if(!i.photo||!s)return;const a="chatPhotoEmpty"===i.photo._;if(s.chat_photo&&a!==("photoEmpty"===s.chat_photo._))return delete this.chatsFull[e],void l.default.dispatchEvent("chat_full_update",e);if(a)return;const n=i.photo.photo_id;(null===(t=s.chat_photo)||void 0===t?void 0:t.id)!==n&&(delete this.chatsFull[e],l.default.dispatchEvent("chat_full_update",e))}),l.default.addEventListener("invalidate_participants",e=>{this.invalidateChannelParticipants(e)}),this.megagroupOnlines={},this.typingsInPeer={}}getProfile(e,t){return this.usersFull[e]&&!t?Promise.resolve(this.usersFull[e]):this.fullPromises[e]?this.fullPromises[e]:this.fullPromises[e]=r.a.invokeApi("users.getFullUser",{id:m.a.getUserInput(e)}).then(t=>{const s=t.user;return m.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=d.a.wrapRichText(t.about,{noLinebreaks:!0})),p.a.savePeerSettings(e,t.notify_settings),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(g.a.isChannel(e))return this.getChannelFull(e,t);const s=this.chatsFull[e];if(s&&!t){const t=g.a.getChat(e);if(t.version===s.participants.version||t.pFlags.left)return Promise.resolve(s)}const i=-e;return void 0!==this.fullPromises[i]?this.fullPromises[i]:this.fullPromises[i]=r.a.invokeApi("messages.getFullChat",{chat_id:e}).then(t=>{g.a.saveApiChats(t.chats,!0),m.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:i})),p.a.savePeerSettings(i,s.notify_settings),delete this.fullPromises[i],this.chatsFull[e]=s,l.default.dispatchEvent("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:r.a.invokeApi("messages.exportChatInvite",{peer:u.a.getInputPeerById(-e)}).then(t=>(void 0!==this.chatsFull[e]&&(this.chatsFull[e].exported_invite=t),t.link)))}getChannelParticipants(e,t={_:"channelParticipantsRecent"},s=200,i=0){if("channelParticipantsRecent"===t._){const t=g.a.getChat(e);if(t&&t.pFlags&&(t.pFlags.kicked||t.pFlags.broadcast&&!t.pFlags.creator&&!t.admin_rights))return Promise.reject()}return r.a.invokeApiCacheable("channels.getParticipants",{channel:g.a.getChannelInput(e),filter:t,offset:i,limit:s,hash:0},{cacheSeconds:60}).then(e=>(m.a.saveApiUsers(e.users),e))}getChannelParticipant(e,t){return r.a.invokeApiSingle("channels.getParticipant",{channel:g.a.getChannelInput(e),participant:u.a.getInputPeerById(t)}).then(e=>(m.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]=r.a.invokeApi("channels.getFullChannel",{channel:g.a.getChannelInput(e)}).then(t=>{g.a.saveApiChats(t.chats,!0),m.a.saveApiUsers(t.users);const i=t.full_chat;return i&&i.chat_photo.id&&(i.chat_photo=f.a.savePhoto(i.chat_photo,{type:"profilePhoto",peerId:s})),p.a.savePeerSettings(s,i.notify_settings),delete this.fullPromises[s],this.chatsFull[e]=i,l.default.dispatchEvent("chat_full_update",e),i},t=>{switch(t.type){case"CHANNEL_PRIVATE":let t=g.a.getChat(e);t={_:"channelForbidden",access_hash:t.access_hash,title:t.title},c.a.processUpdateMessage({_:"updates",updates:[{_:"updateChannel",channel_id:e}],chats:[t],users:[]})}return Promise.reject(t)})}getMentions(e,t,s){const i=e=>{const s=new h.a(!0,!0);return e.forEach(e=>{s.indexObject(e,m.a.getUserSearchText(e))}),Array.from(s.search(t))};return g.a.isChannel(e)?this.getChannelParticipants(e,{_:"channelParticipantsMentions",q:t,top_msg_id:s},50,0).then(e=>i(e.participants.map(e=>g.a.getParticipantPeerId(e)))):this.getChatFull(e).then(e=>i(e.participants.participants.map(e=>e.user_id)))}invalidateChannelParticipants(e){delete this.chatsFull[e],delete this.fullPromises[-e],r.a.clearCache("channels.getParticipants",t=>t.channel.channel_id===e),l.default.dispatchEvent("chat_full_update",e)}updateProfile(e,t,s){return r.a.invokeApi("account.updateProfile",{first_name:e,last_name:t,about:s}).then(e=>(m.a.saveApiUser(e),this.getProfile(l.default.myId,!0)))}uploadProfilePhoto(e){return r.a.invokeApi("photos.uploadProfilePhoto",{file:e}).then(e=>{m.a.saveApiUsers(e.users);const t=l.default.myId;f.a.savePhoto(e.photo,{type:"profilePhoto",peerId:t}),c.a.processLocalUpdate({_:"updateUserPhoto",user_id:t,date:Object(a.h)(!0),photo:m.a.getUser(t).photo,previous:!0})})}getChatMembersString(e){var t,s;const i=g.a.getChat(e);if("chatForbidden"===i._)return Object(o.i18n)("YouWereKicked");const a=this.chatsFull[e];let r;r=a?"channelFull"===a._?a.participants_count:null===(t=a.participants.participants)||void 0===t?void 0:t.length:i.participants_count||(null===(s=i.participants)||void 0===s?void 0:s.participants.length);r=r||1;let d=g.a.isBroadcast(e)?"Peer.Status.Subscribers":"Peer.Status.Member";return Object(o.i18n)(d,[Object(n.d)(r)])}getOnlines(e){var t,s;return _(this,void 0,void 0,(function*(){if(g.a.isMegagroup(e)){const i=Date.now()/1e3|0,a=null!==(t=this.megagroupOnlines[e])&&void 0!==t?t:this.megagroupOnlines[e]={timestamp:0,onlines:1};if(i-a.timestamp<60)return a.onlines;const n=yield r.a.invokeApi("messages.getOnlines",{peer:g.a.getChannelInputPeer(e)}),o=null!==(s=n.onlines)&&void 0!==s?s:1;return a.timestamp=i,a.onlines=o,o}if(g.a.isBroadcast(e))return 1;const i=(yield this.getChatFull(e)).participants;if(i&&i.participants){return i.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}))}getPeerTypings(e){return this.typingsInPeer[e]}}const M=new v;i.a.appProfileManager=M,t.default=M},70:function(e,t,s){"use strict";function i(e){const t=new Array(e.length);for(let s=0;s<e.length;++s)t[s]=(e[s]<16?"0":"")+(e[s]||0).toString(16);return t.join("")}function a(e){const t=e.length,s=new Uint8Array(Math.ceil(t/2));let i=0;t%2&&(s[i++]=parseInt(e.charAt(0),16));for(let a=i;a<t;a+=2)s[i++]=parseInt(e.substr(a,2),16);return s}function n(e){let t,s="";for(let i=e.length,a=0,n=0;n<i;++n)t=n%3,a|=e[n]<<(16>>>t&24),2!==t&&i-n!=1||(s+=String.fromCharCode(o(a>>>18&63),o(a>>>12&63),o(a>>>6&63),o(63&a)),a=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 i=0;i<s;++i)if(e[i]!==t[i])return!1;return!0}function d(...e){const t=e.reduce((e,t)=>e+(t.byteLength||t.length),0),s=new Uint8Array(t);let i=0;return e.forEach(e=>{s.set(e instanceof ArrayBuffer?new Uint8Array(e):e,i),i+=e.byteLength||e.length}),s}s.d(t,"e",(function(){return i})),s.d(t,"c",(function(){return a})),s.d(t,"d",(function(){return n})),s.d(t,"b",(function(){return r})),s.d(t,"a",(function(){return d}))},75:function(e,t,s){"use strict";s.d(t,"a",(function(){return d})),s.d(t,"d",(function(){return h})),s.d(t,"b",(function(){return c})),s.d(t,"c",(function(){return g}));var i=s(32),a=s(41);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(57),r=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.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(a.b)("LL",a.a.Error),this.processQueue=Object(i.f)(()=>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.c)(this.queue,t=>t.div===e),this.intersector.unobserve(e)}}class h extends l{constructor(e=8){super(e),this.parallelLimit=e,this.onVisibilityChange=(e,t)=>{t&&(Object(o.c)(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 c 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.c)(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 g extends l{constructor(e=8,t){super(e),this.parallelLimit=e,this.onVisibilityChange=t,this.intersector=new n((e,t)=>{const s=Object(o.c)(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)}}},77:function(e,t,s){"use strict";s.d(t,"a",(function(){return n})),s.d(t,"b",(function(){return o}));const i={},a=(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(!t)return console.error("renderImageFromUrl: no url?",e,t),void(s&&s());if(i[t]&&n||e instanceof HTMLVideoElement)e&&a(e,t),s&&s();else{const n=e instanceof HTMLImageElement,o=n?e:new Image;o.src=t,o.addEventListener("load",()=>{!n&&e&&a(e,t),i[t]=!0,s&&s()}),s&&o.addEventListener("error",s)}}function o(e,t,s){return new Promise(i=>{n(e,t,i,s)})}},85:function(e,t,s){"use strict";var i=s(118),a=s(26),n=s(43),o=s(47),r=s(30),d=s(76),l=s(0),h=s(12),c=s(27),g=s(23),p=s(13),u=s(88),f=s(58),m=s(37),_=s(38),v=s(115),M=s(14),y=s(34);const I=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=>u.a.get(e))).then(e=>{if(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],this.pushInited){const e=!this.settings.nopush&&!this.settings.nodesktop&&g.default.isAvailable||!1;e!==(!1!==this.registeredDevice)&&(e?g.default.subscribe():g.default.unsubscribe())}g.default.setSettings(this.settings)}),M.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),p.default.addEventListener("instance_deactivated",()=>{this.stop()}),p.default.addEventListener("instance_activated",()=>{this.stopped&&this.start()}),p.default.addEventListener("idle",e=>{this.stopped||(e||this.clear(),this.toggleToggler())}),p.default.addMultipleEventsListeners({updateNotifySettings:e=>{this.savePeerSettings("notifyPeer"===e.peer._?_.a.getPeerId(e.peer.peer):e.peer._,e.notify_settings),p.default.dispatchEvent("notify_settings",e)}}),p.default.addEventListener("push_init",e=>{this.pushInited=!0,this.settings.nodesktop||this.settings.nopush?this.unregisterDevice(e):e?this.registerDevice(e):g.default.subscribe()}),p.default.addEventListener("push_subscribe",e=>{this.registerDevice(e)}),p.default.addEventListener("push_unsubscribe",e=>{this.unregisterDevice(e)}),p.default.addEventListener("dialogs_multiupdate",()=>{this.topMessagesDeferred.resolve()},{once:!0}),p.default.addEventListener("push_notification_click",e=>{if("push_settings"===e.action)return;if("mute1d"===e.action)return void c.a.invokeApi("account.updateDeviceLocked",{period:86400}).then(()=>{});const t=e.custom&&+e.custom.peerId;console.log("click",e,t),t&&this.topMessagesDeferred.then(()=>{e.custom.channel_id&&!m.a.hasChat(+e.custom.channel_id)||t>0&&!y.a.hasUser(t)||p.default.dispatchEvent("history_focus",{peerId:t,mid:+e.custom.msg_id})})})}toggleToggler(e=p.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=h.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,a=""+this.notificationsCount;this.notificationsCount<10?s=22:this.notificationsCount<100?s=20:(a="99+",s=16),s*=window.devicePixelRatio,t.font=`700 ${s}px ${i.a}`,t.textBaseline="middle",t.textAlign="center",t.fillStyle="white",t.fillText(a,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.b)(e._),s=this.peerSettings[t];return"inputNotifyPeer"===e._&&(t=_.a.getPeerId(e.peer),s=s[t]),s||((s||this.peerSettings)[t]=c.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 c.a.invokeApi("account.updateNotifySettings",{peer:e,settings:t}).then(s=>{s&&f.a.processLocalUpdate({_:"updateNotifySettings",peer:Object.assign(Object.assign({},e),{_:Object(d.b)(e._)}),notify_settings:Object.assign(Object.assign({},t),{_:"peerNotifySettings"})})})}getNotifyExceptions(){c.a.invokeApi("account.getNotifyExceptions",{compare_sound:!0}).then(e=>{f.a.processUpdateMessage(e)})}getContactSignUpNotification(){return this.notifyContactsSignUp?this.notifyContactsSignUp:this.notifyContactsSignUp=c.a.invokeApi("account.getContactSignUpNotification")}setContactSignUpNotification(e){c.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&&p.default.dispatchEvent("notify_peer_type_settings",{key:e,settings:t})}isMuted(e){return"peerNotifySettings"===e._&&(1e3*e.mute_until>Object(o.h)()||e.silent)}getPeerMuted(e){const t=this.getNotifySettings({_:"inputNotifyPeer",peer:_.a.getInputPeerById(e)});return(t instanceof Promise?t:Promise.resolve(t)).then(e=>this.isMuted(e))}getPeerLocalSettings(e,t=!0){const s={_:"peerNotifySettings"},i=this.peerSettings.notifyPeer[e];if(!i||i instanceof Promise||Object.assign(s,i),t){const t=_.a.getInputNotifyPeerById(e,!0),i=Object(d.b)(t._),a=this.peerSettings[i];if(a&&!(a instanceof Promise))for(let e in a)void 0===s[e]&&(s[e]=a[e])}return s}isPeerLocalMuted(e,t=!0){if(e===p.default.myId)return!1;const s=this.getPeerLocalSettings(e,t);return this.isMuted(s)}start(){if(this.updateLocalSettings(),p.default.addEventListener("settings_updated",this.updateLocalSettings),g.default.start(),!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(this.stopped)return;e.image||(e.image="assets/img/logo_filled_rounded.png"),this.notificationsCount++,this.titleInterval||this.toggleToggler();const t=Object(o.h)();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,i=e.key||"k"+s;let a;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)}a=new Notification(e.title,{icon:e.image||"",body:e.message||"",tag:e.tag||"",silent:e.silent||!1})}catch(e){return this.notificationsUiSupport=!1,void g.default.setLocalNotificationsDisabled()}a.onclick=()=>{a.close(),v.a.focus(),this.clear(),e.onclick&&e.onclick()},a.onclose=()=>{a.hidden||(delete this.notificationsShown[i],this.clear())},a.show&&a.show(),this.notificationsShown[i]=a,l.isMobile||setTimeout(()=>{this.hide(i)},8e3)}}testSound(e){const t=Object(o.h)();if(this.nextSoundAt&&t<this.nextSoundAt&&this.prevSoundVolume===e)return;this.nextSoundAt=t+1e3,this.prevSoundVolume=e;const s="assets/audio/notification.mp3",i=document.createElement("audio");i.autoplay=!0,i.setAttribute("mozaudiochannel","notification"),i.volume=e,i.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(i),i.addEventListener("ended",()=>{i.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,g.default.hidePushNotifications()}registerDevice(e){if(this.registeredDevice&&Object(r.b)(this.registeredDevice,e))return!1;c.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;c.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}};a.a.appNotificationsManager=I,t.a=I},86:function(e,t,s){"use strict";var i=s(13);t.a=(e,t,s,a,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(!i.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,a)}},91:function(e,t,s){"use strict";s.d(t,"a",(function(){return l}));var i=s(86),a=s(32),n=s(30),o=s(2),r=s(29),d=s(81);class l{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(o.a)(e),this.preloader.classList.contains("manual")?this.loadFunc&&this.loadFunc():this.promise&&this.promise.cancel&&this.promise.cancel()},e&&Object(n.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(r.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(),n=n=>{if(e.notify=null,t!==this.tempId)return;const o=Date.now()-s;if(!n&&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(a.c)(()=>{this.setManual()})):this.detach();this.promise=e=null};e.then(()=>n(null)).catch(e=>n(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(a.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(a.c)(()=>{this.detached&&this.preloader.parentElement&&Object(i.a)(this.preloader,"is-visible",!1,200,()=>{this.preloader.remove()})})}setProgress(e){if(Object(d.a)(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=""}}},95: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 h}));var i=s(32),a=s(0),n=function(e,t,s,i){return new(s||(s=Promise))((function(a,n){function o(e){try{d(i.next(e))}catch(e){n(e)}}function r(e){try{d(i.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,r)}d((i=i.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 i=document.createElement("video");i.volume=0,i.onloadedmetadata=()=>t(i),i.onerror=s,i.src=e})}(e);return Promise.race([Object(i.e)(2e3),o(t)])}))}function d(e){return new Promise(t=>{e.readyState>=e.HAVE_METADATA?t():e.addEventListener(a.isAppleMobile?"loadeddata":"canplay",()=>t(),{once:!0})})}function l(e,t=!1){return n(this,void 0,void 0,(function*(){const s=[],i=(e,a)=>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 i(e,a);e()})))})}else if(e)if(t)s.push(e.type);else{const t=a.getAsFile(),i=e instanceof File?e:e instanceof DataTransferItem?e.getAsFile():yield new Promise((s,i)=>e.file(s,e=>s(t)));if(!i)return;s.push(i)}}));if(e instanceof DragEvent&&e.dataTransfer.files&&!e.dataTransfer.items)for(let i=0;i<e.dataTransfer.files.length;i++){const a=e.dataTransfer.files[i];s.push(t?a.type:a)}else{const s=(e.dataTransfer||e.clipboardData||e.originalEvent.clipboardData).items,a=[];for(let e=0;e<s.length;++e){const n=s[e];if("file"===n.kind){const e=(t?n:n.webkitGetAsEntry())||n.getAsFile();a.push(i(e,n))}}yield Promise.all(a)}return s}))}function h(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 i=t.target.files[0];i?e(i):s("NO_FILE_SELECTED")},{once:!0})}).finally(()=>{t.remove()});return t.click(),s}}}]);
//# sourceMappingURL=6.ef3cabd15c6b19833f3d.chunk.js.map