revenge-plugins/server-drawer/install/index.js
2026-08-02 18:11:23 +00:00

1 line
28 KiB
JavaScript

(function(U,le,c,d,r,i,L,I,Q,se,Xe){"use strict";function p(e){const t=window?.modules;if(t)for(const n in t){const o=t[n];if(!o?.isInitialized)continue;const l=o.publicModule?.exports;if(l)try{if(e(l))return l;if(l.default!=null&&e(l.default))return l.default}catch{}}}function Je(e){return p(function(t){return t?.name===e||t?.displayName===e})}function x(...e){return p(function(t){return e.every(function(n){return typeof t?.[n]=="function"})})}function q(e){const t=Object.keys(e);return p(function(n){return t.every(function(o){try{return e[o](n?.[o])}catch{return!1}})})}function b(e){return p(function(t){return typeof t?.getName=="function"&&t.getName.length===0&&t.getName()===e})}function Ye(e,t,n=100){let o=!1,l;const s=e();return s?(t(s),{cancel(){}}):(l=setInterval(function(){if(o)return;const a=e();a&&(o=!0,clearInterval(l),t(a))},n),{cancel(){o=!0,l&&clearInterval(l)}})}const ae=new Map,Ie=[],ue=[];let O=[],X=!1;function J(e,t,n){ae.set(e,{replacement:t,extraProps:n})}function Ke(e,t){ue.push({predicate:e,transform:t})}function ce(e,t,n){O.push({predicate:e,onDetected:t,persistent:n?.persistent??!1})}function Ze(e){if(O.length===0)return;const t=[];for(const n of O){let o=!1;try{o=n.predicate(e)}catch{}if(o){try{n.onDetected(e)}catch{}n.persistent&&t.push(n)}else t.push(n)}O=t}function Re(e,t){Ze(e);let n=t;if(n)for(const{predicate:l,transform:s}of ue)try{l(n)&&(n=s(n))}catch{}if(n)for(const{predicate:l,replacement:s}of Ie)try{if(l(n))return s?{type:s,props:n}:null}catch{}const o=ae.get(e);if(o)return{type:o.replacement,props:o.extraProps?{...n,...o.extraProps}:n};if(n!==t)return{type:e,props:n}}function $e(e){if(X)return;const t=d.React.createElement;if(!t){console.warn("[ServerDrawer] React.createElement is null, skipping patch");return}const n=function(s,a,...g){const m=Re(s,a);return m===null?null:m?t.call(d.React,m.type,m.props,...g):t.call(d.React,s,a,...g)};Object.assign(n,t),d.React.createElement=n,X=!0;const o=[],l=Ye(function(){return p(function(s){return typeof s?.jsx=="function"&&typeof s?.jsxs=="function"&&"Fragment"in s})},function(s){for(const a of["jsx","jsxs"]){const g=s[a];typeof g=="function"&&(s[a]=function(m,S,...y){const f=Re(m,S);return f===null?null:f?g.call(this,f.type,f.props,...y):g.call(this,m,S,...y)},o.push(function(){s[a]=g}))}});e.push(function(){l.cancel(),X&&(d.React.createElement=t,X=!1),o.forEach(function(s){return s()}),ae.clear(),Ie.length=0,ue.length=0,O=[]})}const Ne="[ServerDrawer]";function et(e){return Ke(function(t){const n=t?.value;return!!(n&&typeof n=="object"&&"isRendered"in n&&"isVisibleToUser"in n&&"quest"in n)},function(t){const n=t.value,o=n.quest??tt();return{...t,value:{...n,isRendered:!0,isVisibleToUser:!0,quest:nt(o)}}}),e.push(function(){}),console.log(Ne,"PATCH: watching for the Quest Dock coordination context"),!0}function tt(){return{id:"server-drawer",config:{quest_content_type:0,assets:{questBarHeroVideo:"",questBarHero:""},features:[]},userStatus:{enrolledAt:"2099-01-01",claimedAt:null},benefits:{rewards:[]},guildId:"0",tasks:[]}}function nt(e){const t=e?.config?.assets;if(!t)return e;const n=t.questBarHero,o=t.questBarHeroVideo;return n!=null&&o!=null?e:{...e,config:{...e.config,assets:{...t,questBarHero:n??"",questBarHeroVideo:o??""}}}}function u(e){let t,n=!1;return function(){if(n)return t;const o=e();return o!=null&&(t=o,n=!0),o??void 0}}const F=u(function(){return x("useStateFromStores")}),H=u(function(){return q({triggerHapticFeedback:function(e){return typeof e=="function"},HapticFeedbackTypes:function(e){return e?.SOFT!==void 0}})}),Y=u(function(){return q({colors:function(e){return e?.BG_ACCENT!==void 0},unsafe_rawColors:function(e){return e?.WHITE!==void 0}})}),Te=u(function(){return x("bulkAck","ackChannel")}),De=u(function(){return q({ReadStateTypes:function(e){return e?.CHANNEL!==void 0},UnreadSetting:function(e){return e?.ALL_MESSAGES!==void 0}})});function xe(e){if(e)try{let t=null;if(e._internalFiberInstanceHandleDEV)t=e._internalFiberInstanceHandleDEV;else if(e._internalInstanceHandle)t=e._internalInstanceHandle;else if(e.__internalInstanceHandle)t=e.__internalInstanceHandle;else{const l=Object.keys(e).find(function(s){return s.startsWith("__reactFiber$")||s.startsWith("__reactInternalInstance$")});l&&(t=e[l])}if(!t)return;if(t.return===void 0&&t.child===void 0){const l=t.stateNode??t.fiber??t._debugOwner;if(l&&(l.return!==void 0||l.child!==void 0))t=l;else return}let n=t,o=0;for(;n.return&&o<5e3;)n=n.return,o++;window.__serverDrawerFiberRoot=n,window.__serverDrawerFiberSelf=t}catch{}}const rt=u(function(){return b("ExpandedGuildFolderStore")});function ot(){const e=Y()?.colors;return{text:e?.TEXT_NORMAL??"#dbdee1",folder:"#5865f2",hover:e?.STATE_LAYER_PRESS??"rgba(255,255,255,0.06)"}}function it(e){const t=F(),n=rt();return t?.useStateFromStores?.([n],function(){const o=n?.getExpandedFolders?.();return o instanceof Set?o.has(e):!1},[e])??!1}const lt=u(function(){return b("GuildStore")});function Fe({id:e,size:t=48}){const n=F(),o=lt(),l=Y()?.colors,s=n?.useStateFromStores?.([o],function(){return o?.getGuild?.(e)},[e])??null;if(!s)return null;const a=t>=40?16:8;return s.icon?r.createElement(i.Image,{source:{uri:`https://cdn.discordapp.com/icons/${s.id}/${s.icon}.png?size=${t*2}`},style:{width:t,height:t,borderRadius:a}}):r.createElement(i.View,{style:[Ae.fallback,{width:t,height:t,borderRadius:a,backgroundColor:l?.BG_ACCENT??"#5865f2"}]},r.createElement(i.Text,{style:[Ae.letter,{fontSize:Math.max(10,t*.4)}]},s.name?.split(" ").map(function(g){return g[0]}).join("").slice(0,2).toUpperCase()||"?"))}const Ae=i.StyleSheet.create({fallback:{alignItems:"center",justifyContent:"center"},letter:{color:"#fff",fontWeight:"700"}}),st=u(function(){return b("ThemeStore")}),at=u(function(){return p(function(e){return e?.default?.internal?.resolveSemanticColor})?.default?.internal?.resolveSemanticColor??p(function(e){return e?.meta?.resolveSemanticColor})?.meta?.resolveSemanticColor});function ut(e,t=st()?.theme){if(e)try{return at()?.(t,e)}catch{return}}const ct=u(function(){return q({TextStyleSheet:function(e){return e?.["text-md/bold"]!==void 0}})?.TextStyleSheet});function K(e,t){return ut(e)??t}const A=12,de=12,Ve=42,fe=220,He=4,M=16,Z=20,Pe={tension:200,friction:20};function dt({visible:e,items:t,title:n,anchorX:o,anchorY:l,onClose:s}){const a=ct(),g=H(),{width:m,height:S}=i.Dimensions.get("window"),y=(n?de+20+He:0)+t.length*Ve;let f=o,w=l+48+10;f+fe>m-A&&(f=m-fe-A),f<A&&(f=A),w+y>S-A&&(w=l-y-10),w<A&&(w=A);const B=K(Q.semanticColors?.BACKGROUND_SURFACE_HIGHEST,"#1e1f22"),V=K(Q.semanticColors?.BORDER_SUBTLE,"#3f4147"),h=K(Q.semanticColors?.TEXT_STRONG,"#f2f3f5"),k=K(Q.semanticColors?.BACKGROUND_MOD_SUBTLE,"rgba(255,255,255,0.06)"),T=r.useRef(new i.Animated.Value(0)).current,W=r.useRef(new i.Animated.Value(.5)).current,_=r.useRef(new i.Animated.Value(0)).current,[oe,qe]=r.useState(!1),ie=r.useRef(!1);r.useEffect(function(){e&&!ie.current&&(qe(!0),T.setValue(0),W.setValue(.5),_.setValue(0),i.Animated.parallel([i.Animated.timing(T,{toValue:1,duration:150,useNativeDriver:!0}),i.Animated.spring(W,{toValue:1,useNativeDriver:!0,...Pe}),i.Animated.spring(_,{toValue:1,useNativeDriver:!0,...Pe})]).start())},[e]);const we=r.useCallback(function(){ie.current||(ie.current=!0,i.Animated.parallel([i.Animated.timing(T,{toValue:0,duration:120,useNativeDriver:!0}),i.Animated.timing(W,{toValue:.8,duration:120,useNativeDriver:!0}),i.Animated.timing(_,{toValue:0,duration:120,useNativeDriver:!0})]).start(function(){ie.current=!1,qe(!1),s()}))},[s]);return oe?r.createElement(i.Modal,{transparent:!0,visible:oe,onRequestClose:we,statusBarTranslucent:!0},r.createElement(i.Pressable,{style:he.root,onPress:we},r.createElement(i.Animated.View,{style:[he.backdrop,{opacity:T}]}),r.createElement(i.Animated.View,{style:[he.container,{left:f,top:w,backgroundColor:B,borderColor:V,minWidth:fe,opacity:_,transform:[{scale:W}]}]},n?r.createElement(i.View,null,r.createElement(i.Text,{style:[a?.["text-md/bold"],{color:h,paddingHorizontal:de,paddingTop:13,paddingBottom:12}]},n),r.createElement(i.View,{style:{borderBottomWidth:He,borderBottomColor:V}})):null,t.map(function(D,Ee){const Se=Ee===0&&!n,ke=Ee===t.length-1,mn=!!(D.iconSource||D.IconComponent);return r.createElement(i.Pressable,{key:Ee,style:function({pressed:pn}){return{paddingHorizontal:de,paddingVertical:10,minHeight:Ve,flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:8,backgroundColor:pn?k:"transparent",borderTopLeftRadius:Se?M:0,borderTopRightRadius:Se?M:0,borderBottomLeftRadius:ke?M:0,borderBottomRightRadius:ke?M:0,borderBottomWidth:!Se&&!ke?1:0,borderBottomColor:V}},onPress:function(){g?.triggerHapticFeedback?.(g.HapticFeedbackTypes.IMPACT_LIGHT),we(),D.action?.()}},r.createElement(i.Text,{style:[a?.["text-md/medium"],{flexShrink:1,color:h}]},D.label),mn?r.createElement(i.View,{style:{width:Z,height:Z,alignItems:"center",justifyContent:"center"}},D.IconComponent?r.createElement(D.IconComponent,{size:"sm",color:h}):D.iconSource?r.createElement(i.Image,{source:D.iconSource,style:{width:Z,height:Z,tintColor:h}}):null):null)})))):null}const he=i.StyleSheet.create({root:{flex:1},backdrop:{...i.StyleSheet.absoluteFill,backgroundColor:"rgba(0,0,0,0.55)"},container:{position:"absolute",borderWidth:1,borderRadius:M,overflow:"hidden",elevation:20,shadowColor:"#000",shadowOffset:{width:0,height:12},shadowOpacity:.24,shadowRadius:24}}),P=48,ft=Te,ht=u(function(){return De()?.ReadStateTypes}),gt=u(function(){return b("GuildReadStateStore")}),Ge=u(function(){return b("GuildStore")}),mt=u(function(){return b("GuildChannelStore")}),pt=u(function(){return b("ChannelStore")});function yt(e){const t=ft(),n=ht(),o=mt(),l=pt();if(!t?.bulkAck||n?.CHANNEL==null||!o?.getSelectableChannelIds){I.showToast("Couldn't find Discord's read-state action - this may be unavailable on your version.",void 0);return}const s=[...o.getSelectableChannelIds(e)??[],...o.getVocalChannelIds?.(e)??[]].map(function(a){return{channelId:a,readStateType:n.CHANNEL,messageId:l?.getChannel?.(a)?.lastMessageId??null}});if(s.length===0){I.showToast("Nothing to mark as read.",void 0);return}t.bulkAck(s),I.showToast("Marked as read",void 0)}function bt({guildId:e}){L.useProxy(c.storage);const t=F(),n=gt(),o=t?.useStateFromStores?.([n],function(){return n?.getMentionCount?.(e)??0},[e])??0,l=t?.useStateFromStores?.([n],function(){return n?.hasUnread?.(e)??!1},[e])??!1;return c.storage.showUnreadBadges?o>0?r.createElement(i.View,{style:j.outline},r.createElement(i.View,{style:j.badge},r.createElement(i.Text,{style:j.text},o>99?"99+":String(o)))):l?r.createElement(i.View,{style:j.dotOutline},r.createElement(i.View,{style:j.dot})):null:null}function Ct({guildId:e}){L.useProxy(c.storage);const t=ot(),n=F(),o=Ge(),l=n?.useStateFromStores?.([o],function(){return o?.getGuild?.(e)?.name??""},[e])??"";return c.storage.showGuildNames===!1||!l?null:r.createElement(i.Text,{numberOfLines:2,style:[wt.label,{color:t.text}]},l)}function ve({node:e,onPick:t}){const n=r.useRef(null),o=r.useRef(new i.Animated.Value(1)).current,l=function(){return i.Animated.spring(o,{toValue:.85,useNativeDriver:!0}).start()},s=function(){return i.Animated.spring(o,{toValue:1,useNativeDriver:!0}).start()},[a,g]=r.useState({visible:!1,items:[],title:"",x:0,y:0}),m=r.useCallback(function(){const f=e.id,w=Ge()?.getGuild?.(f);if(!w)return;const B=n.current;if(!B?.measure)return;const V=[{label:"Mark as Read",action:function(){return yt(f)}},{label:"Copy Server ID",action:function(){d.clipboard.setString(f),I.showToast("Copied server ID",void 0)}}];B.measure(function(h,k,T,W,_,oe){g({visible:!0,items:V,title:w.name,x:_,y:oe})})},[e.id]),S=r.useCallback(function(){const f=H();f?.triggerHapticFeedback?.(f.HapticFeedbackTypes.IMPACT_MEDIUM),m()},[m]),y=e.id;return r.createElement(r.Fragment,null,r.createElement(i.Pressable,{onPressIn:l,onPressOut:s,onPress:function(){return t(y)},onLongPress:S,delayLongPress:500},r.createElement(i.View,{style:ge.outer},r.createElement(i.View,{ref:n,style:ge.iconWrap,collapsable:!1},r.createElement(i.Animated.View,{style:[ge.icon,{transform:[{scale:o}]}]},r.createElement(Fe,{id:y})),r.createElement(bt,{guildId:y})),r.createElement(Ct,{guildId:y}))),r.createElement(dt,{visible:a.visible,items:a.items,title:a.title,anchorX:a.x,anchorY:a.y,onClose:function(){return g(function(f){return{...f,visible:!1}})}}))}const ge=i.StyleSheet.create({outer:{width:P},iconWrap:{width:P,height:P},icon:{width:P,height:P,borderRadius:16,overflow:"hidden"}}),wt=i.StyleSheet.create({label:{width:P,marginTop:4,fontSize:10,lineHeight:12,textAlign:"center"}}),j=i.StyleSheet.create({outline:{position:"absolute",bottom:-3,right:-3,minWidth:23,minHeight:23,borderRadius:12,backgroundColor:"#1a1a2e",alignItems:"center",justifyContent:"center"},badge:{minWidth:19,height:19,borderRadius:9,backgroundColor:"#ed4245",alignItems:"center",justifyContent:"center",paddingHorizontal:5},text:{color:"#fff",fontSize:10,fontWeight:"700",lineHeight:19},dotOutline:{position:"absolute",bottom:-2,right:-2,width:14,height:14,borderRadius:7,backgroundColor:"#1a1a2e",alignItems:"center",justifyContent:"center"},dot:{width:10,height:10,borderRadius:5,backgroundColor:"#ed4245"}}),Et=u(function(){return x("toggleGuildFolderExpand")}),St=u(function(){return b("GuildReadStateStore")}),R=48,me=16,kt=[{top:6,left:6},{top:6,right:6},{bottom:6,left:6},{bottom:6,right:6}],Be=se.getAssetIDByName("FolderIcon");function _e(e){return e==null?"#5865f2":`#${e.toString(16).padStart(6,"0")}`}function It({node:e}){const t=F(),n=St(),o=t?.useStateFromStores?.([n],function(){let l=0;for(const s of e.children)l+=n?.getMentionCount?.(s.id)??0;return l},[e.children])??0;return o>0?r.createElement(i.View,{style:ye.outline},r.createElement(i.View,{style:ye.badge},r.createElement(i.Text,{style:ye.text},o>99?"99+":String(o)))):null}function Rt({node:e}){L.useProxy(c.storage);const t=_e(e.color);return r.createElement(i.View,{style:$.outer},r.createElement(i.View,{style:[$.icon,{backgroundColor:t}]},c.storage.hideFolderIcons?r.createElement(i.View,{style:$.plainIcon},r.createElement(i.Image,{source:Be,style:pe.folderImg,tintColor:"#fff"})):e.children.slice(0,4).map(function(n,o){return r.createElement(i.View,{key:n.id,style:[$.cell,kt[o]]},r.createElement(Fe,{id:n.id,size:me}))})),r.createElement(It,{node:e}))}const $=i.StyleSheet.create({outer:{width:R,height:R},icon:{width:R,height:R,borderRadius:16,overflow:"hidden"},cell:{position:"absolute",width:me,height:me,borderRadius:8,overflow:"hidden"},plainIcon:{width:R,height:R,alignItems:"center",justifyContent:"center"}});function Tt({children:e}){const t=r.useRef(new i.Animated.Value(0)).current;return r.useEffect(function(){i.Animated.timing(t,{toValue:1,duration:180,useNativeDriver:!0}).start()},[]),r.createElement(i.Animated.View,{style:{opacity:t}},e)}function Dt({node:e,onPick:t}){const n=it(e.id),o=function(){Et()?.toggleGuildFolderExpand?.(e.id)};return n?r.createElement(r.Fragment,null,r.createElement(i.Pressable,{onPress:o},r.createElement(i.View,{style:[pe.openIcon,{backgroundColor:_e(e.color)}]},r.createElement(i.Image,{source:Be,style:pe.folderImg,tintColor:"#fff"}))),e.children.map(function(l){return r.createElement(Tt,{key:l.id},r.createElement(ve,{node:l,onPick:t}))})):r.createElement(i.Pressable,{onPress:o},r.createElement(Rt,{node:e}))}const pe=i.StyleSheet.create({openIcon:{width:R,height:R,borderRadius:16,alignItems:"center",justifyContent:"center"},folderImg:{width:24,height:24}}),ye=i.StyleSheet.create({outline:{position:"absolute",bottom:-3,right:-3,minWidth:23,minHeight:23,borderRadius:12,backgroundColor:"#1a1a2e",alignItems:"center",justifyContent:"center"},badge:{minWidth:19,height:19,borderRadius:9,backgroundColor:"#ed4245",alignItems:"center",justifyContent:"center",paddingHorizontal:5},text:{color:"#fff",fontSize:10,fontWeight:"700",lineHeight:19}}),N=48,xt=se.getAssetIDByName("ChatIcon"),Ft=u(function(){return x("selectPrivateChannel")}),At=u(function(){return Je("SelectedChannelStore")}),Vt=u(function(){return x("getGuildId")});function Ht(){const e=H();e?.triggerHapticFeedback?.(e.HapticFeedbackTypes.SOFT);const t=Ft();if(t?.selectPrivateChannel){const n=At()?.getLastSelectedChannelId?.();t.selectPrivateChannel(n)}}function Pt(){const e=F(),t=Vt(),n=Y()?.colors,o=e?.useStateFromStores?.([t],function(){return t?.getGuildId?.()==null})??!1;return r.createElement(i.Pressable,{onPress:Ht,style:Le.outer},r.createElement(i.View,{style:[Le.icon,{backgroundColor:o?n?.BG_ACCENT??"#5865f2":"rgba(128,128,128,0.24)"}]},r.createElement(i.Image,{source:xt,style:{width:24,height:24,tintColor:"#fff"}})))}const Le=i.StyleSheet.create({outer:{width:N,height:N},icon:{width:N,height:N,borderRadius:16,alignItems:"center",justifyContent:"center"}}),Oe=48,Gt=se.getAssetIDByName("CheckmarkLargeIcon"),vt=Te,Bt=u(function(){return De()?.ReadStateTypes}),_t=u(function(){return b("SortedGuildStore")}),Lt=u(function(){return b("GuildChannelStore")}),Ot=u(function(){return b("ChannelStore")});function Mt(){const e=(_t()?.getGuildsTree?.()?.root?.children??[]).filter(function(o){return o?.type!=="root"}),t=[],n=function(o){for(const l of o)l.type==="folder"?n(l.children??[]):l.id!=null&&t.push(String(l.id))};return n(e),t}function jt(){const e=vt(),t=Bt(),n=Lt(),o=Ot();if(!e?.bulkAck||t?.CHANNEL==null||!n?.getSelectableChannelIds||!n?.getVocalChannelIds){I.showToast("Couldn't find Discord's read-state action - this may be unavailable on your version.",void 0);return}const l=Mt();if(l.length===0){I.showToast("Nothing to mark as read.",void 0);return}const s=[];for(const a of l){const g=[...n.getSelectableChannelIds(a)??[],...n.getVocalChannelIds(a)??[]];for(const m of g)s.push({channelId:m,readStateType:t.CHANNEL,messageId:o?.getChannel?.(m)?.lastMessageId??null})}if(s.length===0){I.showToast("Nothing to mark as read.",void 0);return}e.bulkAck(s),I.showToast(`Marked ${s.length} channel${s.length===1?"":"s"} as read`,void 0)}function zt(){const e=r.useCallback(function(){const t=H();t?.triggerHapticFeedback?.(t.HapticFeedbackTypes.SOFT),jt()},[]);return r.createElement(i.Pressable,{onPress:e,style:Wt.outer},r.createElement(i.Image,{source:Gt,style:{width:24,height:24,tintColor:"#80848e"}}))}const Wt=i.StyleSheet.create({outer:{width:Oe,height:Oe,alignItems:"center",justifyContent:"center"}}),Ut=u(function(){return x("getRootNavigationRef")}),Qt=u(function(){return x("transitionToGuild")}),qt=u(function(){return p(function(e){return typeof e?.handleCreateJoinGuildPress=="function"})}),Xt=u(function(){return p(function(e){return e?.CirclePlusIcon})?.CirclePlusIcon}),Jt=u(function(){return p(function(e){return e?.QuestDockExternalCoordinationContext})?.QuestDockExternalCoordinationContext}),Yt=u(function(){return p(function(e){return e?.QuestDockMode?.COLLAPSED!=null})?.QuestDockMode}),Kt=u(function(){return p(function(e){return typeof e?.getName=="function"&&e.getName.length===0&&e.getName()==="SortedGuildStore"})}),ee=48,te=6,Zt=12;function $t(){const e=r.useRef(new i.Animated.Value(1)).current,t=r.useCallback(function(){i.Animated.spring(e,{toValue:.9,useNativeDriver:!0}).start()},[e]),n=r.useCallback(function(){i.Animated.spring(e,{toValue:1,useNativeDriver:!0}).start()},[e]),o=r.useCallback(function(){const a=H();a?.triggerHapticFeedback?.(a.HapticFeedbackTypes.SOFT),qt()?.handleCreateJoinGuildPress?.()},[]),l=Xt(),s=Y()?.unsafe_rawColors;return r.createElement(i.Pressable,{onPress:o,onPressIn:t,onPressOut:n},r.createElement(i.Animated.View,{style:[ne.createJoin,{backgroundColor:s?.GREEN_360,transform:[{scale:e}]}]},l?r.createElement(l,{size:"md",color:s?.WHITE}):r.createElement(i.Text,{style:[ne.createJoinFallback,{color:s?.WHITE}]},"+")))}function Nt({gestureContext:e}){L.useProxy(c.storage);const t=r.useCallback(function(h){const k=H();k?.triggerHapticFeedback?.(k.HapticFeedbackTypes.SOFT);const T=Qt();T?.transitionToGuild?T.transitionToGuild(h):Ut()?.getRootNavigationRef?.()?.navigate("guilds",{guildId:h})},[]),n=F(),o=Kt(),l=n?.useStateFromStores?.([o],function(){return(o?.getGuildsTree()?.root?.children||[]).filter(function(h){return h.type!=="root"})})??[],s=e?r.useContext(e):null,a=s?.minExpandedContentHeight,g=r.useCallback(function(h){if(!a)return;const k=h.nativeEvent.layout.height;a.get()!==k&&a.set(k)},[a]),m=Jt(),S=(m?r.useContext(m):null)?.setRestingQuestDockMode,y=s?.questDockWrapperSpecs;r.useEffect(function(){const h=Yt();if(!S||!h||!y)return;const k=i.BackHandler.addEventListener("hardwareBackPress",function(){return(y.get()?.height??56)>80?(S(h.COLLAPSED),!0):!1});return function(){return k.remove()}},[S,y]);const{width:f}=i.Dimensions.get("window"),w=Math.max(3,Math.floor((f-Zt*2+te)/(ee+te))),B=w*ee+(w-1)*te,V=Math.max(0,(f-B)/2);return r.createElement(i.View,{style:ne.alignTop},r.createElement(i.View,{ref:xe,style:{width:1,height:1}}),r.createElement(i.View,{style:[ne.grid,{paddingHorizontal:V,gap:te}],onLayout:g},!c.storage.hideDmTile&&r.createElement(Pt,null),l.map(function(h){return h.type==="folder"?r.createElement(Dt,{key:h.id,node:h,onPick:t}):r.createElement(ve,{key:h.id,node:h,onPick:t})}),r.createElement($t,null),r.createElement(zt,null)))}const ne=i.StyleSheet.create({alignTop:{flex:1,justifyContent:"flex-start",alignItems:"flex-start"},grid:{flexDirection:"row",flexWrap:"wrap",paddingTop:4,paddingBottom:16},createJoin:{width:ee,height:ee,borderRadius:16,alignItems:"center",justifyContent:"center"},createJoinFallback:{fontSize:28,fontWeight:"700",lineHeight:30}}),G="[ServerDrawer]";let be=null;function en(){return be||(be=p(function(e){return e?.QuestDockGestureContext})?.QuestDockGestureContext??null),be}function re(e){return function(t){return t?.name===e||t?.displayName===e||t?.type?.name===e||t?.type?.displayName===e}}function Ce(){return d.React.createElement(Nt,{gestureContext:en()})}function tn(e){ce(re("QuestDockContentExpanded"),function(o){J(o,Ce),console.log(G,"PATCH: QuestDockContentExpanded replaced (type detector)")});const t=p(function(o){return re("QuestDockContentExpanded")(o?.type)});if(!t?.type)return console.log(G,"WARN: QuestDockContentExpanded module not found yet (will retry)"),!1;const n=t.type;return J(n,Ce),t.type=Ce,e.push(function(){t.type=n}),console.log(G,"PATCH: QuestDockContentExpanded replaced (module mutation)"),!0}function z(e,t){ce(re(e),function(s){J(s,function(){return null}),console.log(G,`PATCH: ${e} replaced (type detector)`)});const n=p(function(s){return re(e)(s?.type)});if(!n?.type)return console.log(G,`WARN: ${e} module not found yet (will retry)`),!1;const o=n.type;function l(){return null}n.type=l;try{Object.defineProperties(n.type,Object.getOwnPropertyDescriptors(o))}catch{}return n.type.displayName=e,t.push(function(){n.type=o}),console.log(G,`PATCH: ${e} replaced (module mutation)`),!0}const Me="[ServerDrawer]";function nn(){return r.createElement(i.View,{ref:xe,style:{width:1,height:1}})}function rn(e){return e?.name==="GuildsBar"||e?.displayName==="GuildsBar"||e?.type?.name==="GuildsBar"||e?.type?.displayName==="GuildsBar"}function on(e){return ce(rn,function(t){J(t,nn),console.log(Me,"PATCH: found a real GuildsBar reference, now rendering nothing")},{persistent:!0}),e.push(function(){}),console.log(Me,"PATCH: watching for the real GuildsBar to appear"),!0}function ln(e){const t=b("ExpandedGuildFolderStore");if(!t?.getExpandedFolders)return!1;const n=function({folderId:o}){if(!c.storage.autoCollapseFolders||o==null)return;const l=t.getExpandedFolders();if(!(!(l instanceof Set)||!l.has(o)))for(const s of l)s!==o&&d.FluxDispatcher.dispatch({type:"TOGGLE_GUILD_FOLDER_EXPAND",folderId:s})};return d.FluxDispatcher.subscribe("TOGGLE_GUILD_FOLDER_EXPAND",n),e.push(function(){return d.FluxDispatcher.unsubscribe("TOGGLE_GUILD_FOLDER_EXPAND",n)}),!0}const{ScrollView:sn,View:an}=d.ReactNative;function un({children:e}){return d.React.createElement(sn,{style:{flex:1}},e,d.React.createElement(an,{style:{height:24}}))}const{View:cn,Text:dn}=d.ReactNative;function je({children:e,style:t}){return d.React.createElement(cn,{style:[{marginHorizontal:16,marginVertical:8,padding:10,borderRadius:8,borderWidth:1,borderColor:"rgba(128,128,128,0.25)"},t]},d.React.createElement(dn,{style:{fontSize:12.5,lineHeight:18,opacity:.75}},e))}const{FormSection:ze,FormSwitchRow:v}=Xe.Forms;function fn(){return L.useProxy(c.storage),d.React.createElement(un,null,d.React.createElement(je,null,"Server Drawer takes over the Quest Dock (the strip above the tab bar) to show your servers as a grid instead - tap to expand, long-press a server for its usual context menu, the chat bubble jumps to DMs, the + button creates or joins a server through Discord's own modal, and the check button marks every channel in every server as read."),d.React.createElement(ze,{title:"Layout"},d.React.createElement(v,{label:"Hide the left server rail",subLabel:"Your servers and DMs already live in the drawer, so the rail is redundant",value:c.storage.hideGuildsBar!==!1,onValueChange:function(e){c.storage.hideGuildsBar=e,Qe()}}),d.React.createElement(v,{label:"Unread badges",subLabel:"Show mention counts and unread dots on server icons in the drawer",value:c.storage.showUnreadBadges!==!1,onValueChange:function(e){c.storage.showUnreadBadges=e}}),d.React.createElement(v,{label:"Show server names",subLabel:"Word-wrapped name below each server's icon",value:c.storage.showGuildNames!==!1,onValueChange:function(e){c.storage.showGuildNames=e}}),d.React.createElement(v,{label:"Hide the DMs tile",subLabel:"Remove the DMs tile from the drawer entirely",value:!!c.storage.hideDmTile,onValueChange:function(e){c.storage.hideDmTile=e}})),d.React.createElement(ze,{title:"Folders"},d.React.createElement(v,{label:"Auto-collapse other folders",subLabel:"Opening a folder collapses any other folder that was already open",value:!!c.storage.autoCollapseFolders,onValueChange:function(e){c.storage.autoCollapseFolders=e}}),d.React.createElement(v,{label:"Hide icons in collapsed folders",subLabel:"Show a plain folder icon instead of a 4-server preview",value:!!c.storage.hideFolderIcons,onValueChange:function(e){c.storage.hideFolderIcons=e}})),d.React.createElement(je,null,"The folder options above are ported from fres621's BetterFolders - its other half (hiding icons in the native left server rail) patched a component that no longer exists in current Discord builds, so it's been rebuilt here instead, where it actually applies to what you see."))}let C=[],E;function hn(e,t){try{return t()}catch(n){return le.logger.error(`[ServerDrawer] "${e}" patch threw, skipping: ${n}`),!1}}function We(){const e={questDockContext:function(){return et(C)},expanded:function(){return tn(C)},collapsed:function(){return z("QuestDockContentCollapsed",C)},enrolledHeader:function(){return z("QuestDockEnrolledHeader",C)},unenrolledHeader:function(){return z("QuestDockUnenrolledHeader",C)},enrolledBody:function(){return z("QuestDockEnrolledBody",C)},unenrolledBody:function(){return z("QuestDockUnenrolledBody",C)},autoCollapseFolders:function(){return ln(C)},...c.storage.hideGuildsBar?{hideGuildsBar:function(){return on(C)}}:{}};$e(C);const t=new Set(Object.keys(e)),n=new Set,o=function(){for(const l of t)hn(l,e[l])&&(n.add(l),t.delete(l));t.size===0&&E&&(clearInterval(E),E=void 0)};if(o(),t.size>0){let l=0;E=setInterval(function(){o(),++l>=50&&E&&(clearInterval(E),E=void 0,t.size>0&&le.logger.error(`[ServerDrawer] Gave up waiting on: ${[...t].join(", ")}`))},200)}le.logger.log(`[ServerDrawer] onLoad: applied immediately - ${[...n].join(", ")||"none"}${t.size?`, still waiting on ${[...t].join(", ")}`:""}`)}function Ue(){E&&(clearInterval(E),E=void 0);for(const e of C)try{e()}catch{}C=[]}function Qe(){Ue(),We()}var gn={onLoad:function(){c.storage.hideGuildsBar??=!0,c.storage.showUnreadBadges??=!0,c.storage.autoCollapseFolders??=!1,c.storage.hideFolderIcons??=!1,We()},onUnload:function(){return Ue()},settings:fn};return U.default=gn,U.restart=Qe,Object.defineProperty(U,"__esModule",{value:!0}),U})({},vendetta,vendetta.plugin,vendetta.metro.common,window.React,vendetta.metro.common.ReactNative,vendetta.storage,vendetta.ui.toasts,vendetta.ui,vendetta.ui.assets,vendetta.ui.components);