PronounDB: Fix on user profiles
This commit is contained in:
parent
8afcb8e4dd
commit
f0e6986835
3 changed files with 29 additions and 27 deletions
|
@ -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 });
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<PronounsResponse> {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue