PronounDB: Fix crash when having pronouns in profile disabled

This commit is contained in:
V 2023-06-30 17:08:43 +02:00
parent f09b44b0d5
commit 07a0ebb1d2
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905

View file

@ -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;
}