Derive default conversation color from storage
This commit is contained in:
parent
8f4a2026e4
commit
347f542ac0
5 changed files with 32 additions and 71 deletions
|
@ -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'),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -216,6 +216,7 @@ function removeCustomColor(
|
|||
};
|
||||
|
||||
dispatch(putItem('customColors', nextCustomColors));
|
||||
resetDefaultChatColor()(dispatch, getState, null);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue