/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { isPluginEnabled } from "@api/PluginManager"; import { definePluginSettings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import alwaysExpandProfiles from "@equicordplugins/alwaysExpandProfiles"; import { Devs } from "@utils/constants"; import { fetchUserProfile, getCurrentChannel } from "@utils/discord"; import definePlugin, { OptionType } from "@utils/types"; import { User } from "@vencord/discord-types"; import { findComponentByCodeLazy } from "@webpack"; import { ContextMenuApi, Menu, UserStore } from "@webpack/common"; interface UserProfileProps { popoutProps: Record; currentUser: User; originalRenderPopout: () => React.ReactNode; } const UserProfile = findComponentByCodeLazy(".POPOUT,user"); let openAlternatePopout = false; let accountPanelRef: React.RefObject = { current: null }; const AccountPanelContextMenu = ErrorBoundary.wrap(() => { const { prioritizeServerProfile } = settings.use(["prioritizeServerProfile"]); return ( { if (isPluginEnabled(alwaysExpandProfiles.name)) { const user = await fetchUserProfile(UserStore.getCurrentUser().id, { guild_id: getCurrentChannel()?.getGuildId() }, false); return alwaysExpandProfiles.openUserModal(user!.userId); } openAlternatePopout = true; accountPanelRef.current?.click(); }} /> settings.store.prioritizeServerProfile = !prioritizeServerProfile} /> ); }, { noop: true }); const settings = definePluginSettings({ prioritizeServerProfile: { type: OptionType.BOOLEAN, description: "Prioritize Server Profile when left clicking your account panel", default: false } }); export default definePlugin({ name: "AccountPanelServerProfile", description: "Right click your account panel in the bottom left to view your profile in the current server", authors: [Devs.Nuckyz, Devs.relitrix], settings, patches: [ { find: ".WIDGETS_RTC_UPSELL_COACHMARK)", group: true, replacement: [ { match: /(\.AVATAR,children:.+?renderPopout:\((\i),\i\)=>){(.+?)}(?=,position)(?<=currentUser:(\i).+?)/, replace: (_, rest, popoutProps, originalPopout, currentUser) => `${rest}$self.UserProfile({popoutProps:${popoutProps},currentUser:${currentUser},originalRenderPopout:()=>{${originalPopout}}})` }, { match: /\.AVATAR,children:.+?onRequestClose:\(\)=>\{/, replace: "$&$self.onPopoutClose();" }, { match: /ref:(\i),style:\i(?=.{0,250}#{intl::USER_PROFILE_ACCOUNT_POPOUT_BUTTON_A11Y_LABEL})/, replace: "$&,onContextMenu:($self.grabRef($1),$self.openAccountPanelContextMenu)" } ] } ], get accountPanelRef() { return accountPanelRef; }, grabRef(ref: React.RefObject) { accountPanelRef = ref; return ref; }, openAccountPanelContextMenu(event: React.UIEvent) { ContextMenuApi.openContextMenu(event, AccountPanelContextMenu); }, onPopoutClose() { openAlternatePopout = false; }, UserProfile: ErrorBoundary.wrap(({ popoutProps, currentUser, originalRenderPopout }: UserProfileProps) => { if ( (settings.store.prioritizeServerProfile && openAlternatePopout) || (!settings.store.prioritizeServerProfile && !openAlternatePopout) ) { return originalRenderPopout(); } const currentChannel = getCurrentChannel(); if (currentChannel?.getGuildId() == null || !UserProfile.$$vencordGetWrappedComponent()) { return originalRenderPopout(); } return ( ); }, { noop: true }) });