1import{g as O}from"./load_locale-BmPY5_GJ.js";import"./client-By3tlFYA.js";import"./index-BuCZtZVa.js";import{g as _}from"./initial_state-G2-ajWaB.js";import{W as S}from"./index-CY8VJ9xB.js";import{aT as w,aU as E,aV as h,aW as G,aX as C,aY as J,aZ as W,a_ as N,a$ as P,b0 as j,b1 as x,b2 as A,b3 as H,b4 as D,b5 as F,b6 as R,b7 as U,b8 as V,b9 as Y}from"./useSelectableClick-B9dw2n2V.js";let p;const b=[],m={},I=e=>{b.push(e)},K=e=>{const t=b.indexOf(e);t!==-1&&b.splice(t,1)},T=({channelName:e,params:t,onConnect:n})=>{const s=y(e,t);m[s]=m[s]||0,m[s]===0&&p.send(JSON.stringify({type:"subscribe",stream:e,...t})),m[s]+=1,n()},v=({channelName:e,params:t,onDisconnect:n})=>{const s=y(e,t);m[s]=m[s]||1,m[s]===1&&p.readyState===S.OPEN&&p.send(JSON.stringify({type:"unsubscribe",stream:e,...t})),m[s]-=1,n()},Q={connected(){b.forEach(e=>T(e))},received(e){const{stream:t}=e;b.filter(({channelName:n,params:s})=>{const l=t[0];if(t.length===1)return n===l;const c=t[1];return["hashtag","hashtag:local"].includes(n)?n===l&&s.tag===c:n==="list"?n===l&&s.list===c:!1}).forEach(n=>{n.onReceive(e)})},disconnected(){b.forEach(e=>v(e))},reconnected(){}},y=(e,t)=>Object.keys(t).length===0?e:"".concat(e,"&").concat(Object.keys(t).map(n=>"".concat(n,"=").concat(t[n])).join("&")),X=(e,t,n)=>(s,l)=>{const c=l().getIn(["meta","streaming_api_base_url"]),o=_(),{onConnect:r,onReceive:f,onDisconnect:a}=n(s,l);if(!o)throw new Error("Trying to connect to the streaming server but no access token is available.");if(!c.startsWith("ws")){const i=$(c,o,y(e,t),{connected(){r()},received(g){f(g)},disconnected(){a()},reconnected(){r()}});return()=>{i.close()}}const u={channelName:e,params:t,onConnect:r,onReceive:f,onDisconnect:a};return I(u),p?p.readyState===S.OPEN&&T(u):p=$(c,o,"",Q),()=>{K(u),v(u)}},Z=["update","delete","notification","conversation","filters_changed","announcement","announcement.delete","announcement.reaction"],q=(e,t)=>{t({event:e.type,payload:e.data})},$=(e,t,n,{connected:s,received:l,disconnected:c,reconnected:o})=>{const r=n.split("&");if(n=r.shift(),e.startsWith("ws")){const a=new S("".concat(e,"/api/v1/streaming/?").concat(r.join("&")),t);return a.onopen=s,a.onmessage=u=>l(JSON.parse(u.data)),a.onclose=c,a.onreconnect=o,a}n=n.replace(/:/g,"/"),n.endsWith(":media")&&(n=n.replace("/media",""),r.push("only_media=true")),r.push("access_token=".concat(t));const f=new EventSource("".concat(e,"/api/v1/streaming/").concat(n,"?").concat(r.join("&")));return f.onopen=()=>{s()},Z.forEach(a=>{f.addEventListener(a,u=>q(u,l))}),f.onerror=c,f},k=e=>Math.floor(Math.random()*Math.floor(e)),d=(e,t,n={},s={})=>{const{messages:l}=O(),c=t.startsWith("public")||t.startsWith("hashtag");return X(t,n,(o,r)=>{const f=r().getIn(["meta","locale"]);let a;const u=async i=>{await i(o,r),a=setTimeout(()=>u(i),2e4+k(2e4))};return{onConnect(){o(A(e)),a&&(clearTimeout(a),a=null),s.fillGaps&&o(s.fillGaps())},onDisconnect(){o(x({timeline:e})),s.fallback&&(a=setTimeout(()=>u(s.fallback),k(4e4)))},onReceive(i){switch(i.event){case"update":o(j(e,JSON.parse(i.payload),{accept:s.accept,bogusQuotePolicy:c}));break;case"status.update":o(P(JSON.parse(i.payload),{bogusQuotePolicy:c}));break;case"delete":o(N(i.payload));break;case"notification":{const g=JSON.parse(i.payload);o(J(g,l,f)),o(W(g));break}case"notifications_merged":{o(C());break}case"conversation":o(G(JSON.parse(i.payload)));break;case"announcement":o(h(JSON.parse(i.payload)));break;case"announcement.reaction":o(E(JSON.parse(i.payload)));break;case"announcement.delete":o(w(i.payload));break}}}})};async function z(e){await e(U({maxId:void 0}));try{await e(V())}catch(t){}await e(Y())}const se=()=>d("home","user",{},{fallback:z,fillGaps:H}),oe=({onlyMedia:e}={})=>d("community".concat(e?":media":""),"public:local".concat(e?":media":""),{},{fillGaps:()=>D({onlyMedia:e})}),ae=({onlyMedia:e,onlyRemote:t,allowLocalOnly:n}={})=>d("public".concat(t?":remote":n?":allow_local_only":"").concat(e?":media":""),"public".concat(t?":remote":n?":allow_local_only":"").concat(e?":media":""),{},{fillGaps:()=>F({onlyMedia:e,onlyRemote:t,allowLocalOnly:n})}),ie=(e,t,n,s)=>d("hashtag:".concat(e).concat(n?":local":""),"hashtag".concat(n?":local":""),{tag:t},{accept:s}),ce=()=>d("direct","direct"),re=e=>d("list:".concat(e),"list",{list:e},{fillGaps:()=>R(e)});export{oe as a,re as b,ae as c,ie as d,ce as e,se as f}; 2//# sourceMappingURL=streaming-CqjqvGGL.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.