aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/pronoundb
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/pronoundb')
-rw-r--r--src/plugins/pronoundb/components/PronounsProfileWrapper.tsx23
-rw-r--r--src/plugins/pronoundb/index.ts21
-rw-r--r--src/plugins/pronoundb/types.ts14
3 files changed, 36 insertions, 22 deletions
diff --git a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx
index 4d12dd5..139fb8a 100644
--- a/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx
+++ b/src/plugins/pronoundb/components/PronounsProfileWrapper.tsx
@@ -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;
}
diff --git a/src/plugins/pronoundb/index.ts b/src/plugins/pronoundb/index.ts
index 5dfeda5..121e0d6 100644
--- a/src/plugins/pronoundb/index.ts
+++ b/src/plugins/pronoundb/index.ts
@@ -44,13 +44,28 @@ export default definePlugin({
},
// Hijack the discord pronouns section (hidden without experiment) and add a wrapper around the text section
{
- find: ".headerTagUsernameNoNickname",
+ find: "currentPronouns:",
+ all: true,
replacement: {
- match: /(?<=""!==(.{1,2})&&).+?children:\1.+?(?=,)/,
- replace: "Vencord.Plugins.plugins.PronounDB.PronounsProfileWrapper(e, $1)"
+ match: /\(0,.{1,3}\.jsxs?\)\((.{1,10}),(\{[^[}]*currentPronouns:[^}]*(\w)\.pronouns[^}]*\})\)/,
+ replace: (original, PronounComponent, pronounProps, fullProps) => {
+ // UserSettings
+ if (fullProps.includes("onPronounsChange")) return original;
+
+ return `Vencord.Plugins.plugins.PronounDB.PronounsProfileWrapper(${PronounComponent}, ${pronounProps}, ${fullProps})`;
+ }
+ }
+ },
+ // Make pronouns experiment be enabled by default
+ {
+ find: "2022-01_pronouns",
+ replacement: {
+ match: "!1", // false
+ replace: "!0"
}
}
],
+
options: {
pronounsFormat: {
type: OptionType.SELECT,
diff --git a/src/plugins/pronoundb/types.ts b/src/plugins/pronoundb/types.ts
index 51e0475..9cfd77c 100644
--- a/src/plugins/pronoundb/types.ts
+++ b/src/plugins/pronoundb/types.ts
@@ -16,15 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { User } from "discord-types/general";
-
export interface UserProfileProps {
- customStatus: JSX.Element,
- displayProfile: {
- // In the future (if discord ever uses their pronouns system) this taking priority can be a plugin setting
- pronouns: string;
- };
- user: User;
+ userId: string;
+}
+
+export interface UserProfilePronounsProps {
+ currentPronouns: string | null;
+ hidePersonalInformation: boolean;
}
export interface PronounsResponse {