diff --git a/src/equicordplugins/customUserColors/index.tsx b/src/equicordplugins/customUserColors/index.tsx index 034b6187..ad7e3567 100644 --- a/src/equicordplugins/customUserColors/index.tsx +++ b/src/equicordplugins/customUserColors/index.tsx @@ -62,12 +62,8 @@ const userContextMenuPatch: NavContextMenuPatchCallback = (children, { user }: { }; export function getCustomColorString(userId: string, withHash?: boolean): string | undefined { - if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) - return; - - if (withHash) - return `#${colors[userId]}`; - + if (!colors[userId] || !Settings.plugins.CustomUserColors.enabled) return; + if (withHash) return `#${colors[userId]}`; return colors[userId]; } @@ -98,8 +94,10 @@ export default definePlugin({ // this also affects name headers in chats outside of servers find: '="SYSTEM_TAG"', replacement: { - match: /(?<=\.username.{0,50}?)style:/, - replace: "style:{color:$self.colorIfServer(arguments[0])},_style:" + // Override colorString with our custom color and disable gradients if applying the custom color. + match: /&&null!=\i\.secondaryColor,(?<=colorString:(\i).+?(\i)=.+?)/, + replace: (m, colorString, hasGradientColors) => `${m}` + + `vcCustomUserColorsDummy=[${colorString},${hasGradientColors}]=$self.getMessageColorsVariables(arguments[0],${hasGradientColors}),` }, predicate: () => !Settings.plugins.IrcColors.enabled }, @@ -134,21 +132,27 @@ export default definePlugin({ }, ], - colorDMList(a: any): string | undefined { - const userId = a?.user?.id; - if (!userId) return; - const colorString = getCustomColorString(userId, true); - if (colorString) return colorString; - return "inherit"; + getMessageColorsVariables(context: any, hasGradientColors: boolean) { + const colorString = this.colorIfServer(context); + const originalColorString = context?.author?.colorString; + + return [colorString, hasGradientColors && colorString === originalColorString]; }, - colorIfServer(a: any): string | undefined { - const roleColor = a.author?.colorString; + colorDMList(context: any): string | undefined { + const userId = context?.user?.id; + const colorString = getCustomColorString(userId, true); + return colorString ?? "inherit"; + }, - if (a?.channel?.guild_id && !settings.store.colorInServers) return roleColor; + colorIfServer(context: any): string | undefined { + const userId = context?.message?.author?.id; + const colorString = context?.author?.colorString; - const color = getCustomColorString(a.message.author.id, true); - return color ?? roleColor ?? undefined; + if (context?.channel?.guild_id && !settings.store.colorInServers) return colorString; + + const color = getCustomColorString(userId, true); + return color ?? colorString ?? undefined; }, colorInReplyingTo(a: any) { diff --git a/src/plugins/ircColors/index.ts b/src/plugins/ircColors/index.ts index 08c0bd24..500302c9 100644 --- a/src/plugins/ircColors/index.ts +++ b/src/plugins/ircColors/index.ts @@ -96,19 +96,13 @@ export default definePlugin({ const color = calculateNameColorForUser(userId); const customColor = userId && Settings.plugins.CustomUserColors.enabled ? getCustomColorString(userId, true) : null; - // Color preview in role settings - if (context?.message?.channel_id === "1337" && userId === "313337") - return customColor ?? colorString; + if ( + (context?.message?.channel_id === "1337" && userId === "313337") || + (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) || + (settings.store.applyColorOnlyToUsersWithoutColor && colorString) + ) return customColor ?? colorString; - if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) { - return customColor ?? colorString; - } - - if (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString) { - return customColor ?? color; - } else { - return customColor ?? colorString; - } + return customColor ?? color; }, calculateNameColorForListContext(context: any) { @@ -117,14 +111,11 @@ export default definePlugin({ const color = calculateNameColorForUser(id); const customColor = id && Settings.plugins.CustomUserColors.enabled ? getCustomColorString(id, true) : null; - if (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) { - return customColor ?? colorString; - } + if ( + (settings.store.applyColorOnlyInDms && !context?.channel?.isPrivate()) || + (settings.store.applyColorOnlyToUsersWithoutColor && colorString) + ) return customColor ?? colorString; - if (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString) { - return customColor ?? color; - } else { - return customColor ?? colorString; - } + return customColor ?? color; } });