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-"); const cl = classNameFactory("vc-customColors-");
export function SetColorModal({ username, modalProps }: { username: string, modalProps: ModalProps; }) { export function SetColorModal({ userId, modalProps }: { userId: string, modalProps: ModalProps; }) {
const initialColor = parseInt(colors[username], 16) || 372735; const initialColor = parseInt(colors[userId], 16) || 372735;
// color picker default to current color set for user (if null it's 0x05afff :3 ) // color picker default to current color set for user (if null it's 0x05afff :3 )
const [colorPickerColor, setColorPickerColor] = useState(initialColor); const [colorPickerColor, setColorPickerColor] = useState(initialColor);
@ -41,13 +41,13 @@ export function SetColorModal({ username, modalProps }: { username: string, moda
} }
async function saveUserColor() { async function saveUserColor() {
colors[username] = colorPickerColor.toString(16).padStart(6, "0"); colors[userId] = colorPickerColor.toString(16).padStart(6, "0");
await set(DATASTORE_KEY, colors); await set(DATASTORE_KEY, colors);
modalProps.onClose(); modalProps.onClose();
} }
async function deleteUserColor() { async function deleteUserColor() {
delete colors[username]; delete colors[userId];
await set(DATASTORE_KEY, colors); await set(DATASTORE_KEY, colors);
modalProps.onClose(); 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 requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}(\i\.\i\("?.+?"?\).*?).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/);
const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: { user: User; }) => { const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: { user: User; }) => {
if (user?.username == null) return; if (user?.id == null) return;
const setCustomColorItem = ( const setCustomColorItem = (
<Menu.MenuItem <Menu.MenuItem
@ -37,7 +37,7 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: {
id="set-color" id="set-color"
action={async () => { action={async () => {
await requireSettingsMenu(); 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 { export function getCustomColorString(userId: string, withHash?: boolean): string | undefined {
if (!colors[username] || !Settings.plugins.CustomUserColors.enabled) if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled)
return; return;
if (withHash) if (withHash)
return `#${colors[username]}`; return `#${colors[userId]}`;
return colors[username]; return colors[userId];
} }
const settings = definePluginSettings({ const settings = definePluginSettings({
@ -94,20 +94,16 @@ export default definePlugin({
predicate: () => settings.store.dmList, predicate: () => settings.store.dmList,
find: "!1,wrapContent", find: "!1,wrapContent",
replacement: { replacement: {
match: /(?<=\}=(\i).*?nameAndDecorators,)/, match: /(nameAndDecorators,)/,
replace: "style:{color:$self.colorDMList($1)}," replace: "$1style:{color:$self.colorDMList(arguments[0])},"
}, },
}, },
], ],
colorDMList(a: any): string | undefined { colorDMList(a: any): string | undefined {
const username = const userId = a?.subText?.props?.user?.id;
typeof a?.name?.props?.children === "string" if (!userId) return;
? a.name.props.children const colorString = getCustomColorString(userId, true);
: a?.name?.props?.children?.props?.children?.[0]
?? null;
if (!username) return;
const colorString = getCustomColorString(username, true);
if (colorString) return colorString; if (colorString) return colorString;
return "inherit"; return "inherit";
}, },
@ -117,7 +113,7 @@ export default definePlugin({
if (a?.channel?.guild_id && !settings.store.colorInServers) return roleColor; 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; return color ?? roleColor ?? undefined;
} }
}); });