diff --git a/native/redux/client-db-utils.js b/native/redux/client-db-utils.js --- a/native/redux/client-db-utils.js +++ b/native/redux/client-db-utils.js @@ -1,18 +1,11 @@ // @flow import type { ClientDBMessageStoreOperation } from 'lib/ops/message-store-ops.js'; -import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js'; import type { RawMessageInfo, ClientDBMessageInfo, ClientDBThreadMessageInfo, } from 'lib/types/message-types.js'; -import type { RawThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; -import type { - ClientDBThreadInfo, - LegacyRawThreadInfo, - MixedRawThreadInfos, -} from 'lib/types/thread-types.js'; import { translateClientDBMessageInfoToRawMessageInfo, translateRawMessageInfoToClientDBMessageInfo, @@ -20,88 +13,7 @@ translateThreadMessageInfoToClientDBThreadMessageInfo, type TranslatedThreadMessageInfos, } from 'lib/utils/message-ops-utils.js'; -import { values, entries } from 'lib/utils/objects.js'; -import { - convertRawThreadInfoToClientDBThreadInfo, - deprecatedConvertClientDBThreadInfoToRawThreadInfo, -} from 'lib/utils/thread-ops-utils.js'; - -import type { AppState } from './state-types.js'; -import { commCoreModule } from '../native-modules.js'; - -function updateClientDBThreadStoreThreadInfos( - state: AppState, - migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos, - handleMigrationFailure?: AppState => AppState, -): AppState { - // Get threads from SQLite `threads` table. - const clientDBThreadInfos = commCoreModule.getAllThreadsSync(); - - const operations = createUpdateDBOpsForThreadStoreThreadInfos( - clientDBThreadInfos, - migrationFunc, - ); - - // Try processing `ClientDBThreadStoreOperation`s and log out if - // `processThreadStoreOperationsSync(...)` throws an exception. - try { - commCoreModule.processThreadStoreOperationsSync(operations); - } catch (exception) { - console.log(exception); - if (handleMigrationFailure) { - return handleMigrationFailure(state); - } - return ({ ...state, cookie: null }: any); - } - - return state; -} - -function createUpdateDBOpsForThreadStoreThreadInfos( - clientDBThreadInfos: $ReadOnlyArray, - migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos, -): $ReadOnlyArray { - // Translate `ClientDBThreadInfo`s to `RawThreadInfo`s. - const rawThreadInfos = clientDBThreadInfos.map( - deprecatedConvertClientDBThreadInfoToRawThreadInfo, - ); - - // Convert `rawThreadInfo`s to a map of `threadID` => `threadInfo`. - const threadIDToThreadInfo = rawThreadInfos.reduce( - ( - acc: { [string]: LegacyRawThreadInfo | RawThreadInfo }, - threadInfo: LegacyRawThreadInfo | RawThreadInfo, - ) => { - acc[threadInfo.id] = threadInfo; - return acc; - }, - {}, - ); - - // Apply `migrationFunc` to `threadInfo`s. - const updatedThreadIDToThreadInfo = migrationFunc(threadIDToThreadInfo); - - // Convert the updated `threadInfo`s back into an array. - const updatedRawThreadInfos: $ReadOnlyArray< - LegacyRawThreadInfo | RawThreadInfo, - > = values(updatedThreadIDToThreadInfo); - - // Translate `RawThreadInfo`s to `ClientDBThreadInfo`s. - const convertedClientDBThreadInfos: $ReadOnlyArray = - updatedRawThreadInfos.map(convertRawThreadInfoToClientDBThreadInfo); - - // Construct `ClientDBThreadStoreOperation`s to clear SQLite `threads` - // table and repopulate with `ClientDBThreadInfo`s. - return [ - { - type: 'remove_all', - }, - ...convertedClientDBThreadInfos.map((thread: ClientDBThreadInfo) => ({ - type: 'replace', - payload: thread, - })), - ]; -} +import { entries } from 'lib/utils/objects.js'; function createUpdateDBOpsForMessageStoreMessages( clientDBMessageInfos: $ReadOnlyArray, @@ -157,8 +69,6 @@ } export { - updateClientDBThreadStoreThreadInfos, - createUpdateDBOpsForThreadStoreThreadInfos, createUpdateDBOpsForMessageStoreMessages, createUpdateDBOpsForMessageStoreThreads, }; diff --git a/native/redux/client-db-utils.js b/native/redux/deprecated-client-db-utils.js copy from native/redux/client-db-utils.js copy to native/redux/deprecated-client-db-utils.js --- a/native/redux/client-db-utils.js +++ b/native/redux/deprecated-client-db-utils.js @@ -1,26 +1,13 @@ // @flow -import type { ClientDBMessageStoreOperation } from 'lib/ops/message-store-ops.js'; import type { ClientDBThreadStoreOperation } from 'lib/ops/thread-store-ops.js'; -import type { - RawMessageInfo, - ClientDBMessageInfo, - ClientDBThreadMessageInfo, -} from 'lib/types/message-types.js'; import type { RawThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import type { ClientDBThreadInfo, LegacyRawThreadInfo, MixedRawThreadInfos, } from 'lib/types/thread-types.js'; -import { - translateClientDBMessageInfoToRawMessageInfo, - translateRawMessageInfoToClientDBMessageInfo, - translateClientDBThreadMessageInfos, - translateThreadMessageInfoToClientDBThreadMessageInfo, - type TranslatedThreadMessageInfos, -} from 'lib/utils/message-ops-utils.js'; -import { values, entries } from 'lib/utils/objects.js'; +import { values } from 'lib/utils/objects.js'; import { convertRawThreadInfoToClientDBThreadInfo, deprecatedConvertClientDBThreadInfoToRawThreadInfo, @@ -29,7 +16,7 @@ import type { AppState } from './state-types.js'; import { commCoreModule } from '../native-modules.js'; -function updateClientDBThreadStoreThreadInfos( +function deprecatedUpdateClientDBThreadStoreThreadInfos( state: AppState, migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos, handleMigrationFailure?: AppState => AppState, @@ -37,7 +24,7 @@ // Get threads from SQLite `threads` table. const clientDBThreadInfos = commCoreModule.getAllThreadsSync(); - const operations = createUpdateDBOpsForThreadStoreThreadInfos( + const operations = deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos( clientDBThreadInfos, migrationFunc, ); @@ -57,7 +44,7 @@ return state; } -function createUpdateDBOpsForThreadStoreThreadInfos( +function deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos( clientDBThreadInfos: $ReadOnlyArray, migrationFunc: MixedRawThreadInfos => MixedRawThreadInfos, ): $ReadOnlyArray { @@ -103,62 +90,7 @@ ]; } -function createUpdateDBOpsForMessageStoreMessages( - clientDBMessageInfos: $ReadOnlyArray, - migrationFunc: ( - $ReadOnlyArray, - ) => $ReadOnlyArray, -): $ReadOnlyArray { - const rawMessageInfos = clientDBMessageInfos.map( - translateClientDBMessageInfoToRawMessageInfo, - ); - - const convertedRawMessageInfos = migrationFunc(rawMessageInfos); - - const replaceMessagesOperations: $ReadOnlyArray = - convertedRawMessageInfos.map(messageInfo => ({ - type: 'replace', - payload: translateRawMessageInfoToClientDBMessageInfo(messageInfo), - })); - - return [ - { - type: 'remove_all', - }, - ...replaceMessagesOperations, - ]; -} - -function createUpdateDBOpsForMessageStoreThreads( - messageStoreThreads: $ReadOnlyArray, - migrationFunc: TranslatedThreadMessageInfos => TranslatedThreadMessageInfos, -): $ReadOnlyArray { - const translatedMessageStoreThreads = - translateClientDBThreadMessageInfos(messageStoreThreads); - - const convertedTranslatedMessageStoreThreads = migrationFunc( - translatedMessageStoreThreads, - ); - - return [ - { - type: 'remove_all_threads', - }, - { - type: 'replace_threads', - payload: { - threads: entries(convertedTranslatedMessageStoreThreads).map( - ([id, thread]) => - translateThreadMessageInfoToClientDBThreadMessageInfo(id, thread), - ), - }, - }, - ]; -} - export { - updateClientDBThreadStoreThreadInfos, - createUpdateDBOpsForThreadStoreThreadInfos, - createUpdateDBOpsForMessageStoreMessages, - createUpdateDBOpsForMessageStoreThreads, + deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos, + deprecatedUpdateClientDBThreadStoreThreadInfos, }; diff --git a/native/redux/persist.js b/native/redux/persist.js --- a/native/redux/persist.js +++ b/native/redux/persist.js @@ -99,12 +99,14 @@ import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { - updateClientDBThreadStoreThreadInfos, - createUpdateDBOpsForThreadStoreThreadInfos, createUpdateDBOpsForMessageStoreMessages, createUpdateDBOpsForMessageStoreThreads, } from './client-db-utils.js'; import { defaultState } from './default-state.js'; +import { + deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos, + deprecatedUpdateClientDBThreadStoreThreadInfos, +} from './deprecated-client-db-utils.js'; import { migrateThreadStoreForEditThreadPermissions } from './edit-thread-permission-migration.js'; import { legacyUpdateRolesAndPermissions } from './legacy-update-roles-and-permissions.js'; import { persistMigrationForManagePinsThreadPermission } from './manage-pins-permission-migration.js'; @@ -636,13 +638,13 @@ return state; }, [38]: (state: AppState) => - updateClientDBThreadStoreThreadInfos( + deprecatedUpdateClientDBThreadStoreThreadInfos( state, legacyUpdateRolesAndPermissions, ), [39]: (state: AppState) => unshimClientDB(state, [messageTypes.EDIT_MESSAGE]), [40]: (state: AppState) => - updateClientDBThreadStoreThreadInfos( + deprecatedUpdateClientDBThreadStoreThreadInfos( state, legacyUpdateRolesAndPermissions, ), @@ -689,10 +691,11 @@ messageInfos.map(convertRawMessageInfoToNewIDSchema), ); - const threadOperations = createUpdateDBOpsForThreadStoreThreadInfos( - threads, - convertThreadStoreThreadInfosToNewIDSchema, - ); + const threadOperations = + deprecatedCreateUpdateDBOpsForThreadStoreThreadInfos( + threads, + convertThreadStoreThreadInfosToNewIDSchema, + ); const draftOperations = generateIDSchemaMigrationOpsForDrafts(drafts); @@ -1020,7 +1023,7 @@ return state; }, [60]: (state: AppState) => - updateClientDBThreadStoreThreadInfos( + deprecatedUpdateClientDBThreadStoreThreadInfos( state, legacyUpdateRolesAndPermissions, handleReduxMigrationFailure, @@ -1044,7 +1047,7 @@ }, {}, ); - return updateClientDBThreadStoreThreadInfos( + return deprecatedUpdateClientDBThreadStoreThreadInfos( state, minimallyEncodeThreadInfosFunc, handleReduxMigrationFailure,