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 @@ -96,9 +96,16 @@ }); } +function convertClientDBReportToClientReportCreationRequest( + reports: $ReadOnlyArray, +): $ReadOnlyArray { + return reports.map(reportRecord => JSON.parse(reportRecord.report)); +} + export { processReportStoreOperations, convertReportsToReplaceReportOps, convertReportsToRemoveReportsOperation, convertReportStoreOperationToClientDBReportStoreOperation, + convertClientDBReportToClientReportCreationRequest, }; diff --git a/lib/reducers/message-reducer.test.js b/lib/reducers/message-reducer.test.js --- a/lib/reducers/message-reducer.test.js +++ b/lib/reducers/message-reducer.test.js @@ -292,6 +292,7 @@ }, messageStoreThreads: [], messages: clientDBMessages, + reports: [], }, }, { diff --git a/lib/reducers/report-store-reducer.js b/lib/reducers/report-store-reducer.js --- a/lib/reducers/report-store-reducer.js +++ b/lib/reducers/report-store-reducer.js @@ -1,5 +1,6 @@ // @flow +import { setClientDBStoreActionType } from '../actions/client-db-store-actions.js'; import { sendReportActionTypes, sendReportsActionTypes, @@ -143,6 +144,30 @@ }, reportStoreOperations, }; + } else if (action.type === setClientDBStoreActionType) { + const { reports } = action.payload; + if (!reports) { + return { + reportStore: state, + reportStoreOperations: [], + }; + } + const reportStoreOperations: $ReadOnlyArray = [ + { + type: 'remove_all_reports', + }, + ...convertReportsToReplaceReportOps(reports), + ]; + + const queuedReports = processReportStoreOperations( + state.queuedReports, + reportStoreOperations, + ); + + return { + reportStore: { ...state, queuedReports }, + reportStoreOperations: [], + }; } if (newReports) { diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -76,6 +76,7 @@ ClearDeliveredReportsPayload, QueueReportsPayload, ReportStore, + ClientReportCreationRequest, } from './report-types.js'; import type { ProcessServerRequestsPayload, @@ -632,6 +633,7 @@ +messages: ?$ReadOnlyArray, +threadStore: ?ThreadStore, +messageStoreThreads: ?$ReadOnlyArray, + +reports: ?$ReadOnlyArray, }, } | { diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -6,6 +6,7 @@ import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.js'; import { MediaCacheContext } from 'lib/components/media-cache-provider.react.js'; +import { convertClientDBReportToClientReportCreationRequest } from 'lib/ops/report-store-ops.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import { logInActionSources, @@ -157,10 +158,13 @@ mediaCacheContext?.evictCache(), ]); try { - const { threads, messages, drafts, messageStoreThreads } = + const { threads, messages, drafts, messageStoreThreads, reports } = await commCoreModule.getClientDBStore(); const threadInfosFromDB = convertClientDBThreadInfosToRawThreadInfos(threads); + const reportsFromDb = + convertClientDBReportToClientReportCreationRequest(reports); + dispatch({ type: setClientDBStoreActionType, payload: { @@ -169,6 +173,7 @@ threadStore: { threadInfos: threadInfosFromDB }, currentUserID: currentLoggedInUserID, messageStoreThreads, + reports: reportsFromDb, }, }); } catch (setStoreException) {