1import{o as e,t}from"./rolldown-runtime-C0FnF6B9.js";import{y as n}from"./initial_state-mp0kpN1Y.js";import{r}from"./locales-DvmEsU7g.js";import{$r as i,Fr as a,Nr as o,Oi as s,Pr as c,Zr as l,ai as u,ii as d,ki as f,ti as p}from"./store-hlPJ4NAh.js";import{A as m,An as h,In as g,Ln as _,Mn as v,On as y,_n as b,jn as x,kn as S,vn as C,wn as w}from"./filters-D7o2XUo9.js";var T=t((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createBackoff=n;var t={exponential:function(e,t){return Math.floor(Math.random()*2**e*t)},fibonacci:function(e,t){var n=1;if(e>n)for(var r=1,n=2,i=2;i<e;i++){var a=r+n;r=n,n=a}return Math.floor(Math.random()*n*t)}};function n(e,n){return new r(t[e],n)}function r(e,t){this.func=e,this.attempts=0,this.delay=t.initialDelay===void 0?100:t.initialDelay}r.prototype.backoff=function(){setTimeout(this.onReady,this.func(++this.attempts,this.delay))}})),E=t(((e,t)=>{t.exports={}})),D=e(t((e=>{Object.defineProperty(e,"__esModule",{value:!0});var t=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();function n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}var r=T().createBackoff,i=typeof WebSocket<`u`?WebSocket:E(),a=function(){function e(t,i){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};n(this,e),this.url=t,this.protocols=i,this.reconnectEnabled=!0,this.listeners={},this.backoff=r(a.backoff||`exponential`,a),this.backoff.onReady=this.onBackoffReady.bind(this),(a.connect===void 0||a.connect)&&this.open()}return t(e,[{key:`open`,value:function(){var e=arguments.length>0&&arguments[0]!==void 0&&arguments[0];this.isReconnect=e;var t=this.ws&&this.ws.binaryType;this.ws=new i(this.url,this.protocols),this.ws.onclose=this.onCloseCallback.bind(this),this.ws.onerror=this.onErrorCallback.bind(this),this.ws.onmessage=this.onMessageCallback.bind(this),this.ws.onopen=this.onOpenCallback.bind(this),t&&(this.ws.binaryType=t)}
1},{key:`onBackoffReady`,value:function(e,t){this.open(!0)}},{key:`onCloseCallback`,value:function(e){!this.isReconnect&&this.listeners.onclose&&this.listeners.onclose.apply(null,arguments),this.reconnectEnabled&&e.code<3e3&&this.backoff.backoff()}},{key:`onErrorCallback`,value:function(){this.listeners.onerror&&this.listeners.onerror.apply(null,arguments)}},{key:`onMessageCallback`,value:function(){this.listeners.onmessage&&this.listeners.onmessage.apply(null,arguments)}},{key:`onOpenCallback`,value:function(){this.listeners.onopen&&this.listeners.onopen.apply(null,arguments),this.isReconnect&&this.listeners.onreconnect&&this.listeners.onreconnect.apply(null,arguments),this.isReconnect=!1}},{key:`close`,value:function(e,t){e===void 0&&(e=1e3),this.reconnectEnabled=!1,this.ws.close(e,t)}},{key:`send`,value:function(e){this.ws.send(e)}},{key:`bufferedAmount`,get:function(){return this.ws.bufferedAmount}},{key:`readyState`,get:function(){return this.ws.readyState}},{key:`binaryType`,get:function(){return this.ws.binaryType},set:function(e){this.ws.binaryType=e}},{key:`extensions`,get:function(){return this.ws.extensions},set:function(e){this.ws.extensions=e}},{key:`protocol`,get:function(){return this.ws.protocol},set:function(e){this.ws.protocol=e}},{key:`onclose`,set:function(e){this.listeners.onclose=e},get:function(){return this.listeners.onclose}},{key:`onerror`,set:function(e){this.listeners.onerror=e},get:function(){return this.listeners.onerror}},{key:`onmessage`,set:function(e){this.listeners.onmessage=e},get:function(){return this.listeners.onmessage}},{key:`onopen`,set:function(e){this.listeners.onopen=e},get:function(){return this.listeners.onopen}},{key:`onreconnect`,set:function(e){this.listeners.onreconnect=e},get:function(){return this.listeners.onreconnect}}]),e}();a.CONNECTING=i.CONNECTING,a.OPEN=i.OPEN,a.CLOSING=i.CLOSING,a.CLOSED=i.CLOSED,e.default=a}))()),O,k=[],A={},j=e=>{k.push(e)},M=e=>{let t=k.indexOf(e);t!==-1&&k.splice(t,1)},N=({channelName:e,params:t,onConnect:n})=>{let r=I(e,t);A[r]=A[r]||0,A[r]===0&&O.send(JSON.stringify({type:`subscribe`,stream:e,...t})),A[r]+=1,n()},P=({channelName:e,params:t,onDisconnect:n})=>{let r=I(e,t);A[r]=A[r]||1,A[r]===1&&O.readyState===D.default.OPEN&&O.send(JSON.stringify({type:`unsubscribe`,stream:e,...t})),--A[r],n()},F={connected(){k.forEach(e=>N(e))},received(e){let{stream:t}=e;k.filter(({channelName:e,params:n})=>{let r=t[0];if(t.length===1)return e===r;let i=t[1];return[`hashtag`,`hashtag:local`].includes(e)?e===r&&n.tag===i:e===`list`?e===r&&n.list===i:e===`antenna`&&e===r&&n.antenna===i}).forEach(t=>{t.onReceive(e)})},disconnected(){k.forEach(e=>P(e))},reconnected(){}},I=(e,t)=>Object.keys(t).length===0?e:`${e}&${Object.keys(t).map(e=>`${e}=${t[e]}`).join(`&`)}`,L=(e,t,r)=>(i,a)=>{let o=a().getIn([`meta`,`streaming_api_base_url`]),s=n(),{onConnect:c,onReceive:l,onDisconnect:u}=r(i,a);if(!s)throw Error(`Trying to connect to the streaming server but no access token is available.`);if(!o.startsWith(`ws`)){let n=B(o,s,I(e,t),{connected(){c()},received(e){l(e)},disconnected(){u()},reconnected(){c()}});return()=>{n.close()}}let d={channelName:e,params:t,onConnect:c,onReceive:l,onDisconnect:u};return j(d),O?O.readyState===D.default.OPEN&&N(d):O=B(o,s,``,F),()=>{M(d),P(d)}},R=[`update`,`delete`,`notification`,`conversation`,`filters_changed`,`announcement`,`announcement.delete`,`announcement.reaction`],z=(e,t)=>{t({event:e.type,payload:e.data})},B=(e,t,n,{connected:r,received:i,disconnected:a,reconnected:o})=>{let s=n.split(`&`);if(n=s.shift(),e.startsWith(`ws`)){let n=new D.default(`${e}/api/v1/streaming/?${s.join(`&`)}`,t);return n.onopen=r,n.onmessage=e=>i(JSON.parse(e.data)),n.onclose=a,n.onreconnect=o,n}n=n.replace(/:/g,`/`),n.endsWith(`:media`)&&(n=n.replace(`/media`,``),s.push(`only_media=true`)),s.push(`access_token=${t}`);let c=new EventSource(`${e}/api/v1/streaming/${n}?${s.join(`&`)}`);return c.onopen=()=>{r()},R.forEach(e=>{c.addEventListener(e,e=>z(e,i))}),c.onerror=a,c},V=e=>Math.floor(Math.random()*Math.floor(e)),H=(e,t,n={},o={})=>{let{messages:p}=r(),h=t.startsWith(`public`)||t.startsWith(`hashtag`);return L(t,n,(t,n)=>{let r=n().getIn([`meta`,`locale`]),v,y=async e=>{await e(t,n),v=setTimeout(()=>y(e),2e4+V(2e4))};return{onConnect(){t(b(e)),v&&=(clearTimeout(v),null),o.fillGaps&&t(o.fillGaps())},onDisconnect(){t(_({timeline:e})),o.fallback&&(v=setTimeout(()=>y(o.fallback),V(4e4)))},onReceive(n){switch(n.event){case`update`:t(g(e,JSON.parse(n.payload),{accept:o.accept,bogusQuotePolicy:h}));break;case`status.update`:t(m(JSON.parse(n.payload),{bogusQuotePolicy:h}));break;case`delete`:t(C(n.payload));break;case`notification`:{let e=JSON.parse(n.payload);t(f(e,p,r)),t(c(e));break}case`emoji_reaction`:t(s(JSON.parse(n.payload)));break;case`notifications_merged`:t(a());break;case`conversation`:t(l(JSON.parse(n.payload)));break;case`announcement`:t(d(JSON.parse(n.payload)));break;case`announcement.reaction`:t(u(JSON.parse(n.payload)));break;case`announcement.delete`:t(i(n.payload))}}}})};async function U(e){await e(w({maxId:void 0}));try{await e(o())}catch{}await e(p())}var W=()=>H(`home`,`user`,{},{fallback:U,fillGaps:h}),G=({onlyMedia:e}={})=>H(`community${e?`:media`:``}`,`public:local${e?`:media`:``}`,{},{fillGaps:()=>S({onlyMedia:e})}),K=({onlyMedia:e,onlyRemote:t}={})=>H(`public${t?`:remote`:``}${e?`:media`:``}`,`public${t?`:remote`:``}${e?`:media`:``}`,{},{fillGaps:()=>v({onlyMedia:e,onlyRemote:t})}),q=(e,t,n,r)=>H(`hashtag:${e}${n?`:local`:``}`,`hashtag${n?`:local`:``}`,{tag:t},{accept:r}),J=()=>H(`direct`,`direct`),Y=e=>H(`list:${e}`,`list`,{list:e},{fillGaps:()=>x(e)}),X=e=>H(`antenna:${e}`,`antenna`,{antenna:e},{fillGaps:()=>y(e)});export{Y as a,q as i,G as n,K as o,J as r,W as s,X as t}; 2//# sourceMappingURL=streaming-BvORLIky.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.