fix(PronounDB): don't use guild pronouns in global profile modal (#1462)

This commit is contained in:
alexia 2023-07-26 01:34:51 +02:00 committed by GitHub
parent abf62f28db
commit f2c6fcaa3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -69,7 +69,7 @@ export default definePlugin({
replacement: [
{
match: /getGlobalName\(\i\);(?<=displayProfile.{0,200})/,
replace: "$&const [vcPronounce,vcPronounSource]=$self.useProfilePronouns(arguments[0].user.id);if(arguments[0].displayProfile&&vcPronounce)arguments[0].displayProfile.pronouns=vcPronounce;"
replace: "$&const [vcPronounce,vcPronounSource]=$self.useProfilePronouns(arguments[0].user.id,true);if(arguments[0].displayProfile&&vcPronounce)arguments[0].displayProfile.pronouns=vcPronounce;"
},
PRONOUN_TOOLTIP_PATCH
]

View File

@ -58,16 +58,20 @@ const bulkFetch = debounce(async () => {
}
});
function getDiscordPronouns(id: string) {
function getDiscordPronouns(id: string, useGlobalProfile: boolean = false) {
const globalPronouns = UserProfileStore.getUserProfile(id)?.pronouns;
if (useGlobalProfile) return globalPronouns;
return (
UserProfileStore.getGuildMemberProfile(id, getCurrentChannel()?.guild_id)?.pronouns
|| UserProfileStore.getUserProfile(id)?.pronouns
|| globalPronouns
);
}
export function useFormattedPronouns(id: string): PronounsWithSource {
export function useFormattedPronouns(id: string, useGlobalProfile: boolean = false): PronounsWithSource {
// Discord is so stupid you can put tons of newlines in pronouns
const discordPronouns = getDiscordPronouns(id)?.trim().replace(NewLineRe, " ");
const discordPronouns = getDiscordPronouns(id, useGlobalProfile)?.trim().replace(NewLineRe, " ");
const [result] = useAwaiter(() => fetchPronouns(id), {
fallbackValue: getCachedPronouns(id),
@ -83,8 +87,8 @@ export function useFormattedPronouns(id: string): PronounsWithSource {
return [discordPronouns, "Discord"];
}
export function useProfilePronouns(id: string): PronounsWithSource {
const pronouns = useFormattedPronouns(id);
export function useProfilePronouns(id: string, useGlobalProfile: boolean = false): PronounsWithSource {
const pronouns = useFormattedPronouns(id, useGlobalProfile);
if (!settings.store.showInProfile) return EmptyPronouns;
if (!settings.store.showSelf && id === UserStore.getCurrentUser().id) return EmptyPronouns;