diff --git a/lib/ops/thread-store-ops.js b/lib/ops/thread-store-ops.js index 8a215ddd7..26dbbc383 100644 --- a/lib/ops/thread-store-ops.js +++ b/lib/ops/thread-store-ops.js @@ -1,99 +1,99 @@ // @flow import { type BaseStoreOpsHandlers } from './base-ops.js'; import type { ClientDBThreadInfo, RawThreadInfo, RawThreadInfos, ThreadStore, } from '../types/thread-types.js'; import { + convertClientDBThreadInfoToRawThreadInfo, convertRawThreadInfoToClientDBThreadInfo, - deprecatedConvertClientDBThreadInfoToRawThreadInfo, } from '../utils/thread-ops-utils.js'; export type RemoveThreadOperation = { +type: 'remove', +payload: { +ids: $ReadOnlyArray }, }; export type RemoveAllThreadsOperation = { +type: 'remove_all', }; export type ReplaceThreadOperation = { +type: 'replace', +payload: { +id: string, +threadInfo: RawThreadInfo }, }; export type ThreadStoreOperation = | RemoveThreadOperation | RemoveAllThreadsOperation | ReplaceThreadOperation; export type ClientDBReplaceThreadOperation = { +type: 'replace', +payload: ClientDBThreadInfo, }; export type ClientDBThreadStoreOperation = | RemoveThreadOperation | RemoveAllThreadsOperation | ClientDBReplaceThreadOperation; export const threadStoreOpsHandlers: BaseStoreOpsHandlers< ThreadStore, ThreadStoreOperation, ClientDBThreadStoreOperation, RawThreadInfos, ClientDBThreadInfo, > = { processStoreOperations( store: ThreadStore, ops: $ReadOnlyArray, ): ThreadStore { if (ops.length === 0) { return store; } let processedThreads = { ...store.threadInfos }; for (const operation of ops) { if (operation.type === 'replace') { processedThreads[operation.payload.id] = operation.payload.threadInfo; } else if (operation.type === 'remove') { for (const id of operation.payload.ids) { delete processedThreads[id]; } } else if (operation.type === 'remove_all') { processedThreads = {}; } } return { ...store, threadInfos: processedThreads }; }, convertOpsToClientDBOps( ops: $ReadOnlyArray, ): $ReadOnlyArray { return ops.map(threadStoreOperation => { if (threadStoreOperation.type === 'replace') { return { type: 'replace', payload: convertRawThreadInfoToClientDBThreadInfo( threadStoreOperation.payload.threadInfo, ), }; } return threadStoreOperation; }); }, translateClientDBData(data: $ReadOnlyArray): { +[id: string]: RawThreadInfo, } { return Object.fromEntries( data.map((dbThreadInfo: ClientDBThreadInfo) => [ dbThreadInfo.id, - deprecatedConvertClientDBThreadInfoToRawThreadInfo(dbThreadInfo), + convertClientDBThreadInfoToRawThreadInfo(dbThreadInfo), ]), ); }, };