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