diff options
author | Vendicated <vendicated@riseup.net> | 2023-04-28 19:15:07 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2023-04-28 19:15:07 +0200 |
commit | 7b13b9a53ea92c337b9840c0050c6a47266efdcc (patch) | |
tree | 571d091ac132e719221e7a1230e41153e1469406 /src/plugins/pronoundb/components | |
parent | 1b2cb52dac86bc97fc42b3b040460cff68c9bf0a (diff) | |
download | Vencord-7b13b9a53ea92c337b9840c0050c6a47266efdcc.tar.gz Vencord-7b13b9a53ea92c337b9840c0050c6a47266efdcc.tar.bz2 Vencord-7b13b9a53ea92c337b9840c0050c6a47266efdcc.zip |
PronounDB: Fix not working in profiles
Diffstat (limited to 'src/plugins/pronoundb/components')
-rw-r--r-- | src/plugins/pronoundb/components/PronounsChatComponent.tsx | 51 | ||||
-rw-r--r-- | src/plugins/pronoundb/components/PronounsProfileWrapper.tsx | 61 |
2 files changed, 22 insertions, 90 deletions
diff --git a/src/plugins/pronoundb/components/PronounsChatComponent.tsx b/src/plugins/pronoundb/components/PronounsChatComponent.tsx index 70a2bf3..e302676 100644 --- a/src/plugins/pronoundb/components/PronounsChatComponent.tsx +++ b/src/plugins/pronoundb/components/PronounsChatComponent.tsx @@ -16,66 +16,59 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Settings } from "@api/settings"; import { classes } from "@utils/misc"; import { findByPropsLazy } from "@webpack"; import { UserStore } from "@webpack/common"; import { Message } from "discord-types/general"; -import { awaitAndFormatPronouns } from "../pronoundbUtils"; +import { useFormattedPronouns } from "../pronoundbUtils"; +import { settings } from "../settings"; const styles: Record<string, string> = findByPropsLazy("timestampInline"); function shouldShow(message: Message): boolean { - // Respect showInMessages - if (!Settings.plugins.PronounDB.showInMessages) + if (!settings.store.showInMessages) return false; - // Don't bother fetching bot or system users if (message.author.bot || message.author.system) return false; - // Respect showSelf options - if (!Settings.plugins.PronounDB.showSelf && message.author.id === UserStore.getCurrentUser().id) + if (!settings.store.showSelf && message.author.id === UserStore.getCurrentUser().id) return false; return true; } export function PronounsChatComponentWrapper({ message }: { message: Message; }) { - if (!shouldShow(message)) - return null; - - return <PronounsChatComponent message={message} />; + return shouldShow(message) + ? <PronounsChatComponent message={message} /> + : null; } export function CompactPronounsChatComponentWrapper({ message }: { message: Message; }) { - if (!shouldShow(message)) - return null; - - return <CompactPronounsChatComponent message={message} />; + return shouldShow(message) + ? <CompactPronounsChatComponent message={message} /> + : null; } function PronounsChatComponent({ message }: { message: Message; }) { - const result = awaitAndFormatPronouns(message.author.id); - if (result != null) { - return ( + const result = useFormattedPronouns(message.author.id); + + return result + ? ( <span className={classes(styles.timestampInline, styles.timestamp)} >• {result}</span> - ); - } - - return null; + ) + : null; } export function CompactPronounsChatComponent({ message }: { message: Message; }) { - const result = awaitAndFormatPronouns(message.author.id); - if (result != null) { - return ( + const result = useFormattedPronouns(message.author.id); + + return result + ? ( <span className={classes(styles.timestampInline, styles.timestamp, "vc-pronoundb-compact")} >• {result}</span> - ); - } - - return null; + ) + : null; } diff --git a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx deleted file mode 100644 index 34cfab5..0000000 --- a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Vencord, a modification for Discord's desktop app - * Copyright (c) 2022 Vendicated and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ - -import { Settings } from "@api/settings"; -import { UserStore } from "@webpack/common"; - -import { awaitAndFormatPronouns } from "../pronoundbUtils"; -import { UserProfilePronounsProps, UserProfileProps } from "../types"; - -export default function PronounsProfileWrapper(PronounsComponent: React.ElementType<UserProfilePronounsProps>, props: UserProfilePronounsProps, profileProps: UserProfileProps) { - const user = UserStore.getUser(profileProps.userId) ?? {}; - // Respect showInProfile - if (!Settings.plugins.PronounDB.showInProfile) - return null; - // Don't bother fetching bot or system users - if (user.bot || user.system) - return null; - // Respect showSelf options - if (!Settings.plugins.PronounDB.showSelf && user.id === UserStore.getCurrentUser().id) - return null; - - return <ProfilePronouns - userId={profileProps.userId} - Component={PronounsComponent} - leProps={props} - />; -} - -function ProfilePronouns( - { userId, Component, leProps }: { - userId: string; - Component: React.ElementType<UserProfilePronounsProps>; - leProps: UserProfilePronounsProps; - } -) { - const result = awaitAndFormatPronouns(userId); - - // If the promise completed, the result was not "unspecified", and there is a mapping for the code, then render - if (result != null) { - // First child is the header, second is a div with the actual text - leProps.currentPronouns ||= result; - return <Component {...leProps} />; - } - - return null; -} |