Fix default conversation color overrides

This commit is contained in:
Josh Perez 2021-12-03 21:10:03 -05:00 committed by GitHub
parent 4a011b71d9
commit 2136c5311b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 23 deletions

View File

@ -81,6 +81,7 @@ import {
someSendStatus, someSendStatus,
} from '../../messages/MessageSendState'; } from '../../messages/MessageSendState';
import * as log from '../../logging/log'; import * as log from '../../logging/log';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';
const THREE_HOURS = 3 * 60 * 60 * 1000; const THREE_HOURS = 3 * 60 * 60 * 1000;
@ -464,8 +465,8 @@ export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)(
const firstAttachment = quote.attachments && quote.attachments[0]; const firstAttachment = quote.attachments && quote.attachments[0];
const conversation = getConversation(message, conversationSelector); const conversation = getConversation(message, conversationSelector);
const defaultConversationColor = const { conversationColor, customColor } =
window.Events.getDefaultConversationColor(); getConversationColorAttributes(conversation);
return { return {
authorId, authorId,
@ -474,11 +475,8 @@ export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)(
authorProfileName, authorProfileName,
authorTitle, authorTitle,
bodyRanges: processBodyRanges(quote, { conversationSelector }), bodyRanges: processBodyRanges(quote, { conversationSelector }),
conversationColor: conversationColor,
conversation.conversationColor || defaultConversationColor.color, customColor,
customColor:
conversation.customColor ||
defaultConversationColor.customColorData?.value,
isFromMe, isFromMe,
rawAttachment: firstAttachment rawAttachment: firstAttachment
? processQuoteAttachment(firstAttachment) ? processQuoteAttachment(firstAttachment)
@ -585,8 +583,8 @@ const getShallowPropsForMessage = createSelectorCreator(memoizeByRoot, isEqual)(
}); });
const contactNameColor = contactNameColorSelector(conversationId, authorId); const contactNameColor = contactNameColorSelector(conversationId, authorId);
const defaultConversationColor = const { conversationColor, customColor } =
window.Events.getDefaultConversationColor(); getConversationColorAttributes(conversation);
return { return {
canDeleteForEveryone: canDeleteForEveryone(message), canDeleteForEveryone: canDeleteForEveryone(message),
@ -594,13 +592,10 @@ const getShallowPropsForMessage = createSelectorCreator(memoizeByRoot, isEqual)(
canReply: canReply(message, ourConversationId, conversationSelector), canReply: canReply(message, ourConversationId, conversationSelector),
contact: getPropsForEmbeddedContact(message, regionCode, accountSelector), contact: getPropsForEmbeddedContact(message, regionCode, accountSelector),
contactNameColor, contactNameColor,
conversationColor: conversationColor,
conversation.conversationColor || defaultConversationColor.color,
conversationId, conversationId,
conversationType: isGroup ? 'group' : 'direct', conversationType: isGroup ? 'group' : 'direct',
customColor: customColor,
conversation.customColor ||
defaultConversationColor.customColorData?.value,
deletedForEveryone: message.deletedForEveryone || false, deletedForEveryone: message.deletedForEveryone || false,
direction: isIncoming(message) ? 'incoming' : 'outgoing', direction: isIncoming(message) ? 'incoming' : 'outgoing',
displayLimit: message.displayLimit, displayLimit: message.displayLimit,

View File

@ -11,8 +11,8 @@ import {
getConversationSelector, getConversationSelector,
getConversationsWithCustomColorSelector, getConversationsWithCustomColorSelector,
} from '../selectors/conversations'; } from '../selectors/conversations';
import { getDefaultConversationColor } from '../selectors/items';
import { getIntl } from '../selectors/user'; import { getIntl } from '../selectors/user';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';
export type SmartChatColorPickerProps = { export type SmartChatColorPickerProps = {
conversationId?: string; conversationId?: string;
@ -22,14 +22,10 @@ const mapStateToProps = (
state: StateType, state: StateType,
props: SmartChatColorPickerProps props: SmartChatColorPickerProps
): PropsDataType => { ): PropsDataType => {
const defaultConversationColor = getDefaultConversationColor(state); const conversation = props.conversationId
const colorValues = props.conversationId
? getConversationSelector(state)(props.conversationId) ? getConversationSelector(state)(props.conversationId)
: { : {};
conversationColor: defaultConversationColor.color, const colorValues = getConversationColorAttributes(conversation);
customColorId: defaultConversationColor.customColorData?.id,
customColor: defaultConversationColor.customColorData?.value,
};
const { customColors } = state.items; const { customColors } = state.items;

View File

@ -22,6 +22,7 @@ import {
} from '../selectors/badges'; } from '../selectors/badges';
import { assert } from '../../util/assert'; import { assert } from '../../util/assert';
import { SignalService as Proto } from '../../protobuf'; import { SignalService as Proto } from '../../protobuf';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';
export type SmartConversationDetailsProps = { export type SmartConversationDetailsProps = {
addMembers: (conversationIds: ReadonlyArray<string>) => Promise<void>; addMembers: (conversationIds: ReadonlyArray<string>) => Promise<void>;
@ -87,7 +88,10 @@ const mapStateToProps = (
badges, badges,
canEditGroupInfo, canEditGroupInfo,
candidateContactsToAdd, candidateContactsToAdd,
conversation, conversation: {
...conversation,
...getConversationColorAttributes(conversation),
},
getPreferredBadge: getPreferredBadgeSelector(state), getPreferredBadge: getPreferredBadgeSelector(state),
i18n: getIntl(state), i18n: getIntl(state),
isAdmin, isAdmin,

View File

@ -0,0 +1,37 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationColorType, CustomColorType } from '../types/Colors';
import type { ConversationType } from '../state/ducks/conversations';
export function getConversationColorAttributes(
conversationColors: Pick<
ConversationType,
'conversationColor' | 'customColorId' | 'customColor'
>
): {
conversationColor: ConversationColorType;
customColor: CustomColorType | undefined;
customColorId: string | undefined;
} {
const defaultConversationColor = window.Events.getDefaultConversationColor();
const conversationColor =
conversationColors.conversationColor || defaultConversationColor.color;
const customColor =
conversationColor !== 'custom'
? undefined
: conversationColors.customColor ||
defaultConversationColor.customColorData?.value;
const customColorId =
conversationColor !== 'custom'
? undefined
: conversationColors.customColorId ||
defaultConversationColor.customColorData?.id;
return {
conversationColor,
customColor,
customColorId,
};
}