2024-07-13 17:14:22 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a Discord client mod
|
|
|
|
* Copyright (c) 2024 Vendicated and contributors
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
import "./styles.css";
|
|
|
|
|
2024-08-01 07:20:00 +00:00
|
|
|
import { definePluginSettings } from "@api/Settings";
|
2024-07-13 17:14:22 +00:00
|
|
|
import ErrorBoundary from "@components/ErrorBoundary";
|
|
|
|
import { Devs } from "@utils/constants";
|
2024-08-01 07:20:00 +00:00
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2024-07-13 17:14:22 +00:00
|
|
|
import { SelectedGuildStore, useState } from "@webpack/common";
|
|
|
|
import { User } from "discord-types/general";
|
|
|
|
|
2024-08-01 07:20:00 +00:00
|
|
|
const settings = definePluginSettings({
|
|
|
|
showAtSymbol: {
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
description: "Whether the the @ symbol should be displayed",
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-07-13 17:14:22 +00:00
|
|
|
export default definePlugin({
|
|
|
|
name: "MentionAvatars",
|
|
|
|
description: "Shows user avatars inside mentions",
|
|
|
|
authors: [Devs.Ven],
|
|
|
|
|
|
|
|
patches: [{
|
|
|
|
find: ".USER_MENTION)",
|
|
|
|
replacement: {
|
|
|
|
match: /children:"@"\.concat\((null!=\i\?\i:\i)\)(?<=\.useName\((\i)\).+?)/,
|
|
|
|
replace: "children:$self.renderUsername({username:$1,user:$2})"
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
|
2024-08-01 07:20:00 +00:00
|
|
|
settings,
|
|
|
|
|
2024-07-13 17:14:22 +00:00
|
|
|
renderUsername: ErrorBoundary.wrap((props: { user: User, username: string; }) => {
|
|
|
|
const { user, username } = props;
|
|
|
|
const [isHovering, setIsHovering] = useState(false);
|
|
|
|
|
2024-08-01 07:20:00 +00:00
|
|
|
if (!user) return <>{getUsernameString(username)}</>;
|
2024-07-13 17:14:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<span
|
|
|
|
onMouseEnter={() => setIsHovering(true)}
|
|
|
|
onMouseLeave={() => setIsHovering(false)}
|
|
|
|
>
|
|
|
|
<img src={user.getAvatarURL(SelectedGuildStore.getGuildId(), 16, isHovering)} className="vc-mentionAvatars-avatar" />
|
2024-08-01 07:20:00 +00:00
|
|
|
{getUsernameString(username)}
|
2024-07-13 17:14:22 +00:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}, { noop: true })
|
2024-08-01 07:20:00 +00:00
|
|
|
|
2024-07-13 17:14:22 +00:00
|
|
|
});
|
2024-08-01 07:20:00 +00:00
|
|
|
|
|
|
|
function getUsernameString(username: string) {
|
|
|
|
return settings.store.showAtSymbol
|
|
|
|
? `@${username}`
|
|
|
|
: username;
|
|
|
|
}
|