Changeset View
Changeset View
Standalone View
Standalone View
native/redux/persist.js
// @flow | // @flow | ||||
import AsyncStorage from '@react-native-async-storage/async-storage'; | import AsyncStorage from '@react-native-async-storage/async-storage'; | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import { Platform } from 'react-native'; | import { Platform } from 'react-native'; | ||||
import Orientation from 'react-native-orientation-locker'; | import Orientation from 'react-native-orientation-locker'; | ||||
import { createMigrate, createTransform } from 'redux-persist'; | import { createMigrate, createTransform } from 'redux-persist'; | ||||
import type { Transform } from 'redux-persist/es/types.js'; | 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 { highestLocalIDSelector } from 'lib/selectors/local-id-selectors.js'; | ||||
import { inconsistencyResponsesToReports } from 'lib/shared/report-utils.js'; | import { inconsistencyResponsesToReports } from 'lib/shared/report-utils.js'; | ||||
import { | import { | ||||
getContainingThreadID, | getContainingThreadID, | ||||
getCommunity, | getCommunity, | ||||
} from 'lib/shared/thread-utils.js'; | } from 'lib/shared/thread-utils.js'; | ||||
import { | import { | ||||
DEPRECATED_unshimMessageStore, | DEPRECATED_unshimMessageStore, | ||||
▲ Show 20 Lines • Show All 523 Lines • ▼ Show 20 Lines | const queuedReports = state.reportStore.queuedReports.map(report => ({ | ||||
...report, | ...report, | ||||
id: getUUID(), | id: getUUID(), | ||||
})); | })); | ||||
return { | return { | ||||
...state, | ...state, | ||||
reportStore: { ...state.reportStore, queuedReports }, | reportStore: { ...state.reportStore, queuedReports }, | ||||
}; | }; | ||||
}, | }, | ||||
[42]: (state: AppState) => { | |||||
const reportStoreOperations: $ReadOnlyArray<ReportStoreOperation> = [ | |||||
{ type: 'remove_all_reports' }, | |||||
...convertReportsToReplaceReportOps(state.reportStore.queuedReports), | |||||
]; | |||||
const dbOperations: $ReadOnlyArray<ClientDBReportStoreOperation> = | |||||
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` | // After migration 31, we'll no longer want to persist `messageStore.messages` | ||||
// via redux-persist. However, we DO want to continue persisting everything in | // via redux-persist. However, we DO want to continue persisting everything in | ||||
// `messageStore` EXCEPT for `messages`. The `blacklist` property in | // `messageStore` EXCEPT for `messages`. The `blacklist` property in | ||||
// `persistConfig` allows us to specify top-level keys that shouldn't be | // `persistConfig` allows us to specify top-level keys that shouldn't be | ||||
// persisted. However, we aren't able to specify nested keys in `blacklist`. | // persisted. However, we aren't able to specify nested keys in `blacklist`. | ||||
// As a result, if we want to prevent nested keys from being persisted we'll | // As a result, if we want to prevent nested keys from being persisted we'll | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | blacklist: [ | ||||
'draftStore', | 'draftStore', | ||||
'connectivity', | 'connectivity', | ||||
'deviceOrientation', | 'deviceOrientation', | ||||
'frozen', | 'frozen', | ||||
'threadStore', | 'threadStore', | ||||
'storeLoaded', | 'storeLoaded', | ||||
], | ], | ||||
debug: __DEV__, | debug: __DEV__, | ||||
version: 41, | version: 42, | ||||
transforms: [messageStoreMessagesBlocklistTransform], | transforms: [messageStoreMessagesBlocklistTransform], | ||||
migrate: (createMigrate(migrations, { debug: __DEV__ }): any), | migrate: (createMigrate(migrations, { debug: __DEV__ }): any), | ||||
timeout: ((__DEV__ ? 0 : undefined): number | void), | timeout: ((__DEV__ ? 0 : undefined): number | void), | ||||
}; | }; | ||||
const codeVersion: number = commCoreModule.getCodeVersion(); | const codeVersion: number = commCoreModule.getCodeVersion(); | ||||
// This local exists to avoid a circular dependency where redux-setup needs to | // This local exists to avoid a circular dependency where redux-setup needs to | ||||
Show All 12 Lines |