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