fix irc colors for dms (#971)
* fix irc colors for dms minimum difference if the colors are 45 deg or less apart * Update .gitignore * Update .gitignore * 1000 miles --------- Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com> Co-authored-by: creations <creations@creations.works>
This commit is contained in:
parent
b59f42cd18
commit
87bcf6231e
1 changed files with 18 additions and 1 deletions
|
|
@ -22,6 +22,7 @@ import { hash as h64 } from "@intrnl/xxhash64";
|
|||
import { Devs } from "@utils/constants";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { useMemo } from "@webpack/common";
|
||||
import { UserStore } from "@webpack/common";
|
||||
|
||||
// Calculate a CSS color string based on the user ID
|
||||
function calculateNameColorForUser(id?: string) {
|
||||
|
|
@ -121,9 +122,25 @@ export default definePlugin({
|
|||
return colorString;
|
||||
}
|
||||
|
||||
return (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString)
|
||||
const dmColor = (!settings.store.applyColorOnlyToUsersWithoutColor || !colorString)
|
||||
? color
|
||||
: colorString;
|
||||
|
||||
// guarantee minimum difference in dms
|
||||
if (context?.channel?.isPrivate?.() && dmColor && userId) {
|
||||
const currentUserId = UserStore.getCurrentUser()?.id;
|
||||
if (currentUserId && userId !== currentUserId) {
|
||||
const currentUserColor = Number(h64(currentUserId) % 360n);
|
||||
const otherUserColor = Number(h64(userId) % 360n);
|
||||
const colorDiff = Math.min(Math.abs(currentUserColor - otherUserColor), 360 - Math.abs(currentUserColor - otherUserColor));
|
||||
if (colorDiff < 45) {
|
||||
const newColor = (otherUserColor + 180) % 360;
|
||||
return `hsl(${newColor}, 100%, ${settings.store.lightness}%)`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dmColor;
|
||||
},
|
||||
|
||||
calculateNameColorForListContext(context: any) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue