From 187d06fd69c0e93b6c14fd7c874ce296848f8d03 Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:13:22 -0500 Subject: [PATCH] Fix color of quotes in chats with custom colors --- stylesheets/components/Quote.scss | 7 +++++++ ts/components/conversation/Quote.tsx | 21 ++++++++++++++++----- ts/services/backups/export.ts | 9 +++++++-- ts/util/getCustomColorStyle.ts | 6 +++--- ts/util/getHSL.ts | 4 ++-- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/stylesheets/components/Quote.scss b/stylesheets/components/Quote.scss index ab6aeec28..6f64de49c 100644 --- a/stylesheets/components/Quote.scss +++ b/stylesheets/components/Quote.scss @@ -162,6 +162,13 @@ } } +.module-quote--outgoing-custom { + .module-quote__primary, + &.module-quote__reference-warning { + border-inline-start-color: variables.$color-white; + } +} + .module-quote__primary { flex-grow: 1; padding-inline: 8px; diff --git a/ts/components/conversation/Quote.tsx b/ts/components/conversation/Quote.tsx index 8be91ecec..779dc8ccb 100644 --- a/ts/components/conversation/Quote.tsx +++ b/ts/components/conversation/Quote.tsx @@ -477,6 +477,14 @@ export function Quote(props: Props): JSX.Element | null { ); } + const customColorStyle = getCustomColorStyle(customColor, true); + + // We don't set a custom color for outgoing quotes + const borderInlineStartColor = + isIncoming || isCompose + ? customColorStyle?.borderInlineStartColor + : undefined; + function renderReferenceWarning() { if (!referencedMessageNotFound || isStoryReply) { return null; @@ -490,9 +498,7 @@ export function Quote(props: Props): JSX.Element | null { ? getClassName(`--incoming-${conversationColor}`) : getClassName(`--outgoing-${conversationColor}`) )} - style={{ - ...getCustomColorStyle(customColor, true), - }} + style={{ ...customColorStyle, borderInlineStartColor }} >
-
+
{renderAuthor()} {renderGenericFile()} {renderPayment()} diff --git a/ts/services/backups/export.ts b/ts/services/backups/export.ts index 5a957ab65..7c6740fcf 100644 --- a/ts/services/backups/export.ts +++ b/ts/services/backups/export.ts @@ -141,6 +141,7 @@ import { migrateAllMessages } from '../../messages/migrateMessageData'; import { trimBody } from '../../util/longAttachment'; import { generateBackupsSubscriberData } from '../../util/backupSubscriptionData'; import { getEnvironment, isTestEnvironment } from '../../environment'; +import { calculateLightness } from '../../util/getHSL'; const MAX_CONCURRENCY = 10; @@ -2784,10 +2785,14 @@ function checkServiceIdEquivalence( function desktopHslToRgbInt( hue: number, saturation: number, - lightness = 1 + lightness?: number ): number { // Desktop stores saturation not as 0.123 (0 to 1.0) but 12.3 (percentage) - return hslToRGBInt(hue, saturation / 100, lightness); + return hslToRGBInt( + hue, + saturation / 100, + lightness ?? calculateLightness(hue) + ); } function toGroupCallStateProto(state: CallStatus): Backups.GroupCall.State { diff --git a/ts/util/getCustomColorStyle.ts b/ts/util/getCustomColorStyle.ts index eeaaef7cc..3a7df966a 100644 --- a/ts/util/getCustomColorStyle.ts +++ b/ts/util/getCustomColorStyle.ts @@ -7,7 +7,7 @@ import { getHSL } from './getHSL'; import { getUserTheme } from '../shims/getUserTheme'; type ExtraQuotePropsType = { - borderLeftColor?: string; + borderInlineStartColor?: string; }; type BackgroundPropertyType = @@ -18,7 +18,7 @@ type BackgroundPropertyType = export function getCustomColorStyle( color?: CustomColorType, isQuote = false -): BackgroundPropertyType { +): (BackgroundPropertyType & ExtraQuotePropsType) | undefined { if (!color) { return undefined; } @@ -33,7 +33,7 @@ export function getCustomColorStyle( if (theme === ThemeType.dark) { adjustedLightness = -0.4; } - extraQuoteProps.borderLeftColor = getHSL(color.start); + extraQuoteProps.borderInlineStartColor = getHSL(color.start); } if (!color.end) { diff --git a/ts/util/getHSL.ts b/ts/util/getHSL.ts index fc35d4325..92bffd8bf 100644 --- a/ts/util/getHSL.ts +++ b/ts/util/getHSL.ts @@ -18,7 +18,7 @@ function getLightnessFromHue(hue: number, min: number, max: number) { return (percentage * (maxValue - minValue)) / 100 + minValue; } -function calculateLightness(hue: number): number { +export function calculateLightness(hue: number): number { let lightness = 45; if (hue < 60) { lightness = getLightnessFromHue(hue, 0, 60); @@ -55,7 +55,7 @@ export function getHSL( adjustedLightness = 0 ): string { return `hsl(${hue}, ${saturation}%, ${ - lightness == null + lightness == null || adjustedLightness !== 0 ? adjustLightnessValue(calculateLightness(hue), adjustedLightness) : lightness * 100 }%)`;