From f0e6986835050dca5f6a73a693ee77c299e7763c Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Fri, 23 Aug 2024 18:41:34 -0300 Subject: [PATCH] PronounDB: Fix on user profiles --- src/plugins/noProfileThemes/index.ts | 15 --------------- src/plugins/pronoundb/index.ts | 24 ++++++++++++++++++------ src/plugins/pronoundb/pronoundbUtils.ts | 17 +++++++++++------ 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/plugins/noProfileThemes/index.ts b/src/plugins/noProfileThemes/index.ts index d4737d43..7c440df8 100644 --- a/src/plugins/noProfileThemes/index.ts +++ b/src/plugins/noProfileThemes/index.ts @@ -19,7 +19,6 @@ import { Devs } from "@utils/constants"; import definePlugin from "@utils/types"; import { UserStore } from "@webpack/common"; -import virtualMerge from "virtual-merge"; export default definePlugin({ name: "NoProfileThemes", @@ -33,21 +32,7 @@ export default definePlugin({ replace: "$&$self.isCurrentUser(this.userId)&&" } }, - { - find: "UserProfileStore", - replacement: { - match: /(?<=getUserProfile\(\i\){return )(.+?)(?=})/, - replace: "$self.removeProfileThemes($1)" - } - } ], isCurrentUser: (userId: string) => userId === UserStore.getCurrentUser()?.id, - removeProfileThemes: (displayProfile: any) => { - if (displayProfile == null) return displayProfile; - - return displayProfile.userId === UserStore.getCurrentUser()?.id - ? displayProfile - : virtualMerge(displayProfile, { banner: undefined, profileEffectId: undefined }); - } }); diff --git a/src/plugins/pronoundb/index.ts b/src/plugins/pronoundb/index.ts index 51486e6e..b0c5bfe6 100644 --- a/src/plugins/pronoundb/index.ts +++ b/src/plugins/pronoundb/index.ts @@ -26,11 +26,6 @@ import { CompactPronounsChatComponentWrapper, PronounsChatComponentWrapper } fro import { useProfilePronouns } from "./pronoundbUtils"; import { settings } from "./settings"; -const PRONOUN_TOOLTIP_PATCH = { - match: /text:(.{0,10}.Messages\.USER_PROFILE_PRONOUNS)(?=,)/, - replace: '$& + (typeof vcPronounSource !== "undefined" ? ` (${vcPronounSource})` : "")' -}; - export default definePlugin({ name: "PronounDB", authors: [Devs.Tyman, Devs.TheKodeToad, Devs.Ven, Devs.Elvyra], @@ -52,7 +47,24 @@ export default definePlugin({ ] }, - // @TODO Patch discord pronoun hook in user profiles (useProfilePronouns) + { + find: ".Messages.USER_PROFILE_PRONOUNS", + group: true, + replacement: [ + { + match: /\.PANEL},/, + replace: "$&[vcPronoun,vcPronounSource,vcHasPendingPronouns]=$self.useProfilePronouns(arguments[0].user?.id)," + }, + { + match: /text:\i\.\i.Messages.USER_PROFILE_PRONOUNS/, + replace: '$&+vcHasPendingPronouns?"":` (${vcPronounSource})`' + }, + { + match: /(\.pronounsText.+?children:)(\i)/, + replace: "$1vcHasPendingPronouns?$2:vcPronoun" + } + ] + } ], settings, diff --git a/src/plugins/pronoundb/pronoundbUtils.ts b/src/plugins/pronoundb/pronoundbUtils.ts index d4fdb09d..991e9031 100644 --- a/src/plugins/pronoundb/pronoundbUtils.ts +++ b/src/plugins/pronoundb/pronoundbUtils.ts @@ -21,13 +21,16 @@ import { debounce } from "@shared/debounce"; import { VENCORD_USER_AGENT } from "@shared/vencordUserAgent"; import { getCurrentChannel } from "@utils/discord"; import { useAwaiter } from "@utils/react"; +import { findStoreLazy } from "@webpack"; import { UserProfileStore, UserStore } from "@webpack/common"; import { settings } from "./settings"; import { CachePronouns, PronounCode, PronounMapping, PronounsResponse } from "./types"; -type PronounsWithSource = [string | null, string]; -const EmptyPronouns: PronounsWithSource = [null, ""]; +const UserSettingsAccountStore = findStoreLazy("UserSettingsAccountStore"); + +type PronounsWithSource = [pronouns: string | null, source: string, hasPendingPronouns: boolean]; +const EmptyPronouns: PronounsWithSource = [null, "", false]; export const enum PronounsFormat { Lowercase = "LOWERCASE", @@ -75,13 +78,15 @@ export function useFormattedPronouns(id: string, useGlobalProfile: boolean = fal onError: e => console.error("Fetching pronouns failed: ", e) }); + const hasPendingPronouns = UserSettingsAccountStore.getPendingPronouns() != null; + if (settings.store.pronounSource === PronounSource.PreferDiscord && discordPronouns) - return [discordPronouns, "Discord"]; + return [discordPronouns, "Discord", hasPendingPronouns]; if (result && result !== PronounMapping.unspecified) - return [result, "PronounDB"]; + return [result, "PronounDB", hasPendingPronouns]; - return [discordPronouns, "Discord"]; + return [discordPronouns, "Discord", hasPendingPronouns]; } export function useProfilePronouns(id: string, useGlobalProfile: boolean = false): PronounsWithSource { @@ -147,7 +152,7 @@ async function bulkFetchPronouns(ids: string[]): Promise { } } -export function extractPronouns(pronounSet?: { [locale: string]: PronounCode[] }): string { +export function extractPronouns(pronounSet?: { [locale: string]: PronounCode[]; }): string { if (!pronounSet || !pronounSet.en) return PronounMapping.unspecified; // PronounDB returns an empty set instead of {sets: {en: ["unspecified"]}}. const pronouns = pronounSet.en;