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,34 +1,21 @@ // @flow -import invariant from 'invariant'; import * as React from 'react'; import { setClientDBStoreActionType } from 'lib/actions/client-db-store-actions.js'; import { MediaCacheContext } from 'lib/components/media-cache-provider.react.js'; -import type { CallSingleKeyserverEndpoint } from 'lib/keyserver-conn/call-single-keyserver-endpoint.js'; -import type { CallKeyserverEndpoint } from 'lib/keyserver-conn/keyserver-conn-types.js'; -import { useKeyserverRecoveryLogIn } from 'lib/keyserver-conn/recovery-utils.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; -import { useInitialNotificationsEncryptedMessage } from 'lib/shared/crypto-utils.js'; import { shouldClearData } from 'lib/shared/data-utils.js'; -import { - recoveryFromDataHandlerActionSources, - type RecoveryFromDataHandlerActionSource, -} from 'lib/types/account-types.js'; import { databaseIdentifier } from 'lib/types/database-identifier-types.js'; import { getConfig } from 'lib/utils/config.js'; 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 { reportDatabaseDeleted, databaseResetStatus, setDatabaseResetStatus, } from 'lib/utils/wait-until-db-deleted.js'; -import { resolveKeyserverSessionInvalidationUsingNativeCredentials } from '../account/legacy-recover-keyserver-session.js'; -import { authoritativeKeyserverID } from '../authoritative-keyserver.js'; import { filesystemMediaCache } from '../media/media-cache.js'; import { commCoreModule } from '../native-modules.js'; import { setStoreLoadedActionType } from '../redux/action-types.js'; @@ -58,13 +45,10 @@ } } -const returnsFalseSinceDoesntNeedToSupportCancellation = () => false; - function SQLiteDataHandler(): React.Node { const initialStateLoaded = useSelector(state => state.initialStateLoaded); const dispatch = useDispatch(); - const dispatchActionPromise = useDispatchActionPromise(); const rehydrateConcluded = useSelector( state => !!(state._persist && state._persist.rehydrated), @@ -75,70 +59,14 @@ state.currentUserInfo?.anonymous ? undefined : state.currentUserInfo?.id, ); const mediaCacheContext = React.useContext(MediaCacheContext); - const getInitialNotificationsEncryptedMessage = - useInitialNotificationsEncryptedMessage(authoritativeKeyserverID); - const keyserverRecoveryLogIn = useKeyserverRecoveryLogIn( - authoritativeKeyserverID, - ); - const recoverDataFromAuthoritativeKeyserver = React.useCallback( - async (source: RecoveryFromDataHandlerActionSource) => { - const innerRecoverDataFromAuthoritativeKeyserver = ( - callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, - callKeyserverEndpoint: CallKeyserverEndpoint, - ) => - resolveKeyserverSessionInvalidationUsingNativeCredentials( - callSingleKeyserverEndpoint, - callKeyserverEndpoint, - dispatchActionPromise, - source, - authoritativeKeyserverID, - getInitialNotificationsEncryptedMessage, - returnsFalseSinceDoesntNeedToSupportCancellation, - ); - try { - await keyserverRecoveryLogIn( - source, - innerRecoverDataFromAuthoritativeKeyserver, - returnsFalseSinceDoesntNeedToSupportCancellation, - ); - dispatch({ type: setStoreLoadedActionType }); - } catch (fetchCookieException) { - if (staffCanSee) { - Alert.alert( - `Error fetching new cookie from native credentials: ${ - getMessageForException(fetchCookieException) ?? - '{no exception message}' - }. Please kill the app.`, - ); - } else { - commCoreModule.terminate(); - } - } - }, - [ - dispatch, - dispatchActionPromise, - keyserverRecoveryLogIn, - staffCanSee, - getInitialNotificationsEncryptedMessage, - ], - ); - - const recoverData = React.useCallback( - (source: RecoveryFromDataHandlerActionSource) => { - 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 showCorruptionAlert = React.useCallback(() => { + const { showAlert } = getConfig(); + showAlert( + 'Corrupted data', + 'Comm failed to load your local data. Please log in again.', + ); + }, []); const callClearSensitiveData = React.useCallback( async (triggeredBy: string) => { @@ -212,9 +140,7 @@ commCoreModule.terminate(); } } - await recoverData( - recoveryFromDataHandlerActionSources.corruptedDatabaseDeletion, - ); + showCorruptionAlert(); })(); return; } @@ -257,14 +183,13 @@ } if (staffCanSee) { Alert.alert( - 'Error setting threadStore or messageStore', + 'Error setting clientDBStore', getMessageForException(setStoreException) ?? '{no exception message}', ); + } else { + showCorruptionAlert(); } - await recoverData( - recoveryFromDataHandlerActionSources.sqliteLoadFailure, - ); } finally { isRunning.current = false; } @@ -277,7 +202,7 @@ rehydrateConcluded, staffCanSee, initialStateLoaded, - recoverData, + showCorruptionAlert, callClearSensitiveData, mediaCacheContext, ]);