MoreUserTags Chat

This commit is contained in:
thororen1234 2025-05-02 21:00:56 -04:00
parent 61e75e1d89
commit 2613ec170e
No known key found for this signature in database
17 changed files with 668 additions and 228 deletions

View file

@ -18,15 +18,15 @@
import "./style.css";
import { addProfileBadge, BadgePosition, BadgeUserArgs, ProfileBadge, removeProfileBadge } from "@api/Badges";
import { addMemberListDecorator, removeMemberListDecorator } from "@api/MemberListDecorators";
import { addMessageDecoration, removeMessageDecoration } from "@api/MessageDecorations";
import { Settings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary";
import { addNicknameIcon, removeNicknameIcon } from "@api/NicknameIcons";
import { definePluginSettings, migratePluginSetting } from "@api/Settings";
import { Devs } from "@utils/constants";
import { classes } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types";
import { filters, findStoreLazy, mapMangledModuleLazy } from "@webpack";
import { PresenceStore, Tooltip, UserStore } from "@webpack/common";
import { PresenceStore, Tooltip, UserStore, useStateFromStores } from "@webpack/common";
import { User } from "discord-types/general";
export interface Session {
@ -44,10 +44,26 @@ const SessionsStore = findStoreLazy("SessionsStore") as {
getSessions(): Record<string, Session>;
};
function Icon(path: string, opts?: { viewBox?: string; width?: number; height?: number; }) {
return ({ color, tooltip, small }: { color: string; tooltip: string; small: boolean; }) => (
const { useStatusFillColor } = mapMangledModuleLazy(".concat(.5625*", {
useStatusFillColor: filters.byCode(".hex")
});
interface IconFactoryOpts {
viewBox?: string;
width?: number;
height?: number;
}
interface IconProps {
color: string;
tooltip: string;
small?: boolean;
}
function Icon(path: string, opts?: IconFactoryOpts) {
return ({ color, tooltip, small }: IconProps) => (
<Tooltip text={tooltip} >
{(tooltipProps: any) => (
{tooltipProps => (
<svg
{...tooltipProps}
height={(opts?.height ?? 20) - (small ? 3 : 0)}
@ -70,18 +86,22 @@ const Icons = {
suncord: Icon("M7 4a6 6 0 00-6 6v4a6 6 0 006 6h10a6 6 0 006-6v-4a6 6 0 00-6-6H7zm0 11a1 1 0 01-1-1v-1H5a1 1 0 010-2h1v-1a1 1 0 012 0v1h1a1 1 0 010 2H8v1a1 1 0 01-1 1zm10-4a1 1 0 100-2 1 1 0 000 2zm1 3a1 1 0 11-2 0 1 1 0 012 0zm0-2a1 1 0 102 0 1 1 0 00-2 0zm-3 1a1 1 0 110-2 1 1 0 010 2z", { viewBox: "0 0 24 24", height: 24, width: 24 }),
vencord: Icon("M14.8 2.7 9 3.1V47h3.3c1.7 0 6.2.3 10 .7l6.7.6V2l-4.2.2c-2.4.1-6.9.3-10 .5zm1.8 6.4c1 1.7-1.3 3.6-2.7 2.2C12.7 10.1 13.5 8 15 8c.5 0 1.2.5 1.6 1.1zM16 33c0 6-.4 10-1 10s-1-4-1-10 .4-10 1-10 1 4 1 10zm15-8v23.3l3.8-.7c2-.3 4.7-.6 6-.6H43V3h-2.2c-1.3 0-4-.3-6-.6L31 1.7V25z", { viewBox: "0 0 50 50" }),
};
type Platform = keyof typeof Icons;
const { useStatusFillColor } = mapMangledModuleLazy(".concat(.5625*", {
useStatusFillColor: filters.byCode(".hex")
});
interface PlatformIconProps {
platform: Platform;
status: string;
small?: boolean;
isProfile?: boolean;
}
const PlatformIcon = ({ platform, status, small }: { platform: Platform, status: string; small: boolean; }) => {
const PlatformIcon = ({ platform, status, small }: PlatformIconProps) => {
const tooltip = platform === "embedded"
? "Console"
: platform[0].toUpperCase() + platform.slice(1);
let Icon = Icons[platform] ?? Icons.desktop;
const { ConsoleIcon } = Settings.plugins.PlatformIndicators;
const { ConsoleIcon } = settings.store;
if (platform === "embedded" && ConsoleIcon === "vencord") {
Icon = Icons.vencord;
}
@ -92,159 +112,166 @@ const PlatformIcon = ({ platform, status, small }: { platform: Platform, status:
return <Icon color={useStatusFillColor(status)} tooltip={tooltip} small={small} />;
};
function ensureOwnStatus(user: User) {
if (user.id === UserStore.getCurrentUser().id) {
const sessions = SessionsStore.getSessions();
if (typeof sessions !== "object") return null;
const sortedSessions = Object.values(sessions).sort(({ status: a }, { status: b }) => {
if (a === b) return 0;
if (a === "online") return 1;
if (b === "online") return -1;
if (a === "idle") return 1;
if (b === "idle") return -1;
return 0;
});
const ownStatus = Object.values(sortedSessions).reduce((acc, curr) => {
if (curr.clientInfo.client !== "unknown")
acc[curr.clientInfo.client] = curr.status;
return acc;
}, {});
const { clientStatuses } = PresenceStore.getState();
clientStatuses[UserStore.getCurrentUser().id] = ownStatus;
function useEnsureOwnStatus(user: User) {
if (user.id !== UserStore.getCurrentUser()?.id) {
return;
}
const sessions = useStateFromStores([SessionsStore], () => SessionsStore.getSessions());
if (typeof sessions !== "object") return null;
const sortedSessions = Object.values(sessions).sort(({ status: a }, { status: b }) => {
if (a === b) return 0;
if (a === "online") return 1;
if (b === "online") return -1;
if (a === "idle") return 1;
if (b === "idle") return -1;
return 0;
});
const ownStatus = Object.values(sortedSessions).reduce((acc, curr) => {
if (curr.clientInfo.client !== "unknown")
acc[curr.clientInfo.client] = curr.status;
return acc;
}, {});
const { clientStatuses } = PresenceStore.getState();
clientStatuses[UserStore.getCurrentUser().id] = ownStatus;
}
function getBadges({ userId }: BadgeUserArgs): ProfileBadge[] {
const user = UserStore.getUser(userId);
if (!user || (user.bot && !Settings.plugins.PlatformIndicators.showBots)) return [];
ensureOwnStatus(user);
const status = PresenceStore.getState()?.clientStatuses?.[user.id] as Record<Platform, string>;
if (!status) return [];
return Object.entries(status).map(([platform, status]) => ({
component: () => (
<span className="vc-platform-indicator">
<PlatformIcon
key={platform}
platform={platform as Platform}
status={status}
small={false}
/>
</span>
),
key: `vc-platform-indicator-${platform}`
}));
interface PlatformIndicatorProps {
user: User;
isProfile?: boolean;
isMessage?: boolean;
isMemberList?: boolean;
}
const PlatformIndicator = ({ user, small = false }: { user: User; small?: boolean; }) => {
if (!user || (user.bot && !Settings.plugins.PlatformIndicators.showBots)) return null;
const PlatformIndicator = ({ user, isProfile, isMessage, isMemberList }: PlatformIndicatorProps) => {
if (user == null || user.bot) return null;
useEnsureOwnStatus(user);
ensureOwnStatus(user);
const status: Record<Platform, string> | undefined = useStateFromStores([PresenceStore], () => PresenceStore.getState()?.clientStatuses?.[user.id]);
if (status == null) {
return null;
}
const status = PresenceStore.getState()?.clientStatuses?.[user.id] as Record<Platform, string>;
if (!status) return null;
const icons = Object.entries(status).map(([platform, status]) => (
const icons = Array.from(Object.entries(status), ([platform, status]) => (
<PlatformIcon
key={platform}
platform={platform as Platform}
status={status}
small={small}
small={isProfile || isMemberList}
/>
));
if (!icons.length) return null;
if (!icons.length) {
return null;
}
return (
<span
className="vc-platform-indicator"
style={{ gap: "2px" }}
<div
className={classes("vc-platform-indicator", isProfile && "vc-platform-indicator-profile", isMessage && "vc-platform-indicator-message")}
style={{ marginLeft: isMemberList ? "4px" : undefined }}
>
{icons}
</span>
</div>
);
};
const badge: ProfileBadge = {
getBadges,
position: BadgePosition.START,
};
function toggleMemberListDecorators(enabled: boolean) {
if (enabled) {
addMemberListDecorator("PlatformIndicators", props => <PlatformIndicator user={props.user} isMemberList />);
} else {
removeMemberListDecorator("PlatformIndicators");
}
}
const indicatorLocations = {
function toggleNicknameIcons(enabled: boolean) {
if (enabled) {
addNicknameIcon("PlatformIndicators", props => <PlatformIndicator user={UserStore.getUser(props.userId)} isProfile />, 1);
} else {
removeNicknameIcon("PlatformIndicators");
}
}
function toggleMessageDecorators(enabled: boolean) {
if (enabled) {
addMessageDecoration("PlatformIndicators", props => <PlatformIndicator user={props.message?.author} isMessage />);
} else {
removeMessageDecoration("PlatformIndicators");
}
}
migratePluginSetting("PlatformIndicators", "badges", "profiles");
const settings = definePluginSettings({
list: {
description: "In the member list",
onEnable: () => addMemberListDecorator("platform-indicator", props =>
<ErrorBoundary noop>
<PlatformIndicator user={props.user} small={true} />
</ErrorBoundary>
),
onDisable: () => removeMemberListDecorator("platform-indicator")
type: OptionType.BOOLEAN,
description: "Show indicators in the member list",
default: true,
onChange: toggleMemberListDecorators
},
badges: {
description: "In user profiles, as badges",
onEnable: () => addProfileBadge(badge),
onDisable: () => removeProfileBadge(badge)
profiles: {
type: OptionType.BOOLEAN,
description: "Show indicators in user profiles",
default: true,
onChange: toggleNicknameIcons
},
messages: {
description: "Inside messages",
onEnable: () => addMessageDecoration("platform-indicator", props =>
<ErrorBoundary noop>
<PlatformIndicator user={props.message?.author} />
</ErrorBoundary>
),
onDisable: () => removeMessageDecoration("platform-indicator")
type: OptionType.BOOLEAN,
description: "Show indicators inside messages",
default: true,
onChange: toggleMessageDecorators
},
colorMobileIndicator: {
type: OptionType.BOOLEAN,
description: "Whether to make the mobile indicator match the color of the user status.",
default: true,
restartNeeded: true
},
ConsoleIcon: {
type: OptionType.SELECT,
description: "What console icon to use",
restartNeeded: true,
options: [
{
label: "Equicord",
value: "equicord",
default: true
},
{
label: "Suncord",
value: "suncord",
},
{
label: "Vencord",
value: "vencord",
},
],
}
};
function addAllIndicators() {
const settings = Settings.plugins.PlatformIndicators;
const { displayMode } = settings;
// transfer settings from the old ones, which had a select menu instead of booleans
if (displayMode) {
if (displayMode !== "both") settings[displayMode] = true;
else {
settings.list = true;
settings.badges = true;
}
settings.messages = true;
delete settings.displayMode;
}
Object.entries(indicatorLocations).forEach(([key, value]) => {
if (settings[key]) value.onEnable();
});
}
function deleteAllIndicators() {
Object.entries(indicatorLocations).forEach(([_, value]) => {
value.onDisable();
});
}
});
export default definePlugin({
name: "PlatformIndicators",
description: "Adds platform indicators (Desktop, Mobile, Web...) to users",
authors: [Devs.kemo, Devs.TheSun, Devs.Nuckyz, Devs.Ven],
dependencies: ["MessageDecorationsAPI", "MemberListDecoratorsAPI"],
dependencies: ["MemberListDecoratorsAPI", "NicknameIconsAPI", "MessageDecorationsAPI"],
settings,
start() {
addAllIndicators();
if (settings.store.list) toggleMemberListDecorators(true);
if (settings.store.profiles) toggleNicknameIcons(true);
if (settings.store.messages) toggleMessageDecorators(true);
},
stop() {
deleteAllIndicators();
if (settings.store.list) toggleMemberListDecorators(false);
if (settings.store.profiles) toggleNicknameIcons;
if (settings.store.messages) toggleMessageDecorators(false);
},
patches: [
{
find: ".Masks.STATUS_ONLINE_MOBILE",
predicate: () => Settings.plugins.PlatformIndicators.colorMobileIndicator,
predicate: () => settings.store.colorMobileIndicator,
replacement: [
{
// Return the STATUS_ONLINE_MOBILE mask if the user is on mobile, no matter the status
@ -260,7 +287,7 @@ export default definePlugin({
},
{
find: ".AVATAR_STATUS_MOBILE_16;",
predicate: () => Settings.plugins.PlatformIndicators.colorMobileIndicator,
predicate: () => settings.store.colorMobileIndicator,
replacement: [
{
// Return the AVATAR_STATUS_MOBILE size mask if the user is on mobile, no matter the status
@ -281,58 +308,12 @@ export default definePlugin({
},
{
find: "}isMobileOnline(",
predicate: () => Settings.plugins.PlatformIndicators.colorMobileIndicator,
predicate: () => settings.store.colorMobileIndicator,
replacement: {
// Make isMobileOnline return true no matter what is the user status
match: /(?<=\i\[\i\.\i\.MOBILE\])===\i\.\i\.ONLINE/,
replace: "!= null"
}
}
],
options: {
...Object.fromEntries(
Object.entries(indicatorLocations).map(([key, value]) => {
return [key, {
type: OptionType.BOOLEAN,
description: `Show indicators ${value.description.toLowerCase()}`,
// onChange doesn't give any way to know which setting was changed, so restart required
restartNeeded: true,
default: true
}];
})
),
colorMobileIndicator: {
type: OptionType.BOOLEAN,
description: "Whether to make the mobile indicator match the color of the user status.",
default: true,
restartNeeded: true
},
showBots: {
type: OptionType.BOOLEAN,
description: "Whether to show platform indicators on bots",
default: false,
restartNeeded: false
},
ConsoleIcon: {
type: OptionType.SELECT,
description: "What console icon to use",
restartNeeded: true,
options: [
{
label: "Equicord",
value: "equicord",
default: true
},
{
label: "Suncord",
value: "suncord",
},
{
label: "Vencord",
value: "vencord",
},
],
},
}
]
});

View file

@ -2,6 +2,20 @@
display: inline-flex;
justify-content: center;
align-items: center;
vertical-align: top;
position: relative;
gap: 2px;
}
.vc-platform-indicator-profile {
background: rgb(var(--bg-overlay-color) / var(--bg-overlay-opacity-6));
border: 1px solid var(--border-faint);
border-radius: var(--radius-xs);
border-color: var(--profile-body-border-color);
margin: 0 1px;
padding: 0 1px;
}
.vc-platform-indicator-message {
position: relative;
vertical-align: top;
top: 2px;
}