From 07a0ebb1d2ee15bcbf2c6ebb6a81546b968ae0c4 Mon Sep 17 00:00:00 2001 From: V Date: Fri, 30 Jun 2023 17:08:43 +0200 Subject: [PATCH] PronounDB: Fix crash when having pronouns in profile disabled --- src/plugins/pronoundb/pronoundbUtils.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/plugins/pronoundb/pronoundbUtils.ts b/src/plugins/pronoundb/pronoundbUtils.ts index d47d7d4f2..07e79a72f 100644 --- a/src/plugins/pronoundb/pronoundbUtils.ts +++ b/src/plugins/pronoundb/pronoundbUtils.ts @@ -29,6 +29,9 @@ import { PronounCode, PronounMapping, PronounsResponse } from "./types"; const UserProfileStore = findStoreLazy("UserProfileStore"); +type PronounsWithSource = [string | null, string]; +const EmptyPronouns: PronounsWithSource = [null, ""]; + export const enum PronounsFormat { Lowercase = "LOWERCASE", Capitalized = "CAPITALIZED" @@ -62,7 +65,7 @@ function getDiscordPronouns(id: string) { ); } -export function useFormattedPronouns(id: string): [string | null, string] { +export function useFormattedPronouns(id: string): PronounsWithSource { // Discord is so stupid you can put tons of newlines in pronouns const discordPronouns = getDiscordPronouns(id)?.trim().replace(NewLineRe, " "); @@ -80,11 +83,11 @@ export function useFormattedPronouns(id: string): [string | null, string] { return [discordPronouns, "Discord"]; } -export function useProfilePronouns(id: string) { +export function useProfilePronouns(id: string): PronounsWithSource { const pronouns = useFormattedPronouns(id); - if (!settings.store.showInProfile) return null; - if (!settings.store.showSelf && id === UserStore.getCurrentUser().id) return null; + if (!settings.store.showInProfile) return EmptyPronouns; + if (!settings.store.showSelf && id === UserStore.getCurrentUser().id) return EmptyPronouns; return pronouns; }