@@ -13,14 +13,18 @@ import DMRoomMap from "./utils/DMRoomMap";
1313import { mediaFromMxc } from "./customisations/Media" ;
1414import { isLocalRoom } from "./utils/localRoom/isLocalRoom" ;
1515import { getFirstGrapheme } from "./utils/strings" ;
16+ import ThemeWatcher from "./settings/watchers/ThemeWatcher" ;
1617
1718/**
1819 * Hardcoded from the Compound colors.
1920 * Shade for background as defined in the compound web implementation
2021 * https://github.com/vector-im/compound-web/blob/main/src/components/Avatar
2122 */
22- const AVATAR_BG_COLORS = [ "#e9f2ff" , "#faeefb" , "#e3f7ed" , "#ffecf0" , "#ffefe4" , "#e3f5f8" , "#f1efff" , "#e0f8d9" ] ;
23- const AVATAR_TEXT_COLORS = [ "#043894" , "#671481" , "#004933" , "#7e0642" , "#850000" , "#004077" , "#4c05b5" , "#004b00" ] ;
23+ const AVATAR_BG_LIGTH_COLORS = [ "#e0f8d9" , "#e3f5f8" , "#faeefb" , "#f1efff" , "#ffecf0" , "#ffefe4" ] ;
24+ const AVATAR_TEXT_LIGHT_COLORS = [ "#005f00" , "#00548c" , "#822198" , "#5d26cd" , "#9f0850" , "#9b2200" ] ;
25+
26+ const AVATAR_BG_DARK_COLORS = [ "#002600" , "#001b4e" , "#37004e" , "#22006a" , "#450018" , "#470000" ] ;
27+ const AVATAR_TEXT_DARK_COLORS = [ "#56c02c" , "#21bacd" , "#d991de" , "#ad9cfe" , "#fe84a2" , "#f6913d" ] ;
2428
2529// Not to be used for BaseAvatar urls as that has similar default avatar fallback already
2630export function avatarUrlForMember (
@@ -42,6 +46,13 @@ export function avatarUrlForMember(
4246 return url ;
4347}
4448
49+ /**
50+ * Determines if the current theme is dark
51+ */
52+ function isDarkTheme ( ) : boolean {
53+ return new ThemeWatcher ( ) . getEffectiveTheme ( ) === "dark" ;
54+ }
55+
4556/**
4657 * Determines the HEX color to use in the avatar pills
4758 * @param id the user or room ID
@@ -51,7 +62,8 @@ export function getAvatarTextColor(id: string): string {
5162 // eslint-disable-next-line react-hooks/rules-of-hooks
5263 const index = useIdColorHash ( id ) ;
5364
54- return AVATAR_TEXT_COLORS [ index - 1 ] ;
65+ // Use light colors by default
66+ return isDarkTheme ( ) ? AVATAR_TEXT_DARK_COLORS [ index - 1 ] : AVATAR_TEXT_LIGHT_COLORS [ index - 1 ] ;
5567}
5668
5769export function avatarUrlForUser (
@@ -103,7 +115,10 @@ export function defaultAvatarUrlForString(s: string): string {
103115 // overwritten color value in custom themes
104116 const cssVariable = `--avatar-background-colors_${ colorIndex } ` ;
105117 const cssValue = getComputedStyle ( document . body ) . getPropertyValue ( cssVariable ) ;
106- const color = cssValue || AVATAR_BG_COLORS [ colorIndex - 1 ] ;
118+ // Light colors are the default
119+ const color =
120+ cssValue || isDarkTheme ( ) ? AVATAR_BG_DARK_COLORS [ colorIndex - 1 ] : AVATAR_BG_LIGTH_COLORS [ colorIndex - 1 ] ;
121+
107122 let dataUrl = colorToDataURLCache . get ( color ) ;
108123 if ( ! dataUrl ) {
109124 // validate color as this can come from account_data
0 commit comments