diff --git a/lib/ops/report-store-ops.js b/lib/ops/report-store-ops.js --- a/lib/ops/report-store-ops.js +++ b/lib/ops/report-store-ops.js @@ -76,8 +76,29 @@ }; } +function convertReportStoreOperationToClientDBReportStoreOperation( + reportStoreOperations: $ReadOnlyArray, +): $ReadOnlyArray { + return reportStoreOperations.map(operation => { + if ( + operation.type === 'remove_reports' || + operation.type === 'remove_all_reports' + ) { + return operation; + } + return { + type: 'replace_report', + payload: { + id: operation.payload.report.id, + report: JSON.stringify(operation.payload.report), + }, + }; + }); +} + export { processReportStoreOperations, convertReportsToReplaceReportOps, convertReportsToRemoveReportsOperation, + convertReportStoreOperationToClientDBReportStoreOperation, }; diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -7,6 +7,12 @@ import { createMigrate, createTransform } from 'redux-persist'; import type { Transform } from 'redux-persist/es/types.js'; +import { + type ReportStoreOperation, + type ClientDBReportStoreOperation, + convertReportStoreOperationToClientDBReportStoreOperation, + convertReportsToReplaceReportOps, +} from 'lib/ops/report-store-ops.js'; import { highestLocalIDSelector } from 'lib/selectors/local-id-selectors.js'; import { inconsistencyResponsesToReports } from 'lib/shared/report-utils.js'; import { @@ -541,6 +547,26 @@ reportStore: { ...state.reportStore, queuedReports }, }; }, + [41]: (state: AppState) => { + const reportStoreOperations: $ReadOnlyArray = [ + { type: 'remove_all_reports' }, + ...convertReportsToReplaceReportOps(state.reportStore.queuedReports), + ]; + const dbOperations: $ReadOnlyArray = + convertReportStoreOperationToClientDBReportStoreOperation( + reportStoreOperations, + ); + + try { + commCoreModule.processReportStoreOperationsSync(dbOperations); + } catch (exception) { + if (isTaskCancelledError(exception)) { + return state; + } + return { ...state, cookie: null }; + } + return state; + }, }; // After migration 31, we'll no longer want to persist `messageStore.messages` @@ -621,7 +647,7 @@ 'storeLoaded', ], debug: __DEV__, - version: 40, + version: 41, transforms: [messageStoreMessagesBlocklistTransform], migrate: (createMigrate(migrations, { debug: __DEV__ }): any), timeout: ((__DEV__ ? 0 : undefined): number | void),