aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/pronoundb/pronoundbUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/pronoundb/pronoundbUtils.ts')
-rw-r--r--src/plugins/pronoundb/pronoundbUtils.ts22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/plugins/pronoundb/pronoundbUtils.ts b/src/plugins/pronoundb/pronoundbUtils.ts
index c2354c3..c079e36 100644
--- a/src/plugins/pronoundb/pronoundbUtils.ts
+++ b/src/plugins/pronoundb/pronoundbUtils.ts
@@ -20,10 +20,16 @@ import { Settings } from "@api/settings";
import { VENCORD_USER_AGENT } from "@utils/constants";
import { debounce } from "@utils/debounce";
import { useAwaiter } from "@utils/misc";
+import { UserStore } from "@webpack/common";
-import { PronounsFormat } from ".";
+import { settings } from "./settings";
import { PronounCode, PronounMapping, PronounsResponse } from "./types";
+export const enum PronounsFormat {
+ Lowercase = "LOWERCASE",
+ Capitalized = "CAPITALIZED"
+}
+
// A map of cached pronouns so the same request isn't sent twice
const cache: Record<string, PronounCode> = {};
// A map of ids and callbacks that should be triggered on fetch
@@ -40,8 +46,8 @@ const bulkFetch = debounce(async () => {
}
});
-export function awaitAndFormatPronouns(id: string): string | null {
- const [result, , isPending] = useAwaiter(() => fetchPronouns(id), {
+export function useFormattedPronouns(id: string): string | null {
+ const [result] = useAwaiter(() => fetchPronouns(id), {
fallbackValue: getCachedPronouns(id),
onError: e => console.error("Fetching pronouns failed: ", e)
});
@@ -53,6 +59,16 @@ export function awaitAndFormatPronouns(id: string): string | null {
return null;
}
+export function useProfilePronouns(id: string) {
+ const pronouns = useFormattedPronouns(id);
+
+ if (!settings.store.showInProfile) return null;
+ if (!settings.store.showSelf && id === UserStore.getCurrentUser().id) return null;
+
+ return pronouns;
+}
+
+
// Gets the cached pronouns, if you're too impatient for a promise!
export function getCachedPronouns(id: string): PronounCode | null {
return cache[id] ?? null;