vd-plugins/ServerDrawer/index.js
2026-07-24 10:51:55 +00:00

1 line
16 KiB
JavaScript

(function(W,s,B,n,o,Q,te){"use strict";const Ae="[ServerDrawer]";function Me(e){const t=s.findByProps("useIsMobileQuestDockRendered");if(!t?.useIsMobileQuestDockRendered)return console.log(Ae,"WARN: useIsMobileQuestDockRendered not found"),!1;const r=t.useIsMobileQuestDockRendered;return t.useIsMobileQuestDockRendered=function(...i){return r.apply(this,i),!0},e.push(function(){t.useIsMobileQuestDockRendered=r}),!0}const Qe="[ServerDrawer]";function Te(e){const t=s.findByProps("useIsMobileQuestDockRenderedBase");if(!t?.useIsMobileQuestDockRenderedBase)return console.log(Qe,"WARN: useIsMobileQuestDockRenderedBase not found"),!1;const r=t.useIsMobileQuestDockRenderedBase;return t.useIsMobileQuestDockRenderedBase=function(...i){return r.apply(this,i),!0},e.push(function(){t.useIsMobileQuestDockRenderedBase=r}),!0}const Ve="[ServerDrawer]";function Fe(e){const t=s.findByProps("useMobileQuestDock");if(!t.useMobileQuestDock)return console.log(Ve,"WARN: useMobileQuestDock not found"),!1;const r=t.useMobileQuestDock;return t.useMobileQuestDock=function(...i){return r.apply(this,i)||{id:"server-drawer",config:{quest_content_type:0,assets:{questBarHeroVideo:null,questBarHero:null},features:[]},userStatus:{enrolledAt:"2099-01-01",claimedAt:null},benefits:{rewards:[]},guildId:"0",tasks:[]}},e.push(function(){t.useMobileQuestDock=r}),!0}const Ge="[ServerDrawer]";function He(e){const t=s.findByProps("getQuestAsset");if(!t?.getQuestAsset)return console.log(Ge,"WARN: getQuestAsset not found"),!1;const r=t.getQuestAsset;return t.getQuestAsset=function(...i){try{return r.apply(this,i)}catch{return{url:null,isAnimated:!1}}},e.push(function(){t.getQuestAsset=r}),!0}const We=s.findByStoreName("GuildStore"),Le=s.findByProps("colors","unsafe_rawColors")?.colors;function ne({id:e,size:t=48}){const r=We?.getGuild(e);if(!r)return null;const i=t>=40?16:8;return r.icon?n.createElement(o.Image,{source:{uri:`https://cdn.discordapp.com/icons/${r.id}/${r.icon}.png?size=${t*2}`},style:{width:t,height:t,borderRadius:i}}):n.createElement(o.View,{style:[oe.fallback,{width:t,height:t,borderRadius:i,backgroundColor:Le?.BG_ACCENT??"#5865f2"}]},n.createElement(o.Text,{style:[oe.letter,{fontSize:Math.max(10,t*.4)}]},r.name?.split(" ").map(function(l){return l[0]}).join("").slice(0,2).toUpperCase()||"?"))}const oe=o.StyleSheet.create({fallback:{alignItems:"center",justifyContent:"center"},letter:{color:"#fff",fontWeight:"700"}}),re=s.findByProps("TextStyleSheet")?.TextStyleSheet,_e=s.findByStoreName("ThemeStore"),se=s.findByProps("colors","unsafe_rawColors"),Oe=se?.internal??se?.meta,ie=s.findByProps("triggerHapticFeedback","HapticFeedbackTypes");function T(e){const t=_e?.theme;return e&&Oe?.resolveSemanticColor(t,e)||"#000000"}const k=12,L=12,le=42,_=220,ue=4,I=16,V=20,de={tension:200,friction:20};function je({visible:e,items:t,title:r,anchorX:i,anchorY:l,onClose:c}){const{width:a,height:S}=o.Dimensions.get("window"),E=(r?L+20+ue:0)+t.length*le;let g=i,f=l+48+10;g+_>a-k&&(g=a-_-k),g<k&&(g=k),f+E>S-k&&(f=l-E-10),f<k&&(f=k);const C=T(Q.semanticColors?.BACKGROUND_SURFACE_HIGHEST),u=T(Q.semanticColors?.BORDER_SUBTLE),h=T(Q.semanticColors?.TEXT_STRONG),Z=T(Q.semanticColors?.BACKGROUND_MOD_SUBTLE),w=n.useRef(new o.Animated.Value(0)).current,R=n.useRef(new o.Animated.Value(.5)).current,p=n.useRef(new o.Animated.Value(0)).current,[v,N]=n.useState(!1),A=n.useRef(!1);n.useEffect(function(){e&&!A.current&&(N(!0),w.setValue(0),R.setValue(.5),p.setValue(0),o.Animated.parallel([o.Animated.timing(w,{toValue:1,duration:150,useNativeDriver:!0}),o.Animated.spring(R,{toValue:1,useNativeDriver:!0,...de}),o.Animated.spring(p,{toValue:1,useNativeDriver:!0,...de})]).start())},[e]);const M=n.useCallback(function(){A.current||(A.current=!0,o.Animated.parallel([o.Animated.timing(w,{toValue:0,duration:120,useNativeDriver:!0}),o.Animated.timing(R,{toValue:.8,duration:120,useNativeDriver:!0}),o.Animated.timing(p,{toValue:0,duration:120,useNativeDriver:!0})]).start(function(){A.current=!1,N(!1),c()}))},[c]);return v?n.createElement(o.Modal,{transparent:!0,visible:v,onRequestClose:M,statusBarTranslucent:!0},n.createElement(o.Pressable,{style:O.root,onPress:M},n.createElement(o.Animated.View,{style:[O.backdrop,{opacity:w}]}),n.createElement(o.Animated.View,{style:[O.container,{left:g,top:f,backgroundColor:C,borderColor:u,minWidth:_,opacity:p,transform:[{scale:R}]}]},r?n.createElement(o.View,null,n.createElement(o.Text,{style:[re?.["text-md/bold"],{color:h,paddingHorizontal:L,paddingTop:13,paddingBottom:12}]},r),n.createElement(o.View,{style:{borderBottomWidth:ue,borderBottomColor:u}})):null,t.map(function(m,y){const $=y===0&&!r,ee=y===t.length-1,Et=!!(m.iconSource||m.IconComponent);return n.createElement(o.Pressable,{key:y,style:function({pressed:Ct}){return{paddingHorizontal:L,paddingVertical:10,minHeight:le,flexDirection:"row",justifyContent:"space-between",alignItems:"center",gap:8,backgroundColor:Ct?Z:"transparent",borderTopLeftRadius:$?I:0,borderTopRightRadius:$?I:0,borderBottomLeftRadius:ee?I:0,borderBottomRightRadius:ee?I:0,borderBottomWidth:!$&&!ee?1:0,borderBottomColor:u}},onPress:function(){ie?.triggerHapticFeedback?.(ie.HapticFeedbackTypes.IMPACT_LIGHT),M(),m.action?.()}},n.createElement(o.Text,{style:[re?.["text-md/medium"],{flexShrink:1,color:h}]},m.label),Et?n.createElement(o.View,{style:{width:V,height:V,alignItems:"center",justifyContent:"center"}},m.IconComponent?n.createElement(m.IconComponent,{size:"sm",color:h}):m.iconSource?n.createElement(o.Image,{source:m.iconSource,style:{width:V,height:V,tintColor:h}}):null):null)})))):null}const O=o.StyleSheet.create({root:{flex:1},backdrop:{...o.StyleSheet.absoluteFill,backgroundColor:"rgba(0,0,0,0.55)"},container:{position:"absolute",borderWidth:1,borderRadius:I,overflow:"hidden",elevation:20,shadowColor:"#000",shadowOffset:{width:0,height:12},shadowOpacity:.24,shadowRadius:24}}),F=48,ae=s.findByProps("useStateFromStores"),G=s.findByStoreName("GuildReadStateStore"),ze=s.findByStoreName("GuildStore"),Ue=s.findByStoreName("SortedGuildStore"),ce=s.findByProps("triggerHapticFeedback","HapticFeedbackTypes");function qe({guildId:e}){const t=ae?.useStateFromStores?.([G],function(){return G?.getMentionCount?.(e)??0},[e])??0,r=ae?.useStateFromStores?.([G],function(){return G?.hasUnread?.(e)??!1},[e])??!1;return t>0?n.createElement(o.View,{style:P.outline},n.createElement(o.View,{style:P.badge},n.createElement(o.Text,{style:P.text},t>99?"99+":String(t)))):r?n.createElement(o.View,{style:P.dotOutline},n.createElement(o.View,{style:P.dot})):null}function fe({node:e,onPick:t}){const r=n.useRef(null),i=n.useRef(new o.Animated.Value(1)).current,l=function(){return o.Animated.spring(i,{toValue:.85,useNativeDriver:!0}).start()},c=function(){return o.Animated.spring(i,{toValue:1,useNativeDriver:!0}).start()},[a,S]=n.useState({visible:!1,items:[],title:"",x:0,y:0}),E=n.useCallback(function(){const C=e.id,u=ze?.getGuild?.(C),h=s.find(function(p){return p?.default?.name==="getGuildsBarGuildMenuItems"})?.default??s.find(function(p){return typeof p?.default=="function"&&p.default.length<=2&&/guild/i.test(p.default.name??"")})?.default;if(!u||!h)return;const Z=Ue?.getGuildsTree?.()?.version,w=h(C,Z);if(!w?.length)return;const R=r.current;R?.measure&&R.measure(function(p,v,N,A,M,m){S({visible:!0,items:w.map(function(y){return{label:y.label??y.title??"Unknown",action:y.action,danger:y.variant==="destructive",iconSource:y.iconSource,IconComponent:y.IconComponent}}),title:u.name,x:M,y:m})})},[e.id]),g=n.useCallback(function(){ce?.triggerHapticFeedback?.(ce.HapticFeedbackTypes.IMPACT_MEDIUM),E()},[E]),f=e.id;return n.createElement(n.Fragment,null,n.createElement(o.Pressable,{onPressIn:l,onPressOut:c,onPress:function(){return t(f)},onLongPress:g,delayLongPress:500},n.createElement(o.View,{ref:r,style:pe.outer,collapsable:!1},n.createElement(o.Animated.View,{style:[pe.icon,{transform:[{scale:i}]}]},n.createElement(ne,{id:f})),n.createElement(qe,{guildId:f}))),n.createElement(je,{visible:a.visible,items:a.items,title:a.title,anchorX:a.x,anchorY:a.y,onClose:function(){return S(function(C){return{...C,visible:!1}})}}))}const pe=o.StyleSheet.create({outer:{width:F,height:F},icon:{width:F,height:F,borderRadius:16,overflow:"hidden"}}),P=o.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"}}),Ke=s.findByProps("useStateFromStores");s.findByProps("colors","unsafe_rawColors")?.colors;const ge=s.findByStoreName("ExpandedGuildFolderStore");function Xe(e){return Ke?.useStateFromStores?.([ge],function(){const t=ge?.getExpandedFolders?.();return t instanceof Set?t.has(e):!1},[e])??!1}const Ye=s.findByProps("toggleGuildFolderExpand"),Je=s.findByProps("useStateFromStores"),he=s.findByStoreName("GuildReadStateStore"),D=48,j=16,Ze=[{top:6,left:6},{top:6,right:6},{bottom:6,left:6},{bottom:6,right:6}],ve=te.getAssetIDByName("FolderIcon");function me(e){return e==null?"#5865f2":`#${e.toString(16).padStart(6,"0")}`}function Ne({node:e}){const t=Je?.useStateFromStores?.([he],function(){let r=0;for(const i of e.children)r+=he?.getMentionCount?.(i.id)??0;return r},[e.children])??0;return t>0?n.createElement(o.View,{style:U.outline},n.createElement(o.View,{style:U.badge},n.createElement(o.Text,{style:U.text},t>99?"99+":String(t)))):null}function $e({node:e}){const t=me(e.color);return n.createElement(o.View,{style:z.outer},n.createElement(o.View,{style:[z.icon,{backgroundColor:t}]},e.children.slice(0,4).map(function(r,i){return n.createElement(o.View,{key:r.id,style:[z.cell,Ze[i]]},n.createElement(ne,{id:r.id,size:j}))})),n.createElement(Ne,{node:e}))}const z=o.StyleSheet.create({outer:{width:D,height:D},icon:{width:D,height:D,borderRadius:16,overflow:"hidden"},cell:{position:"absolute",width:j,height:j,borderRadius:8,overflow:"hidden"}});function et({children:e}){const t=n.useRef(new o.Animated.Value(0)).current;return n.useEffect(function(){o.Animated.timing(t,{toValue:1,duration:180,useNativeDriver:!0}).start()},[]),n.createElement(o.Animated.View,{style:{opacity:t}},e)}function tt({node:e,onPick:t}){const r=Xe(e.id),i=function(){Ye?.toggleGuildFolderExpand?.(e.id)};return r?n.createElement(n.Fragment,null,n.createElement(o.Pressable,{onPress:i},n.createElement(o.View,{style:[ye.openIcon,{backgroundColor:me(e.color)}]},n.createElement(o.Image,{source:ve,style:ye.folderImg,tintColor:"#fff"}))),e.children.map(function(l){return n.createElement(et,{key:l.id},n.createElement(fe,{node:l,onPick:t}))})):n.createElement(o.Pressable,{onPress:i},n.createElement($e,{node:e}))}const ye=o.StyleSheet.create({openIcon:{width:D,height:D,borderRadius:16,alignItems:"center",justifyContent:"center"},folderImg:{width:24,height:24}}),U=o.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}}),nt=s.findByStoreName("SortedGuildStore"),ot=s.findByProps("getRootNavigationRef"),be=s.findByProps("triggerHapticFeedback","HapticFeedbackTypes"),Se=s.findByProps("transitionToGuild"),rt=s.find(function(e){return e?.QuestDockExternalCoordinationContext}),Ee=rt?.QuestDockExternalCoordinationContext,Ce=s.find(function(e){return e?.QuestDockMode?.COLLAPSED!=null})?.QuestDockMode,ke=48,H=6,st=12;function we({gestureContext:e}){const t=n.useCallback(function(u){be?.triggerHapticFeedback(be.HapticFeedbackTypes.SOFT),Se?.transitionToGuild?Se.transitionToGuild(u,null):ot?.getRootNavigationRef()?.navigate("guilds",{guildId:u})},[]),r=n.useMemo(function(){return(nt?.getGuildsTree()?.root?.children||[]).filter(function(u){return u.type!=="root"})},[]),i=e?n.useContext(e):null,l=i?.minExpandedContentHeight,c=n.useCallback(function(u){if(!l)return;const h=u.nativeEvent.layout.height;l.get()!==h&&l.set(h)},[l]),a=(Ee?n.useContext(Ee):null)?.setRestingQuestDockMode,S=i?.questDockWrapperSpecs;n.useEffect(function(){if(!a||!Ce||!S)return;const u=o.BackHandler.addEventListener("hardwareBackPress",function(){return(S.get()?.height??56)>80?(a(Ce.COLLAPSED),!0):!1});return function(){return u.remove()}},[a,S]);const{width:E}=o.Dimensions.get("window"),g=Math.max(3,Math.floor((E-st*2+H)/(ke+H))),f=g*ke+(g-1)*H,C=Math.max(0,(E-f)/2);return n.createElement(o.View,{style:Re.alignTop},n.createElement(o.View,{style:[Re.grid,{paddingHorizontal:C,gap:H}],onLayout:c},r.map(function(u){return u.type==="folder"?n.createElement(tt,{key:u.id,node:u,onPick:t}):n.createElement(fe,{key:u.id,node:u,onPick:t})})))}const Re=o.StyleSheet.create({alignTop:{flex:1,justifyContent:"flex-start",alignItems:"flex-start"},grid:{flexDirection:"row",flexWrap:"wrap",paddingTop:4,paddingBottom:16}}),q=new Map;let b=null;function Be(e,t,r){q.set(e,{replacement:t,extraProps:r})}function it(e){if(b)return;b=B.React.createElement;const t=function(r,i,...l){const c=q.get(r);if(c){const a=c.extraProps?{...i,...c.extraProps}:i;return b.call(B.React,c.replacement,a,...l)}return b.call(B.React,r,i,...l)};Object.assign(t,b),B.React.createElement=t,e.push(function(){b&&(B.React.createElement=b,b=null),q.clear()})}const K="[ServerDrawer]",De=s.find(function(e){return e?.QuestDockGestureContext})?.QuestDockGestureContext;function lt(e){const t=s.find(function(i){return i?.type?.displayName==="QuestDockContentExpanded"||i?.type?.name==="QuestDockContentExpanded"});if(!t?.type)return console.log(K,"WARN: QuestDockContentExpanded not found"),!1;const r=t.type;return Be(r,we,{gestureContext:De}),t.type=function(){return B.React.createElement(we,{gestureContext:De})},e.push(function(){t.type=r}),console.log(K,"PATCH: QuestDockContentExpanded replaced"),!0}function x(e,t){const r=s.find(function(l){return l?.type?.displayName===e||l?.type?.name===e});if(!r?.type)return console.log(K,`WARN: ${e} not found`),!1;const i=r.type;return r.type=function(){return null},t.push(function(){r.type=i}),!0}const ut="[ServerDrawer]",dt=te.getAssetIDByName("ChatIcon"),Ie=s.findByProps("triggerHapticFeedback","HapticFeedbackTypes"),Pe=s.findByProps("selectPrivateChannel"),at=s.findByName("SelectedChannelStore"),ct=s.findByProps("useStateFromStores"),ft=ct?.useStateFromStores,X=s.findByProps("getGuildId"),Y=s.findByProps("colors","unsafe_rawColors")?.colors,pt=s.findByProps("ME"),gt=pt?.ME??"/channels/@me";function ht(){if(Ie?.triggerHapticFeedback(Ie.HapticFeedbackTypes.SOFT),Pe?.selectPrivateChannel){const e=at?.getLastSelectedChannelId?.();Pe.selectPrivateChannel(e)}}function mt(){try{return X?ft([X],function(){const e=X?.getGuildId?.();return e==null||e===gt}):!1}catch{return!1}}function xe(){const e=mt(),t=e?Y?.WHITE??"#fff":Y?.INTERACTIVE_NORMAL??"#80848e";return n.createElement(o.Pressable,{onPress:ht,style:{flex:1,alignItems:"center",justifyContent:"center"}},e?n.createElement(o.View,{style:{position:"absolute",left:0,top:"25%",width:4,height:"50%",borderRadius:2,backgroundColor:Y?.WHITE??"#fff"}}):null,n.createElement(o.Image,{source:dt,style:{width:28,height:28,tintColor:t}}))}function yt(){const e=s.findByName("GuildsBar");if(e)return{default:e};let t=s.find(function(r){try{return r?.default?.type?.name==="GuildsBar"}catch{return!1}});return t?.default||(t=s.find(function(r){try{return r?.default?.displayName==="GuildsBar"}catch{return!1}}),t?.default)?t:null}function bt(e){const t=yt();if(!t?.default)return console.log(ut,"WARN: GuildsBar not found"),!1;const r=t.default;return Be(r,xe),t.default=function(){return n.createElement(xe)},t.default.displayName="GuildsBar",e.push(function(){t.default=r}),!0}const J="[ServerDrawer]",d=[];var St={onLoad(){console.log(J,"onLoad");let e=0;it(d),e++,Me(d)&&e++,Te(d)&&e++,Fe(d)&&e++,He(d)&&e++,lt(d)&&e++,x("QuestDockContentCollapsed",d)&&e++,x("QuestDockEnrolledHeader",d)&&e++,x("QuestDockUnenrolledHeader",d)&&e++,x("QuestDockEnrolledBody",d)&&e++,x("QuestDockUnenrolledBody",d)&&e++,bt(d)&&e++,console.log(J,`onLoad done \u2014 ${e} patches applied, ${d.length} cleanups`)},onUnload(){console.log(J,"onUnload");for(const e of d)e();d.length=0}};return W.default=St,Object.defineProperty(W,"__esModule",{value:!0}),W})({},vendetta.metro,vendetta.metro.common,window.React,vendetta.metro.common.ReactNative,vendetta.ui,vendetta.ui.assets);