Skip to content

Commit

Permalink
Avoid overwriting new chat colors when adjusting conversation attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-signal committed Feb 8, 2024
1 parent 43de83f commit 614bb90
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions ts/state/ducks/conversations.ts
Expand Up @@ -2069,17 +2069,13 @@ function removeCustomColorOnConversations(
): ThunkAction<void, RootStateType, unknown, CustomColorRemovedActionType> {
return async dispatch => {
const conversationsToUpdate: Array<ConversationAttributesType> = [];
// We don't want to trigger a model change because we're updating redux
// here manually ourselves. Au revoir Backbone!
window.getConversations().forEach(conversation => {
if (conversation.get('customColorId') === colorId) {
// eslint-disable-next-line no-param-reassign
delete conversation.attributes.conversationColor;
// eslint-disable-next-line no-param-reassign
delete conversation.attributes.customColor;
// eslint-disable-next-line no-param-reassign
delete conversation.attributes.customColorId;

conversation.set({
conversationColor: undefined,
customColor: undefined,
customColorId: undefined,
});
conversationsToUpdate.push(conversation.attributes);
}
});
Expand Down Expand Up @@ -2107,15 +2103,12 @@ function resetAllChatColors(): ThunkAction<
// Calling this with no args unsets all the colors in the db
await window.Signal.Data.updateAllConversationColors();

// We don't want to trigger a model change because we're updating redux
// here manually ourselves. Au revoir Backbone!
window.getConversations().forEach(conversation => {
// eslint-disable-next-line no-param-reassign
delete conversation.attributes.conversationColor;
// eslint-disable-next-line no-param-reassign
delete conversation.attributes.customColor;
// eslint-disable-next-line no-param-reassign
delete conversation.attributes.customColorId;
conversation.set({
conversationColor: undefined,
customColor: undefined,
customColorId: undefined,
});
});

dispatch({
Expand Down Expand Up @@ -2296,11 +2289,9 @@ export function setVoiceNotePlaybackRate({
return async dispatch => {
const conversationModel = window.ConversationController.get(conversationId);
if (conversationModel) {
if (rate === 1) {
delete conversationModel.attributes.voiceNotePlaybackRate;
} else {
conversationModel.attributes.voiceNotePlaybackRate = rate;
}
conversationModel.set({
voiceNotePlaybackRate: rate === 1 ? undefined : rate,
});
window.Signal.Data.updateConversation(conversationModel.attributes);
}

Expand Down Expand Up @@ -2332,23 +2323,27 @@ function colorSelected({
ColorSelectedActionType
> {
return async dispatch => {
// We don't want to trigger a model change because we're updating redux
// here manually ourselves. Au revoir Backbone!
const conversation = window.ConversationController.get(conversationId);
if (conversation) {
if (conversationColor) {
conversation.attributes.conversationColor = conversationColor;
conversation.set({ conversationColor });
if (customColorData) {
conversation.attributes.customColor = customColorData.value;
conversation.attributes.customColorId = customColorData.id;
conversation.set({
customColor: customColorData.value,
customColorId: customColorData.id,
});
} else {
delete conversation.attributes.customColor;
delete conversation.attributes.customColorId;
conversation.set({
customColor: undefined,
customColorId: undefined,
});
}
} else {
delete conversation.attributes.conversationColor;
delete conversation.attributes.customColor;
delete conversation.attributes.customColorId;
conversation.set({
conversationColor: undefined,
customColor: undefined,
customColorId: undefined,
});
}

window.Signal.Data.updateConversation(conversation.attributes);
Expand Down

0 comments on commit 614bb90

Please sign in to comment.