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 @@ -605,6 +605,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/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 = [