diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js --- a/keyserver/src/responders/website-responders.js +++ b/keyserver/src/responders/website-responders.js @@ -594,6 +594,7 @@ viewer.platformDetails, initialReduxStateValidator, initialReduxState, + true, ); const jsonStream = streamJSON(res, validatedInitialReduxState); diff --git a/keyserver/src/utils/validation-utils.js b/keyserver/src/utils/validation-utils.js --- a/keyserver/src/utils/validation-utils.js +++ b/keyserver/src/utils/validation-utils.js @@ -7,7 +7,7 @@ hasMinCodeVersion, FUTURE_CODE_VERSION, } from 'lib/shared/version-utils.js'; -import { type PlatformDetails, isWebPlatform } from 'lib/types/device-types.js'; +import { type PlatformDetails } from 'lib/types/device-types.js'; import { ServerError } from 'lib/utils/errors.js'; import { tCookie, @@ -39,8 +39,8 @@ if ( hasMinCodeVersion(viewer.platformDetails, { native: FUTURE_CODE_VERSION, + web: FUTURE_CODE_VERSION, }) && - !isWebPlatform(viewer.platformDetails?.platform) && convertToNewIDSchema ) { try { @@ -61,6 +61,7 @@ platformDetails: ?PlatformDetails, outputValidator: TType, data: T, + alwaysConvertSchema?: boolean, ): T { if (!outputValidator.is(data)) { console.trace( @@ -71,8 +72,11 @@ } if ( - hasMinCodeVersion(platformDetails, { native: FUTURE_CODE_VERSION }) && - !isWebPlatform(platformDetails?.platform) && + (hasMinCodeVersion(platformDetails, { + native: FUTURE_CODE_VERSION, + web: FUTURE_CODE_VERSION, + }) || + alwaysConvertSchema) && convertToNewIDSchema ) { return convertServerIDsToClientIDs( diff --git a/lib/shared/version-utils.js b/lib/shared/version-utils.js --- a/lib/shared/version-utils.js +++ b/lib/shared/version-utils.js @@ -12,7 +12,8 @@ * A code version used for features that are waiting to be included * in the very next release */ -const NEXT_CODE_VERSION = 1000000; +const NEXT_NATIVE_CODE_VERSION = 1000000; +const NEXT_WEB_CODE_VERSION = 1000000; function hasMinCodeVersion( platformDetails: ?PlatformDetails, @@ -36,4 +37,9 @@ return true; } -export { FUTURE_CODE_VERSION, NEXT_CODE_VERSION, hasMinCodeVersion }; +export { + FUTURE_CODE_VERSION, + NEXT_NATIVE_CODE_VERSION, + NEXT_WEB_CODE_VERSION, + hasMinCodeVersion, +}; diff --git a/web/redux/persist.js b/web/redux/persist.js --- a/web/redux/persist.js +++ b/web/redux/persist.js @@ -1,5 +1,6 @@ // @flow +import invariant from 'invariant'; import { getStoredState, purgeStoredState } from 'redux-persist'; import storage from 'redux-persist/es/storage/index.js'; import type { PersistConfig } from 'redux-persist/src/types.js'; @@ -9,6 +10,10 @@ type StorageMigrationFunction, } from 'lib/shared/create-async-migrate.js'; import { isDev } from 'lib/utils/dev-utils.js'; +import { + generateIDSchemaMigrationOpsForDrafts, + convertDraftStoreToNewIDSchema, +} from 'lib/utils/migration-utils.js'; import commReduxStorageEngine from './comm-redux-storage-engine.js'; import type { AppState } from './redux-setup.js'; @@ -61,6 +66,34 @@ return state; }, + [3]: async (state: AppState) => { + let newState = state; + if (state.draftStore) { + newState = { + ...newState, + draftStore: convertDraftStoreToNewIDSchema(state.draftStore), + }; + } + + if (!isDatabaseSupported) { + return newState; + } + + const stores = await databaseModule.schedule({ + type: workerRequestMessageTypes.GET_CLIENT_STORE, + }); + invariant(stores?.store, 'Stores should exist'); + await databaseModule.schedule({ + type: workerRequestMessageTypes.PROCESS_STORE_OPERATIONS, + storeOperations: { + draftStoreOperations: generateIDSchemaMigrationOpsForDrafts( + stores.store.drafts, + ), + }, + }); + + return newState; + }, }; const persistWhitelist = [