Revert "CustomUserColors: Use Usernames Now (Fix DM Colors)"

This reverts commit 054e2a0208.
This commit is contained in:
thororen1234 2025-03-06 17:14:28 -05:00
parent 23932f5f07
commit c93e74ec0c
No known key found for this signature in database
2 changed files with 16 additions and 20 deletions

View file

@ -23,8 +23,8 @@ const ColorPicker = findComponentByCodeLazy<ColorPickerProps>("#{intl::USER_SETT
const cl = classNameFactory("vc-customColors-");
export function SetColorModal({ username, modalProps }: { username: string, modalProps: ModalProps; }) {
const initialColor = parseInt(colors[username], 16) || 372735;
export function SetColorModal({ userId, modalProps }: { userId: string, modalProps: ModalProps; }) {
const initialColor = parseInt(colors[userId], 16) || 372735;
// color picker default to current color set for user (if null it's 0x05afff :3 )
const [colorPickerColor, setColorPickerColor] = useState(initialColor);
@ -41,13 +41,13 @@ export function SetColorModal({ username, modalProps }: { username: string, moda
}
async function saveUserColor() {
colors[username] = colorPickerColor.toString(16).padStart(6, "0");
colors[userId] = colorPickerColor.toString(16).padStart(6, "0");
await set(DATASTORE_KEY, colors);
modalProps.onClose();
}
async function deleteUserColor() {
delete colors[username];
delete colors[userId];
await set(DATASTORE_KEY, colors);
modalProps.onClose();
}

View file

@ -29,7 +29,7 @@ export let colors: Record<string, string> = {};
const requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}(\i\.\i\("?.+?"?\).*?).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/);
const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: { user: User; }) => {
if (user?.username == null) return;
if (user?.id == null) return;
const setCustomColorItem = (
<Menu.MenuItem
@ -37,7 +37,7 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: {
id="set-color"
action={async () => {
await requireSettingsMenu();
openModal(modalProps => <SetColorModal username={user.username} modalProps={modalProps} />);
openModal(modalProps => <SetColorModal userId={user.id} modalProps={modalProps} />);
}}
/>
);
@ -46,14 +46,14 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: {
};
export function getCustomColorString(username: string, withHash?: boolean): string | undefined {
if (!colors[username] || !Settings.plugins.CustomUserColors.enabled)
export function getCustomColorString(userId: string, withHash?: boolean): string | undefined {
if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled)
return;
if (withHash)
return `#${colors[username]}`;
return `#${colors[userId]}`;
return colors[username];
return colors[userId];
}
const settings = definePluginSettings({
@ -94,20 +94,16 @@ export default definePlugin({
predicate: () => settings.store.dmList,
find: "!1,wrapContent",
replacement: {
match: /(?<=\}=(\i).*?nameAndDecorators,)/,
replace: "style:{color:$self.colorDMList($1)},"
match: /(nameAndDecorators,)/,
replace: "$1style:{color:$self.colorDMList(arguments[0])},"
},
},
],
colorDMList(a: any): string | undefined {
const username =
typeof a?.name?.props?.children === "string"
? a.name.props.children
: a?.name?.props?.children?.props?.children?.[0]
?? null;
if (!username) return;
const colorString = getCustomColorString(username, true);
const userId = a?.subText?.props?.user?.id;
if (!userId) return;
const colorString = getCustomColorString(userId, true);
if (colorString) return colorString;
return "inherit";
},
@ -117,7 +113,7 @@ export default definePlugin({
if (a?.channel?.guild_id && !settings.store.colorInServers) return roleColor;
const color = getCustomColorString(a.message.author.username, true);
const color = getCustomColorString(a.message.author.id, true);
return color ?? roleColor ?? undefined;
}
});