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