diff --git a/native/redux/handle-redux-migration-failure.js b/native/redux/handle-redux-migration-failure.js new file mode 100644 --- /dev/null +++ b/native/redux/handle-redux-migration-failure.js @@ -0,0 +1,41 @@ +// @flow + +import { wipeKeyserverStore } from 'lib/utils/keyserver-store-utils.js'; +import { resetUserSpecificState } from 'lib/utils/reducers-utils.js'; + +import { defaultState } from './default-state.js'; +import { nonUserSpecificFieldsNative, type AppState } from './state-types.js'; + +const persistBlacklist = [ + 'loadingStatuses', + 'lifecycleState', + 'dimensions', + 'draftStore', + 'connectivity', + 'deviceOrientation', + 'frozen', + 'threadStore', + 'storeLoaded', + 'dbOpsStore', + 'syncedMetadataStore', + 'userStore', + 'auxUserStore', + 'commServicesAccessToken', +]; + +function handleReduxMigrationFailure(oldState: AppState): AppState { + const persistedNonUserSpecificFields = nonUserSpecificFieldsNative.filter( + field => !persistBlacklist.includes(field) || field === '_persist', + ); + const stateAfterReset = resetUserSpecificState( + oldState, + defaultState, + persistedNonUserSpecificFields, + ); + return { + ...stateAfterReset, + keyserverStore: wipeKeyserverStore(stateAfterReset.keyserverStore), + }; +} + +export { persistBlacklist, handleReduxMigrationFailure }; diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -95,7 +95,6 @@ LegacyRawThreadInfo, MixedRawThreadInfos, } from 'lib/types/thread-types.js'; -import { wipeKeyserverStore } from 'lib/utils/keyserver-store-utils.js'; import { translateClientDBMessageInfoToRawMessageInfo, translateRawMessageInfoToClientDBMessageInfo, @@ -106,7 +105,6 @@ convertThreadStoreThreadInfosToNewIDSchema, } from 'lib/utils/migration-utils.js'; import { entries } from 'lib/utils/objects.js'; -import { resetUserSpecificState } from 'lib/utils/reducers-utils.js'; import { deprecatedConvertClientDBThreadInfoToRawThreadInfo, convertRawThreadInfoToClientDBThreadInfo, @@ -124,11 +122,14 @@ deprecatedUpdateClientDBThreadStoreThreadInfos, } from './deprecated-client-db-utils.js'; import { migrateThreadStoreForEditThreadPermissions } from './edit-thread-permission-migration.js'; +import { + handleReduxMigrationFailure, + persistBlacklist, +} from './handle-redux-migration-failure.js'; import { legacyUpdateRolesAndPermissions } from './legacy-update-roles-and-permissions.js'; import { persistMigrationForManagePinsThreadPermission } from './manage-pins-permission-migration.js'; import { persistMigrationToRemoveSelectRolePermissions } from './remove-select-role-permissions.js'; import type { AppState } from './state-types.js'; -import { nonUserSpecificFieldsNative } from './state-types.js'; import { unshimClientDB } from './unshim-utils.js'; import { authoritativeKeyserverID } from '../authoritative-keyserver.js'; import { commCoreModule } from '../native-modules.js'; @@ -136,38 +137,6 @@ import { isTaskCancelledError } from '../utils/error-handling.js'; import { defaultURLPrefix } from '../utils/url-utils.js'; -const persistBlacklist = [ - 'loadingStatuses', - 'lifecycleState', - 'dimensions', - 'draftStore', - 'connectivity', - 'deviceOrientation', - 'frozen', - 'threadStore', - 'storeLoaded', - 'dbOpsStore', - 'syncedMetadataStore', - 'userStore', - 'auxUserStore', - 'commServicesAccessToken', -]; - -function handleReduxMigrationFailure(oldState: AppState): AppState { - const persistedNonUserSpecificFields = nonUserSpecificFieldsNative.filter( - field => !persistBlacklist.includes(field) || field === '_persist', - ); - const stateAfterReset = resetUserSpecificState( - oldState, - defaultState, - persistedNonUserSpecificFields, - ); - return { - ...stateAfterReset, - keyserverStore: wipeKeyserverStore(stateAfterReset.keyserverStore), - }; -} - const migrations = { [1]: (state: AppState) => ({ ...state,