fix(plugins): PronounDB, ViewIcons, WebhookTags, NoBlockedMessages, BetterGifAltText, MessageAccessories

This commit is contained in:
Vendicated 2022-11-11 16:14:05 +01:00
parent f3aba3edb0
commit 1176896a1b
No known key found for this signature in database
GPG key ID: EC781ADFB93EFFA3
10 changed files with 86 additions and 44 deletions

View file

@ -20,27 +20,28 @@ import { useAwaiter } from "../../../utils/misc";
import { Settings } from "../../../Vencord";
import { UserStore } from "../../../webpack/common";
import { fetchPronouns, formatPronouns } from "../pronoundbUtils";
import { PronounMapping, UserProfileProps } from "../types";
import { PronounMapping, UserProfilePronounsProps, UserProfileProps } from "../types";
export default function PronounsProfileWrapper(props: UserProfileProps, pronounsComponent: JSX.Element) {
export default function PronounsProfileWrapper(PronounsComponent: React.ElementType<UserProfilePronounsProps>, props: UserProfilePronounsProps, profileProps: UserProfileProps) {
const user = UserStore.getUser(profileProps.userId) ?? {};
// Don't bother fetching bot or system users
if (props.user.bot || props.user.system) return null;
if (user.bot || user.system) return null;
// Respect showSelf options
if (!Settings.plugins.PronounDB.showSelf && props.user.id === UserStore.getCurrentUser().id) return null;
if (!Settings.plugins.PronounDB.showSelf && user.id === UserStore.getCurrentUser().id)
return null;
const [result, , isPending] = useAwaiter(
() => fetchPronouns(props.user.id),
() => fetchPronouns(user.id),
null,
e => console.error("Fetching pronouns failed: ", e)
);
// If the promise completed, the result was not "unspecified", and there is a mapping for the code, then return a span with the pronouns
// If the promise completed, the result was not "unspecified", and there is a mapping for the code, then render
if (!isPending && result && result !== "unspecified" && PronounMapping[result]) {
// First child is the header, second is a div with the actual text
const [, pronounsBodyComponent] = pronounsComponent.props.children as [JSX.Element, JSX.Element];
pronounsBodyComponent.props.children = formatPronouns(result);
return pronounsComponent;
props.currentPronouns ||= formatPronouns(result);
return <PronounsComponent {...props} />;
}
// Otherwise, return null so nothing else is rendered
else return null;
return null;
}