1import{o as e,t}from"./rolldown-runtime-C0FnF6B9.js";import{d as n}from"./initial_state-DnZ5UeDQ.js";import{r}from"./locales-Dt-Oha2Q.js";import{Gn as i,Ln as a,Vn as o,Wn as s,bn as c,tr as l,xn as u,yn as d,zn as f}from"./store-BKpYtGn4.js";import{Dn as p,En as m,Sn as h,bn as g,hn as _,k as v,ln as y,un as b,xn as x,yn as S}from"./filters-Br4s8K7f.js";var C=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))}})),w=t(((e,t)=>{t.exports={}})),T=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=C().createBackoff,i=typeof WebSocket<`u`?WebSocket:w(),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}))()),E,D=[],O={},k=e=>{D.push(e)},A=e=>{let t=D.indexOf(e);t!==-1&&D.splice(t,1)},j=({channelName:e,params:t,onConnect:n})=>{let r=P(e,t);O[r]=O[r]||0,O[r]===0&&E.send(JSON.stringify({type:`subscribe`,stream:e,...t})),O[r]+=1,n()},M=({channelName:e,params:t,onDisconnect:n})=>{let r=P(e,t);O[r]=O[r]||1,O[r]===1&&E.readyState===T.default.OPEN&&E.send(JSON.stringify({type:`unsubscribe`,stream:e,...t})),--O[r],n()},N={connected(){D.forEach(e=>j(e))},received(e){let{stream:t}=e;D.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}).forEach(t=>{t.onReceive(e)})},disconnected(){D.forEach(e=>M(e))},reconnected(){}},P=(e,t)=>Object.keys(t).length===0?e:`${e}&${Object.keys(t).map(e=>`${e}=${t[e]}`).join(`&`)}`,F=(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=R(o,s,P(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 k(d),E?E.readyState===T.default.OPEN&&j(d):E=R(o,s,``,N),()=>{A(d),M(d)}},I=[`update`,`delete`,`notification`,`conversation`,`filters_changed`,`announcement`,`announcement.delete`,`announcement.reaction`],L=(e,t)=>{t({event:e.type,payload:e.data})},R=(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 T.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()},I.forEach(e=>{c.addEventListener(e,e=>L(e,i))}),c.onerror=a,c},z=e=>Math.floor(Math.random()*Math.floor(e)),B=(e,t,n={},o={})=>{let{messages:d}=r(),h=t.startsWith(`public`)||t.startsWith(`hashtag`);return F(t,n,(t,n)=>{let r=n().getIn([`meta`,`locale`]),g,_=async e=>{await e(t,n),g=setTimeout(()=>_(e),2e4+z(2e4))};return{onConnect(){t(y(e)),g&&=(clearTimeout(g),null),o.fillGaps&&t(o.fillGaps())},onDisconnect(){t(p({timeline:e})),o.fallback&&(g=setTimeout(()=>_(o.fallback),z(4e4)))},onReceive(n){switch(n.event){case`update`:t(m(e,JSON.parse(n.payload),{accept:o.accept,bogusQuotePolicy:h}));break;case`status.update`:t(v(JSON.parse(n.payload),{bogusQuotePolicy:h}));break;case`delete`:t(b(n.payload));break;case`notification`:{let e=JSON.parse(n.payload);t(l(e,d,r)),t(c(e));break}case`notifications_merged`:t(u());break;case`conversation`:t(a(JSON.parse(n.payload)));break;case`announcement`:t(s(JSON.parse(n.payload)));break;case`announcement.reaction`:t(i(JSON.parse(n.payload)));break;case`announcement.delete`:t(f(n.payload))}}}})};async function V(e){await e(_({maxId:void 0}));try{await e(d())}catch{}await e(o())}var H=()=>B(`home`,`user`,{},{fallback:V,fillGaps:g}),U=({onlyMedia:e}={})=>B(`community${e?`:media`:``}`,`public:local${e?`:media`:``}`,{},{fillGaps:()=>S({onlyMedia:e})}),W=({onlyMedia:e,onlyRemote:t}={})=>B(`public${t?`:remote`:``}${e?`:media`:``}`,`public${t?`:remote`:``}${e?`:media`:``}`,{},{fillGaps:()=>h({onlyMedia:e,onlyRemote:t})}),G=(e,t,n,r)=>B(`hashtag:${e}${n?`:local`:``}`,`hashtag${n?`:local`:``}`,{tag:t},{accept:r}),K=()=>B(`direct`,`direct`),q=e=>B(`list:${e}`,`list`,{list:e},{fillGaps:()=>x(e)});export{W as a,q as i,K as n,H as o,G as r,U as t}; 2//# sourceMappingURL=streaming-B3iM9nSs.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.