1;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="10bcaa6b-a0a9-6da9-5750-07615833c575")}catch(e){}}(); 2(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,497625,e=>{"use strict";var t=e.i(478902),s="_1yo5rlx2";let i=()=>(0,t.jsxs)("div",{className:"_1yo5rlx1","aria-hidden":"true",children:[(0,t.jsx)("span",{className:s}),(0,t.jsx)("span",{className:`${s} _1yo5rlx3`}),(0,t.jsx)("span",{className:`${s} _1yo5rlx4`})]});e.s(["CommentsLoading",0,()=>(0,t.jsx)("div",{className:"_1yo5rlx5",role:"status","aria-label":"Loading comments",children:(0,t.jsx)(i,{})})],497625)},221381,427920,e=>{"use strict";var t=e.i(478902),s=e.i(389959),i=e.i(563281),r=e.i(197649),o=e.i(662983);let n=e=>{let{className:i,fullWidth:n,children:a,disabled:l,afterWrapper:d=(0,t.jsx)(o.default,{}),...c}=e,{onFocus:u,onBlur:h,keyboardFocus:p}=(({onFocus:e,onBlur:t,mouseDownThresholdMs:i=750}={})=>{let[r,o]=s.default.useState(!1),n=s.default.useRef(0);return s.default.useEffect(()=>{let e=()=>{n.current=Date.now()};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]),{onFocus:s.default.useCallback(t=>{e?.(t),Date.now()-n.current>i&&o(!0)},[e,i]),onBlur:s.default.useCallback(e=>{t?.(e),o(!1)},[t]),keyboardFocus:r}})(),y=(0,r.default)("zrsklt0",i,{zrsklt6:n}),m=(0,r.default)("zrsklt5","zrsklt2","zrsklt4",p&&"zrsklt3"),f=(0,r.default)("zrsklt1",{zrsklt7:l});return(0,t.jsxs)("span",{className:y,children:[(0,t.jsx)("select",{className:(0,r.default)(m,"coral-selectField"),disabled:l,onFocus:u,onBlur:h,...c,children:a}),(0,t.jsx)("span",{className:f,"aria-hidden":!0,children:d})]})},a=e=>(0,t.jsx)("option",{...e});var l=e.i(210982),d=e.i(798240),c=e.i(396902),u=e.i(623690),h=e.i(465149),p=e.i(385799),y=e.i(593296),m=e.i(722010);e.s(["RepliesSortSelect",0,function(e){let{className:r}=e,{cycloneConfig:{serverURL:o}}=(0,c.useConfigContext)(),{repliesStore:f}=(0,y.useStore)(),{viewer:b}=(0,u.useCyclone)(),g=(0,l.useAnalytics)(),{context:{location:S}}=(0,h.useContentLocationContext)(),{cycloneCommunityId:v}=(0,d.useCurrentCycloneCommunity)();(0,s.useEffect)(()=>{if(b&&b.settings?.replySort)try{let e=b.settings.replySort;f.setSort(e)}catch(e){console.warn("unable to load/parse user replySort preferences",e)}},[f,b?.settings?.replySort]);let k=(0,s.useCallback)(e=>{let t=!f.topLevelSocketPermitted,s=e===m.ReplySort.NewestFirst||e===m.ReplySort.OldestFirst;f.setSort(e),t&&s&&f.insertAllWebsocketReplies(),S===h.ContentLocation.ArticleBody&&g?.emit({event:"coral_comment",coral_comment:{action:"set_sort_order"}}),b&&(0,p.updateUserSettings)(v,b.id,{replySort:e},o,b.token)},[g,v,S,f,o,b]);return S===h.ContentLocation.ArticleBody?(0,t.jsxs)(n,{className:r,value:f.currentSort,onChange:e=>k(e.target.value),children:[(0,t.jsx)(a,{value:m.ReplySort.NewestFirst,children:"Newest"}),(0,t.jsx)(a,{value:m.ReplySort.OldestFirst,children:"Oldest"}),(0,t.jsx)(a,{value:m.ReplySort.MostReplies,children:"Most replies"}),(0,t.jsx)(a,{value:m.ReplySort.MostRecs,children:"Most Rec'd"})]}):(0,t.jsx)(i.Select,{className:r,value:f.currentSort,onChange:e=>k(e.value),options:[{value:m.ReplySort.NewestFirst,display:"Newest first"},{value:m.ReplySort.OldestFirst,display:"Oldest first"},{value:m.ReplySort.MostRecs,display:"Most recs"},{value:m.ReplySort.MostReplies,display:"Most replies"}]})}],221381);var f=e.i(467272),b=e.i(497625);let g=(0,f.default)(()=>e.A(451891),{loadableGenerated:{modules:[19951]},ssr:!1,loading:()=>(0,t.jsx)(b.CommentsLoading,{})});e.s(["default",0,({virtuosoRef:e})=>(0,t.jsx)(g,{virtuosoRef:e})],427920)},563281,e=>{"use strict";var t=e.i(478902),s=e.i(262653),i=e.i(197649),r=e.i(389959);e.i(807738);var o=e.i(738886),n=e.i(662983),a=e.i(970060);e.s(["Select",0,e=>{let{options:l,onChange:d,className:c}=e,[u,h]=(0,r.useState)(e.value),p=(0,r.useRef)(null),y=(0,r.useRef)(null),[m,f]=(0,r.useState)(!1),b=(0,r.useCallback)(e=>{h(e.value),p.current?.click(),d&&d(e)},[d,h]);(0,r.useEffect)(()=>{h(e.value)},[e.value,d,l]),(0,r.useEffect)(()=>{let e=y.current;if(!e)return;let t=()=>{f(e.hasAttribute("data-popup-open"))},s=new MutationObserver(t);return s.observe(e,{attributes:!0,attributeFilter:["data-popup-open"]}),t(),()=>{s.disconnect()}},[y]);let g=(0,r.useMemo)(()=>{for(let e of l)if(e.value===u)return e.display;return""},[l,u]);return(0,t.jsx)("div",{className:(0,i.default)("_1385n2o0",c),children:(0,t.jsxs)(s.Popover.Root,{children:[(0,t.jsx)(s.Popover.Trigger,{onClick:e=>{e.stopPropagation()},ref:y,children:(0,t.jsxs)("div",{className:"_1385n2o1",children:[(0,t.jsx)("span",{className:"_1385n2o2",children:g}),(0,t.jsx)(n.default,{height:12,width:12,className:(0,i.default)("_1385n2o5",m&&"_1385n2o6")})]})}),(0,t.jsx)(s.Popover.Portal,{children:(0,t.jsx)(s.Popover.Positioner,{sideOffset:8,className:"_1385n2oa",children:(0,t.jsx)(s.Popover.Popup,{className:"_1385n2o9",children:(0,t.jsx)("div",{className:"_1385n2o4",children:l.map(e=>(0,t.jsx)(o.default,{className:(0,i.default)("_1385n2o3",u===e.value&&"_1385n2o7"),text:e.display,displayType:"cycloneSecondary",onClick:()=>b(e)},e.value))})})})}),(0,t.jsx)(s.Popover.Close,{children:(0,t.jsx)("div",{ref:p,className:a.sharedStyles.layout.hide})})]})})}],563281)},225803,e=>{"use strict";var t=e.i(389959);e.s(["useCycloneThreadLoad",0,function({rootStore:e,load:s,authPending:i,viewerToken:r}){let o=(0,t.useRef)(null),n=(0,t.useRef)(void 0);(0,t.useEffect)(()=>{i||o.current===e||(o.current=e,r&&(e.setToken(r),n.current=r),s())},[i,s,e,r]),(0,t.useEffect)(()=>{r&&n.current!==r&&(e.setToken(r),n.current=r)},[e,r])},"useRunWhenAuthSettles",0,function(e,s,i){let r=(0,t.useRef)(null);(0,t.useEffect)(()=>{e||r.current===i||(r.current=i,s())},[e,s,i])}])}
2,844441,(e,t,s)=>{"use strict";Object.defineProperty(s,"__esModule",{value:!0}),Object.defineProperty(s,"LoadableContext",{enumerable:!0,get:function(){return i}});let i=e.r(2879)._(e.r(389959)).default.createContext(null)},612666,(e,t,s)=>{"use strict";Object.defineProperty(s,"__esModule",{value:!0}),Object.defineProperty(s,"default",{enumerable:!0,get:function(){return h}});let i=e.r(2879)._(e.r(389959)),r=e.r(844441),o=[],n=[],a=!1;function l(e){let t=e(),s={loading:!0,loaded:null,error:null};return s.promise=t.then(e=>(s.loading=!1,s.loaded=e,e)).catch(e=>{throw s.loading=!1,s.error=e,e}),s}class d{constructor(e,t){this._loadFn=e,this._opts=t,this._callbacks=new Set,this._delay=null,this._timeout=null,this.retry()}promise(){return this._res.promise}retry(){this._clearTimeouts(),this._res=this._loadFn(this._opts.loader),this._state={pastDelay:!1,timedOut:!1};let{_res:e,_opts:t}=this;e.loading&&("number"==typeof t.delay&&(0===t.delay?this._state.pastDelay=!0:this._delay=setTimeout(()=>{this._update({pastDelay:!0})},t.delay)),"number"==typeof t.timeout&&(this._timeout=setTimeout(()=>{this._update({timedOut:!0})},t.timeout))),this._res.promise.then(()=>{this._update({}),this._clearTimeouts()}).catch(e=>{this._update({}),this._clearTimeouts()}),this._update({})}_update(e){this._state={...this._state,error:this._res.error,loaded:this._res.loaded,loading:this._res.loading,...e},this._callbacks.forEach(e=>e())}_clearTimeouts(){clearTimeout(this._delay),clearTimeout(this._timeout)}getCurrentValue(){return this._state}subscribe(e){return this._callbacks.add(e),()=>{this._callbacks.delete(e)}}}function c(t){return function(t,s){let l=Object.assign({loader:null,loading:null,delay:200,timeout:null,webpack:null,modules:null},s),c=null;function u(){if(!c){let e=new d(t,l);c={getCurrentValue:e.getCurrentValue.bind(e),subscribe:e.subscribe.bind(e),retry:e.retry.bind(e),promise:e.promise.bind(e)}}return c.promise()}if("u"<typeof window&&o.push(u),!a&&"u">typeof window){let t=l.webpack&&"function"==typeof e.t.resolveWeak?l.webpack():l.modules;t&&n.push(e=>{for(let s of t)if(e.includes(s))return u()})}function h(e,t){let s;u(),(s=i.default.useContext(r.LoadableContext))&&Array.isArray(l.modules)&&l.modules.forEach(e=>{s(e)});let o=i.default.useSyncExternalStore(c.subscribe,c.getCurrentValue,c.getCurrentValue);return i.default.useImperativeHandle(t,()=>({retry:c.retry}),[]),i.default.useMemo(()=>{var t;return o.loading||o.error?i.default.createElement(l.loading,{isLoading:o.loading,pastDelay:o.pastDelay,timedOut:o.timedOut,error:o.error,retry:c.retry}):o.loaded?i.default.createElement((t=o.loaded)&&t.default?t.default:t,e):null},[e,o])}return h.preload=()=>u(),h.displayName="LoadableComponent",i.default.forwardRef(h)}(l,t)}function u(e,t){let s=[];for(;e.length;){let i=e.pop();s.push(i(t))}return Promise.all(s).then(()=>{if(e.length)return u(e,t)})}c.preloadAll=()=>new Promise((e,t)=>{u(o).then(e,t)}),c.preloadReady=(e=[])=>new Promise(t=>{let s=()=>(a=!0,t());u(n,e).then(s,s)}),"u">typeof window&&(window.__NEXT_PRELOADREADY=c.preloadReady);let h=c},759062,(e,t,s)=>{"use strict";Object.defineProperty(s,"__esModule",{value:!0});var i={default:function(){return u},noSSR:function(){return c}};for(var r in i)Object.defineProperty(s,r,{enumerable:!0,get:i[r]});let o=e.r(2879),n=e.r(478902);e.r(389959);let a=o._(e.r(612666)),l="u"<typeof window;function d(e){return{default:e?.default||e}}function c(e,t){if(delete t.webpack,delete t.modules,!l)return e(t);let s=t.loading;return()=>(0,n.jsx)(s,{error:null,isLoading:!0,pastDelay:!1,timedOut:!1})}function u(e,t){let s=a.default,i={loading:({error:e,isLoading:t,pastDelay:s})=>null};e instanceof Promise?i.loader=()=>e:"function"==typeof e?i.loader=e:"object"==typeof e&&(i={...i,...e});let r=(i={...i,...t}).loader;return(i.loadableGenerated&&(i={...i,...i.loadableGenerated},delete i.loadableGenerated),"boolean"!=typeof i.ssr||i.ssr)?s({...i,loader:()=>null!=r?r().then(d):Promise.resolve(d(()=>null))}):(delete i.webpack,delete i.modules,c(s,i))}("function"==typeof s.default||"object"==typeof s.default&&null!==s.default)&&void 0===s.default.__esModule&&(Object.defineProperty(s.default,"__esMo
2dule",{value:!0}),Object.assign(s.default,s),t.exports=s.default)},467272,(e,t,s)=>{t.exports=e.r(759062)},228837,e=>{"use strict";var t=e.i(389959),s=e.i(623690);e.i(807738);var i=e.i(738886);e.i(379067);var r=e.i(533329),o=e.i(970060),n="ka6at88",a="ka6at89",l="ka6at8a",d="ka6at8b",c=e.i(478902);e.s(["default",0,()=>{let{viewer:e,acknowledgeUserMessage:u}=(0,s.useCyclone)(),[h,p]=(0,t.useState)([]),y=e?.activeWarning,m=e?.activeMessages??[],f=(0,t.useCallback)(async e=>{p(t=>[...t,e]);try{await u(e)}finally{p(t=>t.filter(t=>t!==e))}},[u]);return y||m.length?(0,c.jsx)("section",{className:"ka6at82","aria-label":"Moderation messages",children:(0,c.jsx)("div",{className:o.sharedStyles.layout.mainColumn,children:(0,c.jsxs)("div",{className:"ka6at83",children:[y&&(0,c.jsxs)("article",{className:"ka6at84 ka6at80",role:"alert",children:[(0,c.jsx)("span",{className:"ka6at86 ka6at81",children:"Warning"}),(0,c.jsx)("p",{className:n,children:y.message}),(0,c.jsxs)("div",{className:a,children:[(0,c.jsx)(r.default,{timestamp:y.createdAt,format:"notifications",className:l}),(0,c.jsx)(i.default,{className:d,text:h.includes(y.id)?"Dismissing...":"Dismiss",displayType:"secondary",disabled:h.includes(y.id),onClick:()=>void f(y.id)})]})]}),m.map(e=>{let t=h.includes(e.id);return(0,c.jsxs)("article",{className:"ka6at85 ka6at80 _1upudxk11",children:[(0,c.jsx)("span",{className:"ka6at87 ka6at81",children:"Message"}),(0,c.jsx)("p",{className:n,children:e.message}),(0,c.jsxs)("div",{className:a,children:[(0,c.jsx)(r.default,{timestamp:e.createdAt,format:"notifications",className:l}),(0,c.jsx)(i.default,{className:d,text:t?"Dismissing...":"Dismiss",displayType:"secondary",disabled:t,onClick:()=>void f(e.id)})]})]},e.id)})]})})}):null}],228837)},624334,925677,e=>{"use strict";var t=e.i(509727),s=e.i(645904);let i=async(e,i,r,o)=>{if(!o)return null;let n=new URL("/api",r),a=await (0,s.makeRequest)(n.toString(),t.CloseRepliesMutation,{communityID:e,contentID:i},o);return a.errors||!a.data?null:a.data.closeReplies??null};e.s(["closeReplies",0,i],624334);let r=async(e,i,r,o)=>{if(!o)return null;let n=new URL("/api",r),a=await (0,s.makeRequest)(n.toString(),t.OpenRepliesMutation,{communityID:e,contentID:i},o);return a.errors||!a.data?null:a.data.openReplies??null};e.s(["openReplies",0,r],925677)},860047,e=>{"use strict";var t,s=e.i(579490),i=e.i(645904);let r=` 3 query FanPostsQuery($communityID: String!, $cursor: DateTime!, $count: Int!, $mode: FanPostsMode) { 4 fanPosts(communityID: $communityID, cursor: $cursor, count: $count, mode: $mode) { 5 items { 6 id 7 ... on FanPost { 8 ${s.FanPostFragment} 9 } 10 } 11 hasNext 12 endCursor 13 } 14 } 15`,o=((t={}).NEWEST="NEWEST",t.MOST_RECS="MOST_RECS",t.MOST_REPLIES="MOST_REPLIES",t),n=async(e,t,s,o,n,a)=>{let l=`${t}`,d=new URL("/api",e).toString(),c=await (0,i.makeRequest)(d,r,{communityID:l,cursor:s,count:o,mode:a},n);return c.data?.fanPosts?{fanPosts:c.data.fanPosts}:{fanPosts:{items:[],hasNext:!1}}};e.s(["FanPostsMode",0,o,"fetchFanPosts",0,n])},385799,e=>{"use strict";var t=e.i(509727),s=e.i(645904);let i=async(e,i,r,o,n)=>{let a=`${e}`;if(!n)return;let l=new URL("/api",o),d=await (0,s.makeRequest)(l.toString(),t.updateUserSettingsMutation,{communityID:a,userID:i,settings:r},n);if(!d.errors&&d.data)return d.data.updateUserSettings};e.s(["updateUserSettings",0,i])},323157,e=>{"use strict";var t=e.i(310282),s=e.i(579490),i=e.i(645904);class r{constructor(e,s,i,r,o){this.repliesStore=r,this.serverURL=e,this.communityID=s,this.token=o,this.contentStore=i,this.externalRootID="",this.friendlyID="",this.parentIDs=t.observable.map(new Map),this.hasLoaded=!1,this.hasErrors=!1,(0,t.makeObservable)(this,{hasErrors:t.observable,hasLoaded:t.observable,parentIDs:t.observable,externalRootID:t.observable,friendlyID:t.observable,setExternalRoot:t.action,externalRoot:t.computed,setToken:t.action,getPost:t.action})}setToken(e){this.token=e,this.repliesStore.setToken(e)}getPost(e){return this.contentStore.lookupById.get(e)??null}async loadExternalRoot(e,t,r){let o,n=` 16 query GetExternalRootQuery($communityID: String!, $friendlyID: String!, $url: String!, $title: String) { 17 comments(friendlyID: $friendlyID, communityID: $communityID, url: $url, title: $title) {
18 ${s.ExternalRootFragment} 19 } 20 }`;try{o=await (0,i.makeRequest)(`${this.serverURL}/api`,n,{communityID:e,friendlyID:t,url:r},this.token)}catch{return this.hasErrors=!0,null}return o.data?.comments?(this.setExternalRoot(o.data.comments),this.hasLoaded=!0,this.externalRoot):(this.hasErrors=!0,null)}setExternalRoot(e){this.externalRootID=e.id,this.friendlyID=e.friendlyID||"",this.repliesStore.setRoot(e),this.repliesStore.insert(e)}get externalRoot(){return this.contentStore.lookupById.get(this.externalRootID)}}var o=e.i(722010);let n=e=>{let s={justPostedByViewer:!1,...e,title:e.title?e.title:"",sortDate:new Date(e.createdAt),collapsed:!1,visible:e.visible??!0,recs:"recs"in e?e.recs??0:0,replyCount:e.replyCount??0,showHidden:e.showHidden??!1};return t.observable.object(s)},a=(e,s)=>{(0,t.runInAction)(()=>{let{id:t,parentID:i,title:r,body:n,createdAt:a,recs:l,replyCount:d,directReplyCount:c,collapsed:u,visible:h,deletedAt:p,isRecced:y,isReported:m,isEdited:f,modStatus:b,author:g,repliesAreClosed:S,premod:v,attachments:k,poll:R,seen:I,showHidden:D}=s;e.id=t??e.id,e.body=n??e.body,e.parentID=i??e.parentID,e.createdAt=a??e.createdAt,e.recs=l??e.recs,e.replyCount=d??e.replyCount,e.directReplyCount=c??e.directReplyCount,e.deletedAt=p??e.deletedAt,e.isRecced=y??e.isRecced,e.isReported=m??e.isReported,e.isEdited=f??e.isEdited,e.modStatus=b??e.modStatus,e.author=g??e.author,e.repliesAreClosed=S??e.repliesAreClosed,void 0!==v&&(e.premod=!0===v),e.attachments=void 0!==k?k:e.attachments,e.poll=void 0!==R?R:e.poll,e.collapsed=u??e.collapsed,e.visible=h??e.visible,e.showHidden=D??e.showHidden,e.type===o.ContentObjectType.FanPost&&(e.title=r??e.title),e.type===o.ContentObjectType.QuickPost&&(e.seen=I??!!e.seen),e.sortDate=a?new Date(a):e.sortDate})},l=(e,s)=>{(0,t.runInAction)(()=>{Object.assign(e,s),e.sortDate=new Date(s.createdAt)})};var d=o;let c=(e,t)=>t.sortDate.getTime()-e.sortDate.getTime(),u=(e,t)=>e.sortDate.getTime()-t.sortDate.getTime(),h=(e,t)=>t.recs-e.recs,p=(e,t)=>t.replyCount-e.replyCount,y=(e=d.ReplySort.NewestFirst)=>e===d.ReplySort.OldestFirst?u:e===d.ReplySort.MostRecs?h:e===d.ReplySort.MostReplies?p:c,m=[d.ReplySort.NewestFirst,d.ReplySort.OldestFirst],f=[d.ReplySort.NewestFirst,d.ReplySort.OldestFirst];class b{appliedReplyUpdatedAtMsByID=new Map;pendingReloadUpdates=[];constructor(e,s,i,r,o=d.ReplySort.NewestFirst){this.serverURL=e,this.communityID=s,this.token=r,this.contentStore=i,this.root=null,this.focusedReply=null,this.expandedAncestors=!0,this.traversalFocusContentID=null,this.replyFeeds=t.observable.map(new Map),this.parentIDs=t.observable.map(new Map),this.websocketReplyFeeds=t.observable.map(new Map),this.items=t.observable.array([]),this.currentSort=o,this.userHasInteractedWithPage=!1,this.containerWidth=null,this.hasLoaded=!1,this.loadedWithToken=null,this.hasErrors=!1,this.isReloading=!1,this.lastLoadedReplyCreatedAtMs=null,this.lastSyncOk=null,this.pendingReloadUpdates=[],(0,t.makeObservable)(this,{hasErrors:t.observable,hasLoaded:t.observable,loadedWithToken:t.observable,isReloading:t.observable,items:t.observable,currentSort:t.observable,replyFeeds:t.observable,websocketReplyFeeds:t.observable,parentIDs:t.observable,expandedAncestors:t.observable,ingestLiveReply:t.action,getToken:t.action,insertWebsocketReplies:t.action,insertAllWebsocketReplies:t.action,addToWebsocketReplies:t.action,setContainerWidth:t.action,root:t.observable,reload:t.action,loadReplies:t.action,setRoot:t.action,setSort:t.action,getAndSortChildren:t.action,insert:t.action,applyReplyUpdates:t.action,togglePost:t.action,recursivelyIncrementCounts:t.action,delete:t.action,topLevelReplies:t.computed,bufferedReplyCount:t.computed,bufferedTopLevelReplyCount:t.computed,bufferedTopLevelReplies:t.computed,setToken:t.action,focusedReply:t.observable,setFocusedReply:t.action,focusedTopLevelReply:t.computed,focusedAncestors:t.computed,userHasInteractedWithPage:t.observable,setUserHasInteractedWithPage:t.action,getPost:t.action,containerWidth:t.observable,getWebsocketRepliesSorted:t.action,traversalFocusContentID:t.observable,showHidden:t.action,lastLoadedReplyCreatedAtMs:t.observable,lastSyncOk:t.observable,setLastSyncOk:t.action})}setRoot(e){this.root=e}setLastSyncOk(e){this.lastSyncOk=e}setToken(e){this.token=e}getToken(){return this.token}isInVisibleThread(e,t){if(!t)return!1;let s=this.replyFeeds.get(t);return s?.some(t=>t.id===e)??!1}isInWebsocketFeed(e,t){if(!t)return!1;let s=this.websocketReplyFeeds.get(t);return s?.some(t=>t.id===e)??!1}ingestLiveReply(e,t,s={}){let i=e.updatedAt,r="string"==typeof i?i:"createdAt"in e&&"string"==typeof e.createdAt?e.createdAt:null;null!==r&&s.markEventSeen?.(r),this.isReloading&&this.pendingReloadUpdates.push({type:"reply",obj:e,viewerID:t}),this.applyLiveReply(e,t)}applyLiveReply(e,t){let s=e.parentID;if(s&&this.isInVisibleThread(e.id,s)||s&&this.isInWebsocketFeed(e.id,s)){let t=this.contentStore.lookupById.get(e.id);t&&a(t,e);return}let i="author"in e&&e.author?.id?e.author.id:"authorID"in e&&"string"==typeof e.authorID?e.authorID:void 0;t&&i&&i===t?this.insert(e):this.addToWebsocketReplies(e)}setContainerWidth(e){this.containerWidth=e}setFocusedReply(e){if(!e){this.focusedReply=null;return}let t=this.insert(e);this.focusedReply=t}setUserHasInteractedWithPage(e){this.userHasInteractedWithPage=e}getPost(e){return this.contentStore.lookupById.get(e)??null}get topLevelReplies(){if(!this.root)return[];let e=this.replyFeeds.get(this.root.id);return e?.slice().sort(y(this.currentSort))}get focusedAncestors(){let e=[];
20if(!this.focusedReply)return e;let t=this.focusedReply;for(;t.parentID;){let s=this.contentStore.lookupById.get(t.parentID);if(!s)break;e.splice(0,0,s),t=s}return e}get focusedTopLevelReply(){if(!this.focusedReply)return[];let e=this.parentIDs.get(this.focusedReply.id);if(e===this.focusedReply.rootAncestorID)return[this.focusedReply];if(!e)return[];let t=e;for(;t!==this.focusedReply.rootAncestorID;){let e=this.parentIDs.get(t);if(!e||e===this.focusedReply.rootAncestorID)break;t=e}let s=this.contentStore.lookupById.get(t);return s?[s]:[]}setSort(e,s=!1){if(this.currentSort!==e||s){this.currentSort=e;let s=this.computeSort(e);this.items=t.observable.array(s)}this.currentSort=e}get topLevelSocketPermitted(){return m.includes(this.currentSort)}get nestedSocketPermitted(){return f.includes(this.currentSort)}get bufferedTopLevelReplyCount(){return this.bufferedTopLevelReplies.length}get bufferedReplyCount(){return new Set(Array.from(this.websocketReplyFeeds.values()).flatMap(e=>e.map(e=>e.id))).size}get bufferedTopLevelReplies(){if(!this.root?.id)return[];let e=this.websocketReplyFeeds.get(this.root.id);return e?e.filter(e=>!this.isInVisibleThread(e.id,this.root?.id)):[]}removeFromWebsocketReplies(e,s){let i=this.websocketReplyFeeds.get(s);if(!i||!i.some(t=>t.id===e))return;let r=t.observable.array(i.filter(t=>t.id!==e));this.websocketReplyFeeds.set(s,r)}computeSort(e){if(!this.root)return[];switch(e){case d.ReplySort.NewestFirst:return this.getAndSortChildren(this.root.id,c,u);case d.ReplySort.OldestFirst:return this.getAndSortChildren(this.root.id,u,u);case d.ReplySort.MostRecs:return this.getAndSortChildren(this.root.id,h,u);case d.ReplySort.MostReplies:return this.getAndSortChildren(this.root.id,p,u);default:return this.getAndSortChildren(this.root.id,c,u)}}async reload(){if(!this.hasLoaded||this.isReloading)return"skipped";let e=Date.now();this.pendingReloadUpdates=[],this.isReloading=!0,this.hasErrors=!1,this.lastSyncOk=null;try{return await this.loadReplies()?"reloaded":"failed"}finally{let t=1e3-(Date.now()-e);t>0&&await new Promise(e=>setTimeout(e,t)),this.isReloading=!1,this.pendingReloadUpdates=[]}}async loadReplies(){let e,r=this.root;if(!r)return!1;let o=`query RepliesQuery($communityID: String!, $parentID: String!) { 21 allReplies(communityID: $communityID, id: $parentID) { 22 ${s.QuickPostFragment} 23 } 24 } 25 `,n={communityID:this.communityID,parentID:r.id},l=this.token??null;try{if(e=await (0,i.makeRequest)(`${this.serverURL}/api`,o,n,l),!e.data?.allReplies)return this.hasErrors=!0,!1}catch{return this.hasErrors=!0,!1}let d=e.data.allReplies,c=this.focusedReply?.id;return(0,t.runInAction)(()=>{for(let e of new Set([...this.parentIDs.keys(),...Array.from(this.replyFeeds.values()).flatMap(e=>e.map(e=>e.id)),...Array.from(this.websocketReplyFeeds.values()).flatMap(e=>e.map(e=>e.id))]))this.contentStore.lookupById.delete(e);for(let e of(this.replyFeeds.clear(),this.websocketReplyFeeds.clear(),this.parentIDs.clear(),this.items.clear(),this.appliedReplyUpdatedAtMsByID.clear(),d)){if(!e.parentID)continue;this.replyFeeds.has(e.parentID)||this.replyFeeds.set(e.parentID,t.observable.array([]));let s=this.contentStore.insert(e);if(e.parentID){this.parentIDs.set(e.id,e.parentID);let t=this.replyFeeds.get(e.parentID);!t?.find(t=>t.id===e.id)&&s&&t?.push(s)}}let e=d.find(e=>e.id===r.id);if(e){let t="number"==typeof e.replyCount?e.replyCount:void 0,s="number"==typeof e.directReplyCount?e.directReplyCount:void 0,i=this.contentStore.lookupById.get(r.id);i&&a(i,{replyCount:t,directReplyCount:s}),void 0!==t&&(r.replyCount=t),void 0!==s&&(r.directReplyCount=s)}for(let e of(this.focusedReply=c?this.contentStore.lookupById.get(c)??null:null,this.traversalFocusContentID&&!this.contentStore.lookupById.has(this.traversalFocusContentID)&&(this.traversalFocusContentID=null),this.setSort(this.currentSort,!0),this.pendingReloadUpdates.splice(0)))"reply"===e.type?this.applyLiveReply(e.obj,e.viewerID):this.applyDelete(e.id,e.deletedAt);let s=d.map(e=>"createdAt"in e&&"string"==typeof e.createdAt?Date.parse(e.createdAt):NaN).filter(e=>!Number.isNaN(e));this.lastLoadedReplyCreatedAtMs=s.length>0?Math.max(...s):null,this.loadedWithToken=l,this.hasLoaded=!0}),!0}togglePost(e){let t=this.contentStore.lookupById.get(e);if(!t)return;let s=t.collapsed;a(t,{collapsed:!s})}
25showHidden(e){let t=this.contentStore.lookupById.get(e);t&&!t.showHidden&&a(t,{showHidden:!0})}getAndSortChildren(e,t,s,i=0){let r=this.replyFeeds.get(e);if(!r)return[];let o=r.slice().sort((e,r)=>0===i?t(e,r):s(e,r)),n=[];for(let[e,r]of o.entries())for(let a of(n.push({id:r.id,depth:i,obj:r,isLastOfItsDepth:0===i||e===o.length-1,ancestorIDs:[]}),this.getAndSortChildren(r.id,t,s,i+1)))n.push(a);return n}recursivelyIncrementCounts(e,t){if(!e.parentID)return;let s=this.contentStore.lookupById.get(e.parentID);if(!s)return;let i={replyCount:s.replyCount+1};t&&(i={...i,...{directReplyCount:(s.directReplyCount??0)+1}}),a(s,i),s.parentID&&this.recursivelyIncrementCounts(s,!1)}recursivelyDecrementCounts(e,t){if(!e.parentID)return;let s=this.contentStore.lookupById.get(e.parentID);if(!s)return;let i={replyCount:Math.max(s.replyCount-1,0)};t&&(i.directReplyCount=Math.max((s.directReplyCount??0)-1,0)),a(s,i),s.parentID&&this.recursivelyDecrementCounts(s,!1)}applyReplyUpdates(e,t){let s=this.root?.id,i=[],r=new Map(this.appliedReplyUpdatedAtMsByID),o=[];for(let t of e){let e=Date.parse(t.updatedAt);if(!t.id||Number.isNaN(e))throw Error("Invalid Cyclone reply update");let i=r.get(t.id);if(void 0!==i&&i>=e)continue;if(t.id===s)throw Error("Cyclone reply update cannot target the thread root");let n=this.contentStore.lookupById.get(t.id);if(n&&n.type!==d.ContentObjectType.QuickPost)throw Error("Cyclone reply update cannot replace root content");if(t.reply&&(t.reply.id!==t.id||t.reply.type!==d.ContentObjectType.QuickPost||!t.reply.parentID))throw Error("Invalid Cyclone reply snapshot");if(n&&t.reply&&n.parentID!==t.reply.parentID)throw Error("Cyclone reply updates cannot change parents");r.set(t.id,e),o.push(t)}for(let e of o){if(!e.reply){this.removeReplyUpdate(e.id),i.push(e.id);continue}let s=e.reply,r=this.contentStore.lookupById.get(s.id);if(r){l(r,s);continue}let o=s.author?.id??("authorID"in s&&"string"==typeof s.authorID?s.authorID:void 0);t&&o===t?this.insert(s,{deferSort:!0}):this.addToWebsocketReplies(s)}for(let e of i)this.contentStore.lookupById.has(e)||this.removeReplyDescendants(e);return this.setSort(this.currentSort,!0),this.appliedReplyUpdatedAtMsByID=r,o.length}insert(e,s={}){let i=n({...e,justPostedByViewer:!!s.justPostedByViewer,rootAncestorID:"rootAncestorID"in e?e.rootAncestorID:this.root?.id,rootAncestor:"rootAncestor"in e?e.rootAncestor:this.root});i.parentID&&!this.replyFeeds.has(i.parentID)&&this.replyFeeds.set(i.parentID,t.observable.array([]));let r=this.contentStore.lookupById.get(i.id);r?a(r,e):this.contentStore.lookupById.set(i.id,i);let o=r??i;if(this.root?.id===o.id&&(this.root=o),i.parentID){let e=this.replyFeeds.get(i.parentID),t=e?.some(e=>e.id===i.id),s=r??i;t||(e?.push(s),this.parentIDs.set(i.id,i.parentID),this.recursivelyIncrementCounts(s,!0)),this.removeFromWebsocketReplies(i.id,i.parentID)}return s.deferSort||this.setSort(this.currentSort,!0),r??i}removeReplyFromFeed(e,t,s){let i=e.get(t),r=i?.findIndex(e=>e.id===s)??-1;i&&r>=0&&i.splice(r,1)}removeReplyDescendants(e,t=new Set){if(!t.has(e)){for(let s of(t.add(e),new Set([...this.replyFeeds.get(e)?.map(e=>e.id)??[],...this.websocketReplyFeeds.get(e)?.map(e=>e.id)??[]])))this.removeReplyDescendants(s,t),this.removeReplyUpdate(s);this.replyFeeds.delete(e),this.websocketReplyFeeds.delete(e)}}removeReplyUpdate(e){let t=this.contentStore.lookupById.get(e);if(!t||t.type!==d.ContentObjectType.QuickPost)return;let s=t.parentID,i=!!s&&this.isInVisibleThread(t.id,s);s&&(this.removeReplyFromFeed(this.replyFeeds,s,e),this.removeReplyFromFeed(this.websocketReplyFeeds,s,e)),i&&this.recursivelyDecrementCounts(t,!0),this.parentIDs.delete(e),this.contentStore.lookupById.delete(e),this.focusedReply?.id===e&&(this.focusedReply=null)}insertWebsocketReplies(e){if(!e)return;let t=e.slice();for(let s of(e.clear(),t)){let e=this.insert(s),t=this.websocketReplyFeeds.get(e.id);this.insertWebsocketReplies(t)}}insertAllWebsocketReplies(){let e=new Map(Array.from(this.websocketReplyFeeds.values()).flatMap(e=>e.slice()).map(e=>[e.id,e])),t=0,s=!0;for(;e.size>0&&s;)for(let[i,r]of(s=!1,e)){let o=r.parentID?this.contentStore.lookupById.get(r.parentID):null;(r.parentID===this.root?.id||o&&o.parentID&&this.isInVisibleThread(o.id,o.parentID))&&(this.insert(r,{deferSort:!0}),e.delete(i),t+=1,s=!0)}t>0&&this.setSort(this.currentSort,!0)}addToWebsocketReplies(e){let s=n(e);s.parentID&&!this.websocketReplyFeeds.has(s.parentID)&&this.websocketReplyFeeds.set(s.parentID,t.observable.array([]));let i=this.contentStore.lookupById.get(s.id);if(i)return void a(i,e);if(!(s.parentID&&this.isInWebsocketFeed(s.id,s.parentID))&&(this.contentStore.lookupById.set(s.id,s),s.parentID)){let e=this.websocketReplyFeeds.get(s.parentID);e?.push(s)}}getWebsocketRepliesSorted(e){let t=this.websocketReplyFeeds.get(e);return t?t.slice().sort(y(this.currentSort)):[]}delete({id:e,deletedAt:t}){this.isReloading&&this.pendingReloadUpdates.push({type:"delete",id:e,deletedAt:t}),this.applyDelete(e,t)}applyDelete(e,t){let s=this.contentStore.lookupById.get(e);s&&a(s,{deletedAt:t})}}var g=e.i(781333);class S{constructor(e,s,i){this.serverURL=e,this.networkID=s,this.token=i,this.ongoingDiscussions=t.observable.object({hasErrors:!1,hasLoaded:!1,items:[]}),(0,t.makeObservable)(this,{networkID:t.observable,ongoingDiscussions:t.observable,loadOngoingDiscussions:t.action,setToken:t.action})}setToken(e){this.token=e}async loadOngoingDiscussions(){let e,r=`query OngoingDiscussionsQuery($communityIDs: [String!]!) { 26 viewer { 27 ongoingDiscussions(communityIDs: $communityIDs) { 28 ... on QuickPost {
29 ${s.QuickPostFragment} 30 id 31 createdAt 32 community { 33 id 34 name 35 } 36 rootAncestor { 37 ... on ExternalRoot { 38 title 39 urls 40 replyCount 41 community { 42 id 43 } 44 } 45 } 46 } 47 } 48 } 49 } 50 `,o={communityIDs:(0,g.getNetworkCycloneCommunityIds)(this.networkID)};try{if(e=await (0,i.makeRequest)(`${this.serverURL}/api`,r,o,this.token),!e.data?.viewer?.ongoingDiscussions){this.ongoingDiscussions.hasErrors=!0;return}}catch{this.ongoingDiscussions.hasErrors=!0;return}this.ongoingDiscussions.hasLoaded=!0,this.ongoingDiscussions.items=t.observable.array(e.data.viewer.ongoingDiscussions)}}let v=` 51 query CommunityQuery($id: String!) { 52 community(id: $id) { 53 settings { 54 userIsTooNewThresholdMs 55 } 56 pinnedContentObject { 57 ... on FanPost { 58 ${s.FanPostFragment} 59 } 60 } 61 } 62 } 63`;class k{constructor(e,s,i){this.contentStore=i,this.communityID=e,this.serverURL=s,this.pinnedContentID=null,this.community=null,this.loadCommunity(),(0,t.makeObservable)(this,{loadCommunity:t.action,pinnedContentID:t.observable,setPinnedContentID:t.action,pinnedContent:t.computed,community:t.observable})}setPinnedContentID(e){this.pinnedContentID=e}get pinnedContent(){return this.pinnedContentID?this.contentStore.get(this.pinnedContentID):null}async loadCommunity(){let e=new URL("/api",this.serverURL),t=await (0,i.makeRequest)(e.toString(),v,{id:this.communityID});if(!t.data||!t.data.community||t.errors)return;let s=t.data.community??null;this.community=s,s.pinnedContentObject&&(this.pinnedContentID=s.pinnedContentObject.id,this.contentStore.insert(s.pinnedContentObject))}}class R{constructor(){this.lookupById=t.observable.map(new Map),this.unfurlMediaEmbeds=t.observable.array([]),(0,t.makeObservable)(this,{lookupById:t.observable,unfurlMediaEmbeds:t.observable,updateUnfurlMediaEmbeds:t.action})}updateUnfurlMediaEmbeds(e){let t=this.unfurlMediaEmbeds.indexOf(e);-1===t?this.unfurlMediaEmbeds.push(e):this.unfurlMediaEmbeds.splice(t,1)}get(e){return this.lookupById.get(e)}insert(e){let t=n({...e}),s=this.lookupById.get(t.id);return s?a(s,e):this.lookupById.set(t.id,t),this.lookupById.get(e.id)}}var I=e.i(649784);let D=` 64 query GetFanPostByShortID($communityID: String!, $shortID: String!) { 65 fanPost: fanPostByShortID(shortID: $shortID, communityID: $communityID) { 66 ${s.FanPostFragment} 67 } 68 } 69`,C=async(e,t,s,r)=>{let o=`${t}`,n=new URL("/api",e).toString(),a=await (0,i.makeRequest)(n,D,{communityID:o,shortID:s},r);return{fanPost:a.data?.fanPost}};var w=e.i(860047);class A{constructor(e,s,i,r,o,n){this.items=t.observable.array([]),this.hasNext=null,this.endCursor=null,this.contentStore=e,this.serverURL=s,this.communityID=i,this.communityStore=r,this.token=o,this.ignoredUsers=n,this.filterMode=w.FanPostsMode.NEWEST,this.loadingMore=!1,(0,t.makeObservable)(this,{visibleItems:t.computed,visibleItemsWithNativeAds:t.computed,hasNext:t.observable,endCursor:t.observable,insert:t.action,items:t.observable,setItems:t.action,setEndCursor:t.action,setHasNext:t.action,delete:t.action,loadMore:t.action,reload:t.action,setToken:t.action,setIgnoredUsers:t.action,setFilterMode:t.action,filterMode:t.observable,loadingMore:t.observable,setLoadingMore:t.action,ignoredUsers:t.observable})}setToken(e){this.token=e}setIgnoredUsers(e){this.ignoredUsers=e}setFilterMode(e){this.filterMode=e}setLoadingMore(e){this.loadingMore=e}get visibleItems(){let e=this.ignoredUsers??[];return this.filterMode===w.FanPostsMode.NEWEST?this.items.filter(t=>"string"==typeof t||!t.deletedAt&&t.id!==this.communityStore.pinnedContent?.id&&!e.some(e=>e.id===t.author?.id)):this.items.filter(t=>"string"==typeof t||!t.deletedAt||!e.some(e=>e.id===t.author?.id))}get visibleItemsWithNativeAds(){let e=this.visibleItems,t=e=>3===e||e>3&&(e-3)%8==0,s=[];for(let i=0;i<e.length;i++)t(i)&&e[i]!==I.NATIVE_AD_PLACEHOLDER&&s.push(I.NATIVE_AD_PLACEHOLDER),s.push(e[i]);return s}setHasNext(e){this.hasNext=e}setEndCursor(e){this.endCursor=e}async reload(e,t=10,s=!1){e&&(this.token=e);let{fanPosts:i}=await (0,w.fetchFanPosts)(`${this.serverURL}
69/api`,this.communityID,new Date().toISOString(),t,this.token,this.filterMode);for(let e of i.items){let t=this.contentStore.lookupById.get(e.id);t&&a(t,e)}if(s&&(this.setHasNext(!!i.hasNext),this.setEndCursor(i.endCursor??null),this.setItems([...i.items])),this.communityStore.pinnedContent?.shortID&&this.filterMode===w.FanPostsMode.NEWEST){let{fanPost:e}=await C(this.serverURL,this.communityID,this.communityStore.pinnedContent.shortID,this.token);e&&this.insert(e)}}async loadMore(){if(!this.hasNext||!this.endCursor)return;this.setLoadingMore(!0);let{fanPosts:e}=await (0,w.fetchFanPosts)(`${this.serverURL}/api`,this.communityID,this.endCursor,10,this.token);this.setHasNext(!!e.hasNext),this.setEndCursor(e.endCursor??null),this.setItems([...this.items,...e.items]),this.setLoadingMore(!1)}insert(e){let t=n({...e}),s=this.contentStore.lookupById.get(t.id);return s?a(s,e):this.contentStore.lookupById.set(t.id,t),s??t}setItems(e){let t=[];for(let s of e){if(s===I.NATIVE_AD_PLACEHOLDER)continue;let e=this.insert(s);t.push(e)}this.items.replace(t)}delete({id:e,deletedAt:t}){let s=this.contentStore.lookupById.get(e);s&&(a(s,{deletedAt:t}),this.communityStore.pinnedContentID===e&&this.communityStore.setPinnedContentID(null))}}class T{constructor(e,s,i,r,o){this.serverURL=e,this.communityID=s,this.token=o,this.contentStore=i,this.repliesStore=r,this.fanPostID="",this.parentIDs=t.observable.map(new Map),(0,t.makeObservable)(this,{parentIDs:t.observable,fanPostID:t.observable,setFanPost:t.action,fanPost:t.computed,setToken:t.action,getPost:t.action})}setToken(e){this.token=e,this.repliesStore.setToken(e)}getPost(e){return this.contentStore.lookupById.get(e)??null}async loadFanPost(e,t){let r=` 70 query GetFanPostQuery($communityID: String!, $id: String!) { 71 fanPost(id: $id, communityID: $communityID) { 72 ${s.FanPostFragment} 73 } 74 }`,o=await (0,i.makeRequest)(`${this.serverURL}/api`,r,{communityID:e,id:t},this.token);return o.data?.fanPost?(this.setFanPost(o.data.fanPost),this.fanPost):null}setFanPost(e){this.fanPostID=e.id,this.repliesStore.setRoot(e),this.repliesStore.insert(e)}get fanPost(){return this.contentStore.lookupById.get(this.fanPostID)}}e.s(["RootStore",0,class{constructor(e,t,s,i,o){this.token=i,this.ignoredUsers=o,this.contentStore=new R,this.communityStore=new k(s,e,this.contentStore),this.repliesStore=new b(e,s,this.contentStore,i),this.externalRootStore=new r(e,s,this.contentStore,this.repliesStore,i),this.fanPostStore=new T(e,s,this.contentStore,this.repliesStore,i),this.fanPostIndexStore=new A(this.contentStore,e,s,this.communityStore,i,o),this.viewerStore=new S(e,t,i)}setToken(e){this.token=e,this.fanPostStore.setToken(e),this.fanPostIndexStore.setToken(e),this.repliesStore.setToken(e),this.externalRootStore.setToken(e),this.viewerStore.setToken(e)}setIgnoredUsers(e){this.ignoredUsers=e,this.fanPostIndexStore.setIgnoredUsers(e)}}],323157)},334441,e=>{"use strict";var t=e.i(389959),s=e.i(579490),i=e.i(645904);async function r(e,t,r,o,n){let a=` 75 query RepliesUpdatedSince( 76 $communityID: String! 77 $id: String! 78 $since: DateTime! 79 ) { 80 repliesUpdatedSince( 81 communityID: $communityID 82 id: $id 83 since: $since 84 ) { 85 id 86 updatedAt 87 reply { 88 ${s.QuickPostFragment} 89 } 90 } 91 } 92 `,l=await (0,i.makeRequest)(`${e}/api`,a,{communityID:t,id:r,since:new Date(o).toISOString()},n);if(!l.data?.repliesUpdatedSince||l.errors)throw Error("Unable to fetch updated Cyclone replies");return l.data.repliesUpdatedSince}let o=new WeakMap;async function n(e,t,s,i,o){let n=t.root?.id;if(!n)return{ok:!1,fetched:0,applied:0};try{let a=await r(s,t.communityID,n,i,t.getToken()),l=t.applyReplyUpdates(a,o);if(a.length>0){let t=Math.max(...a.map(({updatedAt:e})=>Date.parse(e)));e.markEventSeen(t)}return t.setLastSyncOk(!0),{ok:!0,fetched:a.length,applied:l}}catch{return t.setLastSyncOk(!1),{ok:!1,fetched:0,applied:0}}}var a=e.i(310282);function l(e){return`${e.serverURL}:${e.communityID}:${e.queueID}`}class d{hasBeenLive=!1;refreshOnNextAck=!1;connectionState="offline";lastEventAt=0;lastAckAt=0;socket=null;scope=null;messageHandler=null;enabled=!1;isDisposing=!1;reconnectAttempt=0;lastHeartbeatSentAt=0;onReconnect=null;visibilityListener=null;constructor(){(0,a.makeAutoObservable)(this,{registerScope:!1,setEnabled:!1,setOnReconnect:!1,dispose:!1})}setOnReconnect(e){this.onReconnect=e}setEnabled(e){this.enabled=e,e&&this.scope?this.connect():e||(this.clearReconnectTimer(),this.teardownSocket(),this.setConnectionState("offline"))}registerScope(e,t){let s=this.scope,i=(s?l(s):null)!==l(e),r=s?.viewerID!==e.viewerID;return s&&i&&(this.lastEventAt=0),this.scope=e,this.messageHandler=t,this.enabled&&(i?this.connect():r&&this.socket&&this.socket.readyState===WebSocket.OPEN&&this.sendScope(this.socket)),()=>{this.messageHandler===t&&(this.messageHandler=null)}}markEventSeen(e){let t=e instanceof Date?e.getTime():"string"==typeof e?new Date(e).getTime():e;!Number.isNaN(t)&&t>this.lastEventAt&&(this.lastEventAt=t)}dispose(){this.isDisposing=!0,this.enabled=!1,this.scope=null,this.messageHandler=null,this.onReconnect=null,this.removeVisibilityListener(),this.clearTimers(),this.teardownSocket(),this.setConnectionState("offline")}setConnectionState(e){(0,a.runInAction)(()=>{this.connectionState=e})}connect(){let e;if(!this.enabled||!this.scope||this.isDisposing)return;this.hasBeenLive&&(this.refreshOnNextAck=!0),this.clearReconnectTimer(),this.teardownSocket(),this.isDisposing=!1;let{serverURL:t}=this.scope;if(t){try{e=new URL("/messages",t).toString()}catch{this.scheduleReconnect();return}this.setConnectionState("reconnecting");try{let t=new WebSocket(e);this.socket=t,t.onopen=()=>{t.readyState===WebSocket.OPEN&&this.socket===t&&(this.reconnectAttempt=0,this.setConnectionState("reconnecting"),this.sendScope(t),this.sendHeartbeat())},t.onmessage=e=>{this.handleMessage(e)},t.onerror=()=>{this.isDisposing||this.socket!==t||this.scheduleReconnect()},t.onclose=()=>{this.isDisposing||this.socket!==t||this.scheduleReconnect()}}catch{this.scheduleReconnect()}this.ensureVisibilityListener()}}sendScope(e){if(!this.scope||e.readyState!==WebSocket.OPEN)return;let t=JSON.stringify({type:"SCOPE",protocolVersion:1,queueID:this.scope.queueID,communityID:this.scope.communityID,viewerID:this.scope.viewerID});try{e.send(t)}catch{this.scheduleReconnect()}}handleMessage(e){try{let t="string"==typeof e.data?e.data:String(e.data??""),s=JSON.parse(t);if(!s?.type)return;if("HEARTBEAT_ACK"===s.type)return void this.handleHeartbeatAck(s.time);try{this.messageHandler?.(s)}catch(e){}}catch{}}handleHeartbeatAck(e){"number"==typeof e&&e===this.lastHeartbeatSentAt&&(this.clearAckWatchdog(),(0,a.runInAction)(()=>{this.lastAckAt=Date.now()}),this.refreshOnNextAck&&(this.refreshOnNextAck=!1,this.onReconnect?.()),this.hasBeenLive=!0,this.setConnectionState("live"))}scheduleHeartbeat(){this.clearHeartbeatTimer();let e=Date.now();this.heartbeatTimer=setTimeout(()=>{Date.now()-e-15e3>1e4&&this.setConnectionState("reconnecting"),this.sendHeartbeat()},15e3)}sendHeartbeat(){if(this.isDisposing||!this.enabled)return;let e=this.socket;if(!e||e.readyState!==WebSocket.OPEN)return void this.scheduleReconnect();let t=Date.now();try{e.send(JSON.stringify({type:"HEARTBEAT",time:t}))}catch{this.scheduleReconnect();return}this.lastHeartbeatSentAt=t,this.scheduleHeartbeat(),this.resetAckWatchdog()}
92resetAckWatchdog(){this.clearAckWatchdog(),this.ackWatchdogTimer=setTimeout(()=>{this.lastAckAt>=this.lastHeartbeatSentAt||this.scheduleReconnect()},1e4)}scheduleReconnect(){var e;if(this.isDisposing||!this.enabled)return;this.teardownSocket(),this.setConnectionState("reconnecting");let t=(e=Math.min(1e3*2**this.reconnectAttempt,3e4))+Math.floor(Math.random()*e*.25);this.reconnectAttempt+=1,this.clearReconnectTimer(),this.reconnectTimer=setTimeout(()=>{this.connect()},t)}teardownSocket(){this.clearHeartbeatTimer(),this.clearAckWatchdog();let e=this.socket;if(this.socket=null,e&&e.readyState!==WebSocket.CLOSING&&e.readyState!==WebSocket.CLOSED)try{e.close()}catch{}}ensureVisibilityListener(){!this.visibilityListener&&"u">typeof document&&(this.visibilityListener=()=>{if("visible"===document.visibilityState&&this.enabled&&this.scope){let e=this.socket,t="live"!==this.connectionState||Date.now()-this.lastAckAt>=25e3;if(!e||e.readyState!==WebSocket.OPEN){this.reconnectAttempt=0,this.connect();return}t&&(this.setConnectionState("reconnecting"),this.sendHeartbeat())}},document.addEventListener("visibilitychange",this.visibilityListener))}removeVisibilityListener(){this.visibilityListener&&"u">typeof document&&(document.removeEventListener("visibilitychange",this.visibilityListener),this.visibilityListener=null)}clearTimers(){this.clearReconnectTimer(),this.clearHeartbeatTimer(),this.clearAckWatchdog()}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=void 0)}clearHeartbeatTimer(){this.heartbeatTimer&&(clearTimeout(this.heartbeatTimer),this.heartbeatTimer=void 0)}clearAckWatchdog(){this.ackWatchdogTimer&&(clearTimeout(this.ackWatchdogTimer),this.ackWatchdogTimer=void 0)}}var c=e.i(722010);let u=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),h=new Set(["type","queueID","payload"]);var p=e.i(210982),y=e.i(478902);let m=(0,t.createContext)(null);e.s(["CycloneWebsocketProvider",0,({serverURL:e,repliesStore:s,viewerID:i,enabled:r,ignoreLiveReplies:a=!1,children:l})=>{let f=(0,t.useRef)(null),b=(0,t.useRef)(null),g=(0,t.useRef)(a);g.current=a,f.current||(f.current=new d);let S=f.current,v=(0,p.useAnalytics)(),k=(0,t.useRef)(v);k.current=v,(0,t.useEffect)(()=>{let t=function({manager:e,repliesStore:t,serverURL:s,viewerID:i,debounceMs:r=250,onComplete:a}){let l,d=null,c=!1,u=!1,h=!1,p=e=>{d=null===d?e:Math.min(d,e)},y=()=>{l=setTimeout(()=>{l=void 0,m()},r)},m=async()=>{if(h||c||null===d)return;let r=d;d=null,c=!0;let l=await function(e,t,s,i,r){let a=o.get(t);if(a)return a;let l=n(e,t,s,i,r).finally(()=>{o.get(t)===l&&o.delete(t)});return o.set(t,l),l}(e,t,s,r,i);c=!1,a?.(l,r),l.ok||p(r),u&&(u=!1,y())},f=()=>{d=null,u=!1,l&&(clearTimeout(l),l=void 0)};return{schedule(e){if(!h){if(p(e),c){u=!0;return}l&&clearTimeout(l),y()}},reset:f,dispose(){h=!0,f()}}}({manager:S,repliesStore:s,serverURL:e,viewerID:i,onComplete:(e,t)=>{!function(e,t){if(!e)return;let s={event:"cyclone_reconnect",cyclone_reconnect:{last_event_age_ms:t.lastEventAgeMs,has_updates:t.hasUpdates,updates_check_failed:t.updatesCheckFailed}};e.emit(s)}(k.current,{lastEventAgeMs:Date.now()-t,hasUpdates:e.ok?e.applied>0:null,updatesCheckFailed:!e.ok})}});return b.current=t,S.setOnReconnect(()=>{s.root?.id&&t.schedule(S.lastEventAt)}),()=>{S.setOnReconnect(null),t.dispose(),b.current===t&&(b.current=null)}},[S,s,e,i]),(0,t.useEffect)(()=>{let e=[s.root?.createdAt?Date.parse(s.root.createdAt):NaN,s.lastLoadedReplyCreatedAtMs].filter(e=>null!==e&&!Number.isNaN(e));e.length>0&&S.markEventSeen(Math.max(...e))},[S,s.lastLoadedReplyCreatedAtMs,s.root?.createdAt]),(0,t.useEffect)(()=>{S.setEnabled(r)},[S,r]),(0,t.useEffect)(()=>{if(!r)return;let t=s.root?.id;if(t)return S.registerScope({serverURL:e,communityID:s.communityID,queueID:t,viewerID:i},e=>{g.current||function(e,t,s,i){let r,o,n,a,l="QuickPostDeleted"!==e.type?null:u(e.payload)?e.payload:"string"==typeof e.id?{id:e.id,deletedAt:"string"==typeof e.deletedAt?e.deletedAt:null}:null;if(l?.id)return t.delete({id:l.id,deletedAt:l.deletedAt??new Date().toISOString()});let d=function(e){if(e.type!==c.ContentObjectType.QuickPost)return null;if(u(e.payload))return e.payload;if("string"==typeof e.payload)try{let t=JSON.parse(e.payload);if(u(t))return t}catch{}let t={};for(let s of Object.keys(e))h.has(s)||(t[s]=e[s]);return"string"==typeof t.id&&"string"==typeof t.parentID?t:null}(e);if(!d)return;let p=(r=d.author,o=r?.id??("string"==typeof d.authorID?d.authorID:void 0),n=d.community,a="string"==typeof d.communityID?d.communityID:n?.id??"",{...d,replyCount:"number"==typeof d.replyCount?d.replyCount:0,recs:"number"==typeof d.recs?d.recs:0,seen:!!i&&!!o&&i===o||!!d.seen,community:{id:a,type:c.CommunityType.General}});t.ingestLiveReply(p,i,{markEventSeen:e=>s.markEventSeen(e)})}(e,s,S,i)})},[r,S,s,s.communityID,s.root?.id,e,i]),(0,t.useEffect)(()=>()=>{S.dispose(),f.current=null},[S]);let R=(0,t.useMemo)(()=>({manager:S,resetReplyUpdateRefresh:()=>b.current?.reset()}),[S]);return(0,y.jsx)(m.Provider,{value:R,children:l})},"useOptionalCycloneWebsocketContext",0,function(){return(0,t.useContext)(m)}],334441)}]); 93 94//# debugId=10bcaa6b-a0a9-6da9-5750-07615833c575 95//# sourceMappingURL=2kczfte66897-.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.