Build 576754stable
Module 271004
3,788 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{jA:()=>h,As:()=>E,XH:()=>A});var i=n(636537),r=n(228366),a=n(763827),s=n(403362);n(321073);var l=n(272355),o=n(967198),d=n(857071),c=n(742872);class u extends l.A{timers=new Map;viewedLurkingGuildIds=new Set;navigatedAwayFromLurkingGuildIds=new Set;hasNavigatedAway(e){return this.navigatedAwayFromLurkingGuildIds.has(e)}_initialize(){d.A.addChangeListener(this.handleStoreChange),o.A.addChangeListener(this.handleStoreChange),a.A.addChangeListener(this.handleStoreChange),this.handleStoreChange()}_terminate(){for(let e of(d.A.removeChangeListener(this.handleStoreChange),o.A.removeChangeListener(this.handleStoreChange),a.A.removeChangeListener(this.handleStoreChange),this.timers.values()))clearTimeout(e);this.timers.clear(),this.viewedLurkingGuildIds.clear(),this.navigatedAwayFromLurkingGuildIds.clear()}handleStoreChange=()=>{this.trackViewedLurkingGuilds(),this.evictOverflowingLurkers(),this.ensureMissingExpiries(),this.expireElapsed(),this.syncTimers()};trackViewedLurkingGuilds=()=>{let e=new Set(d.A.lurkingGuildIds());for(let t of Array.from(this.viewedLurkingGuildIds))e.has(t)||this.viewedLurkingGuildIds.delete(t);for(let t of Array.from(this.navigatedAwayFromLurkingGuildIds))e.has(t)||this.navigatedAwayFromLurkingGuildIds.delete(t);let t=o.A.getGuildId();for(let e of this.viewedLurkingGuildIds)e!==t&&this.navigatedAwayFromLurkingGuildIds.add(e);null!=t&&e.has(t)&&this.viewedLurkingGuildIds.add(t)};evictOverflowingLurkers=()=>{let e=d.A.lurkingGuildIds();if(e.length<=3||!(0,c.Jz)("LurkerPreviewManager.evictOverflowingLurkers").stickyLurk)return;let t=e.length-3,n=e.slice(0,t);this.expireLurkerPreviews(n)};ensureMissingExpiries=()=>{let e=d.A.lurkingGuildIds();if(0===e.length)return;let t=d.A.getLurkingPreviewExpirations(),n=o.A.getGuildId(),i=e.filter(e=>null==t[e]&&e!==n&&this.viewedLurkingGuildIds.has(e));0===i.length||(0,c.Jz)("LurkerPreviewManager.ensureMissingExpiries").stickyLurk&&r.h.dispatch({type:"LURKER_PREVIEW_SET_EXPIRY",guildIds:i,expiresAt:Date.now()+6e4})};expireElapsed=()=>{let e=d.A.getLurkingPreviewExpirations(),t=o.A.getGuildId(),n=a.A.getGuildId(),i=Date.now(),r=[];for(let a of Object.keys(e))a!==t&&a!==n&&e[a]<=i&&r.push(a);r.length>0&&this.expireLurkerPreviews(r)};syncTimers=()=>{let e=d.A.getLurkingPreviewExpirations();for(let t of Array.from(this.timers.keys()))if(null==e[t]){let e=this.timers.get(t);null!=e&&clearTimeout(e),this.timers.delete(t)}for(let t of Object.keys(e)){if(this.timers.has(t))continue;let n=e[t];if(n<=Date.now())continue;let i=setTimeout(()=>{this.timers.delete(t),this.handleStoreChange()},n-Date.now());this.timers.set(t,i)}};expireLurkerPreviews=async e=>{await Promise.all(e.map(e=>A(e)))}}new u;var _=n(652215);async function E(e){let t=d.A.lurkingGuildIds().filter(t=>!e.includes(t));if(0===t.length)return;let n=new Map(t.map(e=>[e,d.A.getLurkingSourceForGuild(e)]));r.h.dispatch({type:"GUILD_STOP_LURKING",ignoredGuildIds:e}),await Promise.all(t.map(async e=>{let t=n.get(e)??null;try{await i.Bo.del({url:_.Rsh.GUILD_LEAVE(e),body:{lurking:!0},oldFormErrors:!0,rejectWithError:!0})}catch(n){r.h.dispatch({type:"GUILD_STOP_LURKING_FAILURE",lurkingGuildId:e,lurkingSource:t})}}))}async function A(e){if(!d.A.lurkingGuildIds().includes(e))return;let t=d.A.getLurkingSourceForGuild(e);r.h.dispatch({type:"GUILD_STOP_LURKING_FOR_GUILD",lurkingGuildId:e});try{await i.Bo.del({url:_.Rsh.GUILD_LEAVE(e),body:{lurking:!0},oldFormErrors:!0,rejectWithError:!0})}catch(n){r.h.dispatch({type:"GUILD_STOP_LURKING_FAILURE",lurkingGuildId:e,lurkingSource:t})}}async function h(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=d.A.lurkingGuildIds();if(0===t.length||!(null==e||!t.includes(e)))return;let n=[e,a.A.getGuildId()].filter(s.Vq);await E(n)}}