(()=>{"use strict";const e="account",t="tt-media-progressive",n="tt-assets",s=("undefined"!=typeof window&&window.innerHeight,Math.round(450),new Set(["newMessage","newScheduledMessage","deleteMessages","deleteScheduledMessages","deleteHistory","deleteParticipantHistory"]),new Set(["svg","svgz"]),new Set(["image/png","image/jpeg","image/gif"])),a=new Set(["video/mp4","video/quicktime"]);new Set(["audio/mp3","audio/ogg","audio/wav","audio/mpeg","audio/flac","audio/aac","audio/m4a","audio/mp4","audio/x-m4a"]),new Set([...s,...a]),new Set(["USERNAME_PURCHASE_AVAILABLE","USERNAME_INVALID"]),new Set(["t.me","web.t.me","a.t.me","k.t.me","z.t.me"]),new Set(["AU","BD","CA","CO","EG","HN","IE","IN","JO","MX","MY","NI","NZ","PH","PK","SA","SV","US"]),(-(10n**12n)-777n).toString(),new Set(["USER_CANCELED"]);const i=e=>new Promise(t=>{setTimeout(()=>t(),e)});async function o(e){const t=await r(async()=>{const t=await self.caches.open(n),s=await t.match(e.request);return{cache:t,cached:s}},3e3),{cache:s,cached:a}=t||{};if(s&&a){if(a.ok)return a;await s.delete(e.request)}const i=await fetch(e.request);return i.ok&&s&&s.put(e.request,i.clone()),i}async function r(e,t){let n=!1;try{return await Promise.race([i(t).then(()=>n?void 0:Promise.reject(new Error("TIMEOUT"))),e()])}catch(e){return void console.error(e)}finally{n=!0}}"function"==typeof SuppressedError&&SuppressedError;new WeakMap,new WeakMap,new WeakMap,new WeakMap,new WeakMap;const c="SharedWorker"in globalThis;Intl,new URL("tg://host").host,(globalThis||window).isTauri,Boolean(globalThis.electron);const l="undefined"!=typeof WorkerGlobalScope&&globalThis.self instanceof WorkerGlobalScope?globalThis.self.name:void 0;function u(t){const n=new URL(t).searchParams.get(e),s=n?Number(n):1;if(s&&!Number.isNaN(s)&&1!==s)return s}if((l?Number(new URLSearchParams(l).get(e)):void 0)||c&&u(globalThis.location.href),"object"==typeof window){const e=new BroadcastChannel("tt-version");e.postMessage({version:"1.0.0"}),e.addEventListener("message",t=>{const{version:n}=t.data;n&&(-1===d("1.0.0",n)&&window.location.reload(),1===d("1.0.0",n)&&e.postMessage({version:"1.0.0"}))})}function d(e,t){return e.startsWith(`${t}-`)?-1:t.startsWith(`${e}-`)?1:e.localeCompare(t,void 0,{numeric:!0,sensitivity:"case",caseFirst:"upper"})}const f=524288,p=new Map;async function h(e,t){const n=t.url.includes("/download/"),s=await(n?async function(e){const t=u(e);return(await self.clients.matchAll()).find(e=>"window"===e.type&&"top-level"===e.frameType&&u(e.url)===t)}(t.url):self.clients.get(e.clientId));if(!s)return;const a=Date.now().toString(36)+Math.random().toString(36).slice(2),o={};let r=!1;const c=Promise.race([i(6e4).then(()=>r?void 0:Promise.reject(new Error("ERROR_PART_TIMEOUT"))),new Promise((e,t)=>{Object.assign(o,{resolve:e,reject:t})})]);return p.set(a,o),c.catch(()=>{}).finally(()=>{p.delete(a),r=!0}),s.postMessage({type:"requestPart",messageId:a,params:t}),c}self.addEventListener("message",e=>{const{type:t,messageId:n,result:s}=e.data;if("partResponse"===t){const e=p.get(n);e&&e.resolve(s)}});const w=1048576;class g{constructor(){this.queue=[]}push(e){this.queue.push(e)}async pop(){return await this.queue.shift()}get size(){return this.queue.length}}var m=function(e){return e.True="1",e.False="0",e}(m||{});let y=(new Date).valueOf();const v=new Set,S={};function R(e){return e.custom.from_id?e.custom.from_id:e.custom.chat_id||e.custom.channel_id?`-${e.custom.chat_id||e.custom.channel_id}`:void 0}function b(e){if(e.custom.msg_id)return parseInt(e.custom.msg_id,10)}async function M(){const e=new URL(self.registration.scope).origin;return(await self.clients.matchAll({type:"window"})).filter(t=>new URL(t.url).origin===e)}async function I(e){const t=(await M())[0];t&&t.postMessage({type:"playNotificationSound",payload:{id:e}})}function E({chatId:e,messageId:t,body:n,title:s,icon:a,reaction:i,isSilent:o,shouldReplaceHistory:r}){const c=(new Date).valueOf()-y<1e3,l={body:n,data:{chatId:e,messageId:t,reaction:i,count:1,shouldReplaceHistory:r},icon:a||"icon-192x192.png",badge:"icon-192x192.png",tag:String(c?0:e||0),vibrate:[200,100,200]};return Promise.all([i||o?void 0:I(String(t)||e||""),self.registration.showNotification(s,l)])}async function T(e,t){if(t.chatId&&(e.postMessage({type:"focusMessage",payload:t}),!e.focused))try{await e.focus()}catch(e){}}self.addEventListener("sync",()=>{y=Date.now()});class P{constructor(){this.promise=new Promise((e,t)=>{this.reject=t,this.resolve=e})}static resolved(e){const t=new P;return t.resolve(e),t}}const A=new Map;const U=/\.(wasm|html)$/,L=/[\da-f]{20}.*\.(js|css|woff2?|svg|png|jpg|jpeg|tgs|json|wasm)$/;self.addEventListener("install",e=>{e.waitUntil(self.skipWaiting())}),self.addEventListener("activate",e=>{e.waitUntil(Promise.race([i(3e3),Promise.all([self.caches.delete(n),self.clients.claim()])]))}),self.addEventListener("fetch",e=>{const{url:s}=e.request,{scope:a}=self.registration;if(!s.startsWith(a))return!1;const{pathname:i,protocol:c}=new URL(s),{pathname:l}=new URL(a);if(i.includes("/progressive/"))return e.respondWith(async function(e){const{url:n}=e.request,s=u(n),a=e.request.headers.get("range"),i=/^bytes=(\d+)-(\d+)?$/g.exec(a||""),o=Number(i[1]);let r=Number(i[2]);(!r||r-o+1>f)&&(r=o+f-1);const c=new URL(n);if(0===o&&1===r){const e=c.searchParams.get("fileSize"),t=e&&Number(e),n=c.searchParams.get("mimeType");if(t&&n)return new Response(new Uint8Array(2).buffer,{status:206,statusText:"Partial Content",headers:[["Content-Range",`bytes 0-1/${t}`],["Accept-Ranges","bytes"],["Content-Length","2"],["Content-Type",n]]})}c.searchParams.set("start",String(o)),c.searchParams.set("end",String(r));const l=c.href,[d,p]=await async function(e,n){const s=e?`${t}_${e}`:t,a=await self.caches.open(s);return Promise.all([a.match(`${n}&type=arrayBuffer`).then(e=>e?e.arrayBuffer():void 0),a.match(`${n}&type=headers`).then(e=>e?e.json():void 0)])}(s,l);if(d)return new Response(d,{status:206,statusText:"Partial Content",headers:p});let w;try{w=await h(e,{url:n,start:o,end:r})}catch(e){}if(!w)return new Response("",{status:500,statusText:"Failed to fetch progressive part"});const{arrayBuffer:g,fullSize:m,mimeType:y}=w,v=Math.min(r-o+1,g.byteLength);r=o+v-1;const S=g.slice(0,v),R=[["Content-Range",`bytes ${o}-${r}/${m}`],["Accept-Ranges","bytes"],["Content-Length",String(v)],["Content-Type",y]];return v<=524288&&r<2097151&&async function(e,n,s,a){const i=e?`${t}_${e}`:t,o=await self.caches.open(i);Promise.all([o.put(new Request(`${n}&type=arrayBuffer`),new Response(s)),o.put(new Request(`${n}&type=headers`),new Response(JSON.stringify(a)))])}(s,l,S,R),new Response(S,{status:206,statusText:"Partial Content",headers:R})}(e)),!0;if(i.includes("/download/"))return e.respondWith(async function(e){const{url:t}=e.request;let n;try{n=await h(e,{url:t,start:0,end:65536})}catch(e){}if(!n)return new Response("",{status:500,statusText:"Failed to fetch file to download"});const s=function(e){if(!e)return;const t=Array.from(e).filter(e=>{const t=e.charCodeAt(0);return t>=32&&127!==t}).join("");return t?`filename*=UTF-8''${encodeURIComponent(t).replaceAll("'","%27").replaceAll("(","%28").replaceAll(")","%29").replaceAll("*","%2A")}`:void 0}(new URL(t).searchParams.get("filename")||void 0),{fullSize:a,mimeType:i}=n,o=[["Content-Length",String(a)],["Content-Type",i],["Content-Disposition","attachment"+(s?`; ${s}`:"")]],r=new g,c=n=>(r.push(h(e,{url:t,start:n,end:n+w-1}).then(e=>e?.arrayBuffer)),n+w);let l=0;const u=new ReadableStream({start(){for(let e=0;e<8&&!(l>=a);e++)l=c(l)},async pull(e){const t=await r.pop();t?(e.enqueue(new Uint8Array(t)),t.byteLengthfetch(e.request),3e3);if(!t?.ok)return o(e);const s=t.clone();return self.caches.open(n).then(t=>t?.put(e.request,s)),t}(e)),!0;if(i.match(L))return e.respondWith(o(e)),!0}return!1}),self.addEventListener("push",function(e){const t=function(e){try{return e.data.json()}catch(e){return}}(e);if(!t||t.mute===m.True)return;const n=function(e){let t=e.title||"Montana Messenger";const n=e.custom?.silent===m.True;return n&&(t+=" 🔕"),{chatId:R(e),messageId:b(e),body:e.description,isSilent:n,title:t}}(t);v.has(n.messageId)?v.delete(n.messageId):e.waitUntil(E(n))}),self.addEventListener("notificationclick",function(e){const t=self.registration.scope;e.notification.close();const{data:n}=e.notification;e.waitUntil((async()=>{const e=await M();if(await Promise.all(e.map(e=>(S[e.id]=n,T(e,n)))),self.clients.openWindow&&!(e.length>0)){S[0]=n;try{const e=await self.clients.openWindow(t);e&&(S[e.id]=n)}catch(e){}}})())}),self.addEventListener("message",e=>{(function(e){if(!e.data)return;const t=e.source;if("clientReady"===e.data.type){const n=S[t.id]||S[0];n&&(delete S[t.id],delete S[0],e.waitUntil(T(t,n)))}if("showMessageNotification"===e.data.type){const t=e.data.payload;e.waitUntil((async()=>(t.chatId&&(await self.registration.getNotifications({tag:t.chatId})).forEach(e=>e.close()),v.add(t.messageId),E(t)))())}"closeMessageNotifications"===e.data.type&&e.waitUntil(async function({chatId:e,lastReadInboxMessageId:t}){const n=await self.registration.getNotifications(),s=t||Number.MAX_VALUE;n.forEach(t=>{("0"===t.tag||t.data.chatId===e&&t.data.messageId<=s)&&t.close()})}(e.data.payload))})(e),function(e){const{source:t,data:n}=e;if(t&&"clientReady"===n.type){const{id:e}=t,n=A.get(e);n?n.resolve():A.set(e,P.resolved())}}(e)})})(); //# sourceMappingURL=234.f255bcdf884280d7dc10.js.map