Skip to content

Commit

Permalink
Fix default conversation color overrides
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and josh-signal committed Dec 6, 2021
1 parent 50d4f17 commit 3fe986d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
23 changes: 9 additions & 14 deletions ts/state/selectors/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
someSendStatus,
} from '../../messages/MessageSendState';
import * as log from '../../logging/log';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';

const THREE_HOURS = 3 * 60 * 60 * 1000;

Expand Down Expand Up @@ -464,8 +465,8 @@ export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)(
const firstAttachment = quote.attachments && quote.attachments[0];
const conversation = getConversation(message, conversationSelector);

const defaultConversationColor =
window.Events.getDefaultConversationColor();
const { conversationColor, customColor } =
getConversationColorAttributes(conversation);

return {
authorId,
Expand All @@ -474,11 +475,8 @@ export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)(
authorProfileName,
authorTitle,
bodyRanges: processBodyRanges(quote, { conversationSelector }),
conversationColor:
conversation.conversationColor || defaultConversationColor.color,
customColor:
conversation.customColor ||
defaultConversationColor.customColorData?.value,
conversationColor,
customColor,
isFromMe,
rawAttachment: firstAttachment
? processQuoteAttachment(firstAttachment)
Expand Down Expand Up @@ -585,22 +583,19 @@ const getShallowPropsForMessage = createSelectorCreator(memoizeByRoot, isEqual)(
});
const contactNameColor = contactNameColorSelector(conversationId, authorId);

const defaultConversationColor =
window.Events.getDefaultConversationColor();
const { conversationColor, customColor } =
getConversationColorAttributes(conversation);

return {
canDeleteForEveryone: canDeleteForEveryone(message),
canDownload: canDownload(message, conversationSelector),
canReply: canReply(message, ourConversationId, conversationSelector),
contact: getPropsForEmbeddedContact(message, regionCode, accountSelector),
contactNameColor,
conversationColor:
conversation.conversationColor || defaultConversationColor.color,
conversationColor,
conversationId,
conversationType: isGroup ? 'group' : 'direct',
customColor:
conversation.customColor ||
defaultConversationColor.customColorData?.value,
customColor,
deletedForEveryone: message.deletedForEveryone || false,
direction: isIncoming(message) ? 'incoming' : 'outgoing',
displayLimit: message.displayLimit,
Expand Down
12 changes: 4 additions & 8 deletions ts/state/smart/ChatColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
getConversationSelector,
getConversationsWithCustomColorSelector,
} from '../selectors/conversations';
import { getDefaultConversationColor } from '../selectors/items';
import { getIntl } from '../selectors/user';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';

export type SmartChatColorPickerProps = {
conversationId?: string;
Expand All @@ -22,14 +22,10 @@ const mapStateToProps = (
state: StateType,
props: SmartChatColorPickerProps
): PropsDataType => {
const defaultConversationColor = getDefaultConversationColor(state);
const colorValues = props.conversationId
const conversation = props.conversationId
? getConversationSelector(state)(props.conversationId)
: {
conversationColor: defaultConversationColor.color,
customColorId: defaultConversationColor.customColorData?.id,
customColor: defaultConversationColor.customColorData?.value,
};
: {};
const colorValues = getConversationColorAttributes(conversation);

const { customColors } = state.items;

Expand Down
6 changes: 5 additions & 1 deletion ts/state/smart/ConversationDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../selectors/badges';
import { assert } from '../../util/assert';
import { SignalService as Proto } from '../../protobuf';
import { getConversationColorAttributes } from '../../util/getConversationColorAttributes';

export type SmartConversationDetailsProps = {
addMembers: (conversationIds: ReadonlyArray<string>) => Promise<void>;
Expand Down Expand Up @@ -87,7 +88,10 @@ const mapStateToProps = (
badges,
canEditGroupInfo,
candidateContactsToAdd,
conversation,
conversation: {
...conversation,
...getConversationColorAttributes(conversation),
},
getPreferredBadge: getPreferredBadgeSelector(state),
i18n: getIntl(state),
isAdmin,
Expand Down
37 changes: 37 additions & 0 deletions ts/util/getConversationColorAttributes.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}

0 comments on commit 3fe986d

Please sign in to comment.