Skip to content

Commit

Permalink
Merge branch 'add-mentionavatars-settings' into sqaaakoi-stable-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqaaakoi committed Jul 31, 2024
2 parents bae088c + 605eab2 commit a707d67
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/plugins/mentionAvatars/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@

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({
hideAtSymbol: {
type: OptionType.BOOLEAN,
description: "Whether the the @-symbol should be hidden.",
default: false
}
});

export default definePlugin({
name: "MentionAvatars",
description: "Shows user avatars inside mentions",
authors: [Devs.Ven],
authors: [Devs.Ven, Devs.Luna],

patches: [{
find: ".USER_MENTION)",
Expand All @@ -25,20 +34,28 @@ 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) {
if (settings.store.hideAtSymbol) return username;
return `@${username}`;
}

0 comments on commit a707d67

Please sign in to comment.