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 @@ -655,6 +655,7 @@ return messageStore; } let processedMessages = { ...messageStore.messages }; + let processedThreads = { ...messageStore.threads }; for (const operation of messageStoreOperations) { if (operation.type === 'replace') { processedMessages[operation.payload.id] = operation.payload.messageInfo; @@ -678,9 +679,23 @@ delete processedMessages[operation.payload.from]; } else if (operation.type === 'remove_all') { processedMessages = {}; + } else if (operation.type === 'replace_thread') { + for (const threadID in operation.payload.threads) { + processedThreads[threadID] = operation.payload.threads[threadID]; + } + } else if (operation.type === 'remove_thread') { + for (const id of operation.payload.ids) { + delete processedThreads[id]; + } + } else if (operation.type === 'remove_all_threads') { + processedThreads = {}; } } - return { ...messageStore, messages: processedMessages }; + return { + ...messageStore, + threads: processedThreads, + messages: processedMessages, + }; } type ReduceMessageStoreResult = { diff --git a/lib/types/message-types.js b/lib/types/message-types.js --- a/lib/types/message-types.js +++ b/lib/types/message-types.js @@ -381,6 +381,7 @@ +currentAsOf: number, }; +// MessageStore messages ops export type RemoveMessageOperation = { +type: 'remove', +payload: { +ids: $ReadOnlyArray }, @@ -405,6 +406,21 @@ +type: 'remove_all', }; +// MessageStore threads ops +export type ReplaceMessageStoreThreadOperation = { + +type: 'replace_thread', + +payload: { +threads: { +[threadID: string]: ThreadMessageInfo } }, +}; + +export type RemoveMessageStoreThreadOperation = { + +type: 'remove_thread', + +payload: { +ids: $ReadOnlyArray }, +}; + +export type RemoveMessageStoreAllThreadsOperation = { + +type: 'remove_all_threads', +}; + // We were initially using `number`s` for `thread`, `type`, `future_type`, etc. // However, we ended up changing `thread` to `string` to account for thread IDs // including information about the keyserver (eg 'GENESIS|123') in the future. @@ -437,7 +453,10 @@ | ReplaceMessageOperation | RekeyMessageOperation | RemoveMessagesForThreadsOperation - | RemoveAllMessagesOperation; + | RemoveAllMessagesOperation + | ReplaceMessageStoreThreadOperation + | RemoveMessageStoreThreadOperation + | RemoveMessageStoreAllThreadsOperation; export type ClientDBMessageStoreOperation = | RemoveMessageOperation diff --git a/lib/utils/message-ops-utils.js b/lib/utils/message-ops-utils.js --- a/lib/utils/message-ops-utils.js +++ b/lib/utils/message-ops-utils.js @@ -231,17 +231,27 @@ function convertMessageStoreOperationsToClientDBOperations( messageStoreOperations: $ReadOnlyArray, ): $ReadOnlyArray { - return messageStoreOperations.map(messageStoreOperation => { - if (messageStoreOperation.type !== 'replace') { - return messageStoreOperation; - } - return { - type: 'replace', - payload: translateRawMessageInfoToClientDBMessageInfo( - messageStoreOperation.payload.messageInfo, - ), - }; - }); + const convertedOperations = messageStoreOperations.map( + messageStoreOperation => { + if ( + messageStoreOperation.type === 'replace_thread' || + messageStoreOperation.type === 'remove_thread' || + messageStoreOperation.type === 'remove_all_threads' + ) { + return undefined; + } + if (messageStoreOperation.type !== 'replace') { + return messageStoreOperation; + } + return { + type: 'replace', + payload: translateRawMessageInfoToClientDBMessageInfo( + messageStoreOperation.payload.messageInfo, + ), + }; + }, + ); + return convertedOperations.filter(Boolean); } function getPinnedContentFromClientDBMessageInfo(