diff --git a/lib/utils/services-utils.js b/lib/utils/services-utils.js --- a/lib/utils/services-utils.js +++ b/lib/utils/services-utils.js @@ -9,6 +9,11 @@ // other Comm services. const usingCommServicesAccessToken = false; +// If this is true, then the app is able to support multiple keyservers. This +// requires the use of Tunnelbroker and the backup service to persist and sync +// the KeyserverStore. +const supportingMultipleKeyservers = false; + // If this is false, then the app no longer needs to rely on being connected to // an authoritative keyserver for things like DMs. const relyingOnAuthoritativeKeyserver = true; @@ -40,6 +45,7 @@ export { handleHTTPResponseError, usingCommServicesAccessToken, + supportingMultipleKeyservers, relyingOnAuthoritativeKeyserver, createHTTPAuthorizationHeader, createDefaultHTTPRequestHeaders, diff --git a/native/data/sqlite-data-handler.js b/native/data/sqlite-data-handler.js --- a/native/data/sqlite-data-handler.js +++ b/native/data/sqlite-data-handler.js @@ -1,5 +1,6 @@ // @flow +import invariant from 'invariant'; import * as React from 'react'; import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.js'; @@ -21,6 +22,7 @@ import { getMessageForException } from 'lib/utils/errors.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; +import { supportingMultipleKeyservers } from 'lib/utils/services-utils.js'; import { resolveKeyserverSessionInvalidationUsingNativeCredentials } from '../account/legacy-recover-keyserver-session.js'; import { authoritativeKeyserverID } from '../authoritative-keyserver.js'; @@ -108,6 +110,21 @@ ], ); + const recoverData = React.useCallback( + (source: RecoveryActionSource) => { + if (supportingMultipleKeyservers) { + invariant( + false, + 'recoverData in SQLiteDataHandler is not yet implemented when ' + + 'supportingMultipleKeyservers is enabled. It should recover ' + + 'from broken SQLite state by restoring from backup service', + ); + } + return recoverDataFromAuthoritativeKeyserver(source); + }, + [recoverDataFromAuthoritativeKeyserver], + ); + const callClearSensitiveData = React.useCallback( async (triggeredBy: string) => { await clearSensitiveData(); @@ -161,9 +178,7 @@ commCoreModule.terminate(); } } - await recoverDataFromAuthoritativeKeyserver( - recoveryActionSources.corruptedDatabaseDeletion, - ); + await recoverData(recoveryActionSources.corruptedDatabaseDeletion); })(); return; } @@ -228,9 +243,7 @@ '{no exception message}', ); } - await recoverDataFromAuthoritativeKeyserver( - recoveryActionSources.sqliteLoadFailure, - ); + await recoverData(recoveryActionSources.sqliteLoadFailure); } })(); }, [ @@ -241,7 +254,7 @@ rehydrateConcluded, staffCanSee, storeLoaded, - recoverDataFromAuthoritativeKeyserver, + recoverData, callClearSensitiveData, mediaCacheContext, ]);