@@ -67,9 +67,8 @@ export default definePlugin({
6767 find : '="SYSTEM_TAG"' ,
6868 replacement : {
6969 // Override colorString with our custom color and disable gradients if applying the custom color.
70- match : / & & n u l l ! = \i \. s e c o n d a r y C o l o r , (?< = c o l o r S t r i n g : ( \i ) .+ ?( \i ) = .+ ?) / ,
71- replace : ( m , colorString , hasGradientColors ) => `${ m } ` +
72- `vcIrcColorsDummy=[${ colorString } ,${ hasGradientColors } ]=$self.getMessageColorsVariables(arguments[0],${ hasGradientColors } ),`
70+ match : / (?< = c o l o r S t r i n g : \i , c o l o r S t r i n g s : \i , c o l o r R o l e N a m e : \i } = ) ( \i ) , / ,
71+ replace : "$self.wrapMessageColorProps($1, arguments[0]),"
7372 }
7473 } ,
7574 {
@@ -82,11 +81,26 @@ export default definePlugin({
8281 }
8382 ] ,
8483
85- getMessageColorsVariables ( context : any , hasGradientColors : boolean ) {
86- const colorString = this . calculateNameColorForMessageContext ( context ) ;
87- const originalColorString = context ?. author ?. colorString ;
84+ wrapMessageColorProps ( colorProps : { colorString : string , colorStrings ?: Record < "primaryColor" | "secondaryColor" | "tertiaryColor" , string > ; } , context : any ) {
85+ try {
86+ const colorString = this . calculateNameColorForMessageContext ( context ) ;
87+ if ( colorString === colorProps . colorString ) {
88+ return colorProps ;
89+ }
8890
89- return [ colorString , hasGradientColors && colorString === originalColorString ] ;
91+ return {
92+ ...colorProps ,
93+ colorString,
94+ colorStrings : colorProps . colorStrings && {
95+ primaryColor : colorString ,
96+ secondaryColor : undefined ,
97+ tertiaryColor : undefined
98+ }
99+ } ;
100+ } catch ( e ) {
101+ console . error ( "Failed to calculate message color strings:" , e ) ;
102+ return colorProps ;
103+ }
90104 } ,
91105
92106 calculateNameColorForMessageContext ( context : any ) {
@@ -108,16 +122,20 @@ export default definePlugin({
108122 } ,
109123
110124 calculateNameColorForListContext ( context : any ) {
111- const id = context ?. user ?. id ;
112- const colorString = context ?. colorString ;
113- const color = calculateNameColorForUser ( id ) ;
125+ try {
126+ const id = context ?. user ?. id ;
127+ const colorString = context ?. colorString ;
128+ const color = calculateNameColorForUser ( id ) ;
114129
115- if ( settings . store . applyColorOnlyInDms && ! context ?. channel ?. isPrivate ( ) ) {
116- return colorString ;
117- }
130+ if ( settings . store . applyColorOnlyInDms && ! context ?. channel ?. isPrivate ( ) ) {
131+ return colorString ;
132+ }
118133
119- return ( ! settings . store . applyColorOnlyToUsersWithoutColor || ! colorString )
120- ? color
121- : colorString ;
134+ return ( ! settings . store . applyColorOnlyToUsersWithoutColor || ! colorString )
135+ ? color
136+ : colorString ;
137+ } catch ( e ) {
138+ console . error ( "Failed to calculate name color for list context:" , e ) ;
139+ }
122140 }
123141} ) ;
0 commit comments