From 614bb904b175db2d461cf2fc127e737d0ef7530a Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Wed, 7 Feb 2024 19:51:45 -0500 Subject: [PATCH] Avoid overwriting new chat colors when adjusting conversation attributes --- ts/state/ducks/conversations.ts | 59 +++++++++++++++------------------ 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index b2f35431e0..573918b30e 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -2069,17 +2069,13 @@ function removeCustomColorOnConversations( ): ThunkAction { return async dispatch => { const conversationsToUpdate: Array = []; - // 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); } }); @@ -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({ @@ -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); } @@ -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);