diff --git a/lib/reducers/integrity-reducer.js b/lib/reducers/integrity-reducer.js --- a/lib/reducers/integrity-reducer.js +++ b/lib/reducers/integrity-reducer.js @@ -8,7 +8,10 @@ logInActionTypes, keyserverRegisterActionTypes, } from '../actions/user-actions.js'; -import { integrityStoreOpsHandlers } from '../ops/integrity-store-ops.js'; +import { + integrityStoreOpsHandlers, + type IntegrityStoreOperation, +} from '../ops/integrity-store-ops.js'; import type { ThreadStoreOperation } from '../ops/thread-store-ops'; import type { IntegrityStore } from '../types/integrity-types'; import type { RawThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js'; @@ -65,25 +68,32 @@ if (threadStoreOperations.length === 0) { return newState; } - let processedThreadHashes = { ...newState.threadHashes }; + const integrityOperations: IntegrityStoreOperation[] = []; let threadHashingStatus = newState.threadHashingStatus; for (const operation of threadStoreOperations) { if (operation.type === 'replace') { - processedThreadHashes[operation.payload.id] = hash( - operation.payload.threadInfo, - ); + const newIntegrityThreadHash = hash(operation.payload.threadInfo); + integrityOperations.push({ + type: 'replace_integrity_thread_hashes', + payload: { + threadHashes: { [operation.payload.id]: newIntegrityThreadHash }, + }, + }); } else if (operation.type === 'remove') { for (const id of operation.payload.ids) { - delete processedThreadHashes[id]; + integrityOperations.push({ + type: 'remove_integrity_thread_hashes', + payload: { ids: [id] }, + }); } } else if (operation.type === 'remove_all') { - processedThreadHashes = {}; + integrityOperations.push({ type: 'remove_all_integrity_thread_hashes' }); threadHashingStatus = 'completed'; } } return { ...newState, - threadHashes: processedThreadHashes, + threadHashes: processStoreOps(newState, integrityOperations).threadHashes, threadHashingStatus, }; }