diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index f224b74be3..bdd860f29f 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -4690,18 +4690,14 @@ export class ConversationModel extends window.Backbone return migrateColor(this.get('color')); } - getConversationColor(): ConversationColorType { - const defaultConversationColor = window.Events.getDefaultConversationColor(); - - return this.get('conversationColor') || defaultConversationColor.color; + getConversationColor(): ConversationColorType | undefined { + return this.get('conversationColor'); } getCustomColorData(): { customColor?: CustomColorType; customColorId?: string; } { - const defaultConversationColor = window.Events.getDefaultConversationColor(); - if (this.getConversationColor() !== 'custom') { return { customColor: undefined, @@ -4710,12 +4706,8 @@ export class ConversationModel extends window.Backbone } return { - customColor: - this.get('customColor') || - defaultConversationColor.customColorData?.value, - customColorId: - this.get('customColorId') || - defaultConversationColor.customColorData?.id, + customColor: this.get('customColor'), + customColorId: this.get('customColorId'), }; } diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 533cc0ed98..c4e6dba0d6 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -32,8 +32,6 @@ import { AvatarColorType, ConversationColorType, CustomColorType, - DefaultConversationColorType, - DEFAULT_CONVERSATION_COLOR, } from '../../types/Colors'; import { LastMessageStatus, @@ -409,7 +407,6 @@ type CustomColorRemovedActionType = { type: typeof CUSTOM_COLOR_REMOVED; payload: { colorId: string; - defaultConversationColor: DefaultConversationColorType; }; }; type SetPreJoinConversationActionType = { @@ -987,16 +984,10 @@ function removeCustomColorOnConversations( await window.Signal.Data.updateConversations(conversationsToUpdate); } - const defaultConversationColor = window.storage.get( - 'defaultConversationColor', - DEFAULT_CONVERSATION_COLOR - ); - dispatch({ type: CUSTOM_COLOR_REMOVED, payload: { colorId, - defaultConversationColor, }, }); }; @@ -1023,16 +1014,11 @@ function resetAllChatColors(): ThunkAction< delete conversation.attributes.customColorId; }); - const defaultConversationColor = window.storage.get( - 'defaultConversationColor', - DEFAULT_CONVERSATION_COLOR - ); - dispatch({ type: COLORS_CHANGED, payload: { - conversationColor: defaultConversationColor.color, - customColorData: defaultConversationColor.customColorData, + conversationColor: undefined, + customColorData: undefined, }, }); }; @@ -3046,7 +3032,7 @@ export function reducer( if (action.type === CUSTOM_COLOR_REMOVED) { const { conversationLookup } = state; - const { colorId, defaultConversationColor } = action.payload; + const { colorId } = action.payload; const nextState = { ...state, @@ -3061,9 +3047,9 @@ export function reducer( const changed = { ...existing, - conversationColor: defaultConversationColor.color, - customColor: defaultConversationColor.customColorData?.value, - customColorId: defaultConversationColor.customColorData?.id, + conversationColor: undefined, + customColor: undefined, + customColorId: undefined, }; Object.assign( diff --git a/ts/state/ducks/items.ts b/ts/state/ducks/items.ts index 8f7f12a77a..8c93fbeaf8 100644 --- a/ts/state/ducks/items.ts +++ b/ts/state/ducks/items.ts @@ -216,6 +216,7 @@ function removeCustomColor( }; dispatch(putItem('customColors', nextCustomColors)); + resetDefaultChatColor()(dispatch, getState, null); }; } diff --git a/ts/state/selectors/message.ts b/ts/state/selectors/message.ts index 0f7d49e3a9..91f02eb3fd 100644 --- a/ts/state/selectors/message.ts +++ b/ts/state/selectors/message.ts @@ -44,7 +44,6 @@ import { } from '../../types/EmbeddedContact'; import { AssertProps, BodyRangesType } from '../../types/Util'; import { LinkPreviewType } from '../../types/message/LinkPreviews'; -import { ConversationColors } from '../../types/Colors'; import { CallMode } from '../../types/Calling'; import { SignalService as Proto } from '../../protobuf'; import { AttachmentType, isVoiceMessage } from '../../types/Attachment'; @@ -428,6 +427,8 @@ export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)( const firstAttachment = quote.attachments && quote.attachments[0]; const conversation = getConversation(message, conversationSelector); + const defaultConversationColor = window.Events.getDefaultConversationColor(); + return { authorId, authorName, @@ -436,8 +437,10 @@ export const getPropsForQuote = createSelectorCreator(memoizeByRoot, isEqual)( authorTitle, bodyRanges: processBodyRanges(quote, { conversationSelector }), conversationColor: - conversation.conversationColor ?? ConversationColors[0], - customColor: conversation.customColor, + conversation.conversationColor || defaultConversationColor.color, + customColor: + conversation.customColor || + defaultConversationColor.customColorData?.value, isFromMe, rawAttachment: firstAttachment ? processQuoteAttachment(firstAttachment) @@ -546,6 +549,8 @@ const getShallowPropsForMessage = createSelectorCreator(memoizeByRoot, isEqual)( author.id ); + const defaultConversationColor = window.Events.getDefaultConversationColor(); + return { canDeleteForEveryone: canDeleteForEveryone(message), canDownload: canDownload(message, conversationSelector), @@ -553,10 +558,12 @@ const getShallowPropsForMessage = createSelectorCreator(memoizeByRoot, isEqual)( contact: getPropsForEmbeddedContact(message, regionCode, accountSelector), contactNameColor, conversationColor: - conversation?.conversationColor ?? ConversationColors[0], + conversation.conversationColor || defaultConversationColor.color, conversationId, conversationType: isGroup ? 'group' : 'direct', - customColor: conversation?.customColor, + customColor: + conversation.customColor || + defaultConversationColor.customColorData?.value, deletedForEveryone: message.deletedForEveryone || false, direction: isIncoming(message) ? 'incoming' : 'outgoing', expirationLength, diff --git a/ts/test-electron/state/ducks/conversations_test.ts b/ts/test-electron/state/ducks/conversations_test.ts index 1873cb8754..fcc3fa29ef 100644 --- a/ts/test-electron/state/ducks/conversations_test.ts +++ b/ts/test-electron/state/ducks/conversations_test.ts @@ -1777,9 +1777,6 @@ describe('both/state/ducks/conversations', () => { }); it('resetAllChatColors', async () => { - window.storage.put('defaultConversationColor', { - color: 'crimson', - }); const dispatch = sinon.spy(); await resetAllChatColors()(dispatch, getState, null); @@ -1787,37 +1784,15 @@ describe('both/state/ducks/conversations', () => { const nextState = reducer(getState().conversations, action); sinon.assert.calledOnce(dispatch); - assert.equal( - nextState.conversationLookup.abc.conversationColor, - 'crimson' - ); - assert.equal( - nextState.conversationLookup.def.conversationColor, - 'crimson' - ); - assert.equal( - nextState.conversationLookup.ghi.conversationColor, - 'crimson' - ); - assert.equal( - nextState.conversationLookup.jkl.conversationColor, - 'crimson' - ); - assert.equal( - nextState.conversationsByUuid.abc.conversationColor, - 'crimson' - ); - assert.equal( - nextState.conversationsByUuid.def.conversationColor, - 'crimson' - ); - assert.equal( - nextState.conversationsByE164.ghi.conversationColor, - 'crimson' - ); - assert.equal( - nextState.conversationsByGroupId.jkl.conversationColor, - 'crimson' + assert.isUndefined(nextState.conversationLookup.abc.conversationColor); + assert.isUndefined(nextState.conversationLookup.def.conversationColor); + assert.isUndefined(nextState.conversationLookup.ghi.conversationColor); + assert.isUndefined(nextState.conversationLookup.jkl.conversationColor); + assert.isUndefined(nextState.conversationsByUuid.abc.conversationColor); + assert.isUndefined(nextState.conversationsByUuid.def.conversationColor); + assert.isUndefined(nextState.conversationsByE164.ghi.conversationColor); + assert.isUndefined( + nextState.conversationsByGroupId.jkl.conversationColor ); window.storage.remove('defaultConversationColor'); });