Avoid overwriting new chat colors when adjusting conversation attributes

This commit is contained in:
trevor-signal 2024-02-07 19:51:45 -05:00 committed by GitHub
parent 43de83f0de
commit 614bb904b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2069,17 +2069,13 @@ function removeCustomColorOnConversations(
): ThunkAction<void, RootStateType, unknown, CustomColorRemovedActionType> { ): ThunkAction<void, RootStateType, unknown, CustomColorRemovedActionType> {
return async dispatch => { return async dispatch => {
const conversationsToUpdate: Array<ConversationAttributesType> = []; 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 => { window.getConversations().forEach(conversation => {
if (conversation.get('customColorId') === colorId) { if (conversation.get('customColorId') === colorId) {
// eslint-disable-next-line no-param-reassign conversation.set({
delete conversation.attributes.conversationColor; conversationColor: undefined,
// eslint-disable-next-line no-param-reassign customColor: undefined,
delete conversation.attributes.customColor; customColorId: undefined,
// eslint-disable-next-line no-param-reassign });
delete conversation.attributes.customColorId;
conversationsToUpdate.push(conversation.attributes); conversationsToUpdate.push(conversation.attributes);
} }
}); });
@ -2107,15 +2103,12 @@ function resetAllChatColors(): ThunkAction<
// Calling this with no args unsets all the colors in the db // Calling this with no args unsets all the colors in the db
await window.Signal.Data.updateAllConversationColors(); 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 => { window.getConversations().forEach(conversation => {
// eslint-disable-next-line no-param-reassign conversation.set({
delete conversation.attributes.conversationColor; conversationColor: undefined,
// eslint-disable-next-line no-param-reassign customColor: undefined,
delete conversation.attributes.customColor; customColorId: undefined,
// eslint-disable-next-line no-param-reassign });
delete conversation.attributes.customColorId;
}); });
dispatch({ dispatch({
@ -2296,11 +2289,9 @@ export function setVoiceNotePlaybackRate({
return async dispatch => { return async dispatch => {
const conversationModel = window.ConversationController.get(conversationId); const conversationModel = window.ConversationController.get(conversationId);
if (conversationModel) { if (conversationModel) {
if (rate === 1) { conversationModel.set({
delete conversationModel.attributes.voiceNotePlaybackRate; voiceNotePlaybackRate: rate === 1 ? undefined : rate,
} else { });
conversationModel.attributes.voiceNotePlaybackRate = rate;
}
window.Signal.Data.updateConversation(conversationModel.attributes); window.Signal.Data.updateConversation(conversationModel.attributes);
} }
@ -2332,23 +2323,27 @@ function colorSelected({
ColorSelectedActionType ColorSelectedActionType
> { > {
return async dispatch => { 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); const conversation = window.ConversationController.get(conversationId);
if (conversation) { if (conversation) {
if (conversationColor) { if (conversationColor) {
conversation.attributes.conversationColor = conversationColor; conversation.set({ conversationColor });
if (customColorData) { if (customColorData) {
conversation.attributes.customColor = customColorData.value; conversation.set({
conversation.attributes.customColorId = customColorData.id; customColor: customColorData.value,
customColorId: customColorData.id,
});
} else { } else {
delete conversation.attributes.customColor; conversation.set({
delete conversation.attributes.customColorId; customColor: undefined,
customColorId: undefined,
});
} }
} else { } else {
delete conversation.attributes.conversationColor; conversation.set({
delete conversation.attributes.customColor; conversationColor: undefined,
delete conversation.attributes.customColorId; customColor: undefined,
customColorId: undefined,
});
} }
window.Signal.Data.updateConversation(conversation.attributes); window.Signal.Data.updateConversation(conversation.attributes);