Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MentionAvatars: Add option to hide @ symbol #2725

Merged
merged 10 commits into from
Aug 1, 2024
24 changes: 21 additions & 3 deletions src/plugins/mentionAvatars/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@

import "./styles.css";

import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import definePlugin, { OptionType } from "@utils/types";
import { SelectedGuildStore, useState } from "@webpack/common";
import { User } from "discord-types/general";

const settings = definePluginSettings({
showAtSymbol: {
type: OptionType.BOOLEAN,
description: "Whether the the @ symbol should be displayed",
default: true
}
});

export default definePlugin({
name: "MentionAvatars",
description: "Shows user avatars inside mentions",
Expand All @@ -25,20 +34,29 @@ export default definePlugin({
}
}],

settings,

renderUsername: ErrorBoundary.wrap((props: { user: User, username: string; }) => {
const { user, username } = props;
const [isHovering, setIsHovering] = useState(false);

if (!user) return <>@{username}</>;
if (!user) return <>{getUsernameString(username)}</>;

return (
<span
onMouseEnter={() => setIsHovering(true)}
onMouseLeave={() => setIsHovering(false)}
>
<img src={user.getAvatarURL(SelectedGuildStore.getGuildId(), 16, isHovering)} className="vc-mentionAvatars-avatar" />
@{username}
{getUsernameString(username)}
</span>
);
}, { noop: true })

});

function getUsernameString(username: string) {
return settings.store.showAtSymbol
? `@${username}`
: username;
}