diff --git a/lib/reducers/message-reducer.js b/lib/reducers/message-reducer.js --- a/lib/reducers/message-reducer.js +++ b/lib/reducers/message-reducer.js @@ -76,7 +76,6 @@ type ReplaceMessageOperation, type MessageStoreOperation, type MessageTruncationStatus, - type ThreadMessageInfo, type MessageTruncationStatuses, messageTruncationStatus, messageTypes, @@ -1521,23 +1520,31 @@ const messageIDs = messageStore.threads[messageInfo.threadID]?.messageIDs ?? []; const now = Date.now(); - const threadState: ThreadMessageInfo = messageStore.threads[threadID] - ? { - ...messageStore.threads[threadID], - messageIDs: [localID, ...messageIDs], - } - : { - messageIDs: [localID], - startReached: true, - lastNavigatedTo: now, - lastPruned: now, - }; + const updatedThreads = { + [threadID]: messageStore.threads[threadID] + ? { + ...messageStore.threads[threadID], + messageIDs: [localID, ...messageIDs], + } + : { + messageIDs: [localID], + startReached: true, + lastNavigatedTo: now, + lastPruned: now, + }, + }; const messageStoreOperations = [ { type: 'replace', payload: { id: localID, messageInfo }, }, + { + type: 'replace_threads', + payload: { + threads: { ...updatedThreads }, + }, + }, ]; const processedMessageStore = processMessageStoreOperations( @@ -1545,16 +1552,24 @@ messageStoreOperations, ); + const newMessageStore = { + ...messageStore, + threads: { + ...messageStore.threads, + ...updatedThreads, + }, + messages: processedMessageStore.messages, + }; + + assertMessageStoreThreadsAreEqual( + processedMessageStore, + newMessageStore, + action.type, + ); + return { messageStoreOperations, - messageStore: { - ...messageStore, - threads: { - ...messageStore.threads, - [threadID]: threadState, - }, - messages: processedMessageStore.messages, - }, + messageStore: newMessageStore, }; } else if (action.type === processServerRequestsActionType) { const {