diff --git a/lib/components/keyserver-connection-handler.js b/lib/components/keyserver-connection-handler.js --- a/lib/components/keyserver-connection-handler.js +++ b/lib/components/keyserver-connection-handler.js @@ -255,6 +255,7 @@ const recoverySessionChange = await resolveKeyserverSessionInvalidation( dispatch, + dispatchActionPromise, cookie, urlPrefix, recoveryActionSource, @@ -306,6 +307,7 @@ }, [ dispatch, + dispatchActionPromise, cookie, urlPrefix, keyserverID, diff --git a/lib/keyserver-conn/keyserver-conn-types.js b/lib/keyserver-conn/keyserver-conn-types.js --- a/lib/keyserver-conn/keyserver-conn-types.js +++ b/lib/keyserver-conn/keyserver-conn-types.js @@ -1,10 +1,6 @@ // @flow -import type { - AuthActionSource, - LogInStartingPayload, - LogInResult, -} from '../types/account-types.js'; +import type { AuthActionSource } from '../types/account-types.js'; import type { Endpoint } from '../types/endpoints.js'; import type { Dispatch } from '../types/redux-types.js'; import type { @@ -27,12 +23,6 @@ failed: FAILED_ACTION_TYPE, }; -export type DispatchRecoveryAttempt = ( - actionTypes: ActionTypes<'LOG_IN_STARTED', 'LOG_IN_SUCCESS', 'LOG_IN_FAILED'>, - promise: Promise, - startingPayload: LogInStartingPayload, -) => Promise; - export const setNewSessionActionType = 'SET_NEW_SESSION'; export function setNewSession( dispatch: Dispatch, diff --git a/lib/keyserver-conn/recovery-utils.js b/lib/keyserver-conn/recovery-utils.js --- a/lib/keyserver-conn/recovery-utils.js +++ b/lib/keyserver-conn/recovery-utils.js @@ -1,12 +1,8 @@ // @flow -import { type ActionTypes, setNewSession } from './keyserver-conn-types.js'; +import { setNewSession } from './keyserver-conn-types.js'; import type { InitialNotifMessageOptions } from '../shared/crypto-utils.js'; -import type { - RecoveryActionSource, - LogInStartingPayload, - LogInResult, -} from '../types/account-types.js'; +import type { RecoveryActionSource } from '../types/account-types.js'; import type { Endpoint } from '../types/endpoints.js'; import type { Dispatch } from '../types/redux-types.js'; import type { ClientSessionChange } from '../types/session-types.js'; @@ -14,7 +10,7 @@ import type { CallSingleKeyserverEndpointOptions } from '../utils/call-single-keyserver-endpoint.js'; import { getConfig } from '../utils/config.js'; import { promiseAll } from '../utils/promises.js'; -import { wrapActionPromise } from '../utils/redux-promise-utils.js'; +import type { DispatchActionPromise } from '../utils/redux-promise-utils.js'; import { usingCommServicesAccessToken } from '../utils/services-utils.js'; // This function is a shortcut that tells us whether it's worth even trying to @@ -42,6 +38,7 @@ // legacy auth responder, which won't work on web and won't work for ETH users. async function resolveKeyserverSessionInvalidation( dispatch: Dispatch, + dispatchActionPromise: DispatchActionPromise, cookie: ?string, urlPrefix: string, recoveryActionSource: RecoveryActionSource, @@ -57,7 +54,6 @@ return null; } let newSessionChange = null; - let callSingleKeyserverEndpointCallback = null; const boundCallSingleKeyserverEndpoint = async ( endpoint: Endpoint, data: { +[key: string]: mixed }, @@ -77,34 +73,23 @@ keyserverID, ); }; - try { - const result = await callSingleKeyServerEndpoint( - cookie, - innerBoundSetNewSession, - () => new Promise(r => r(null)), - () => new Promise(r => r(null)), - urlPrefix, - null, - false, - null, - null, - endpoint, - data, - dispatch, - options, - false, - keyserverID, - ); - if (callSingleKeyserverEndpointCallback) { - callSingleKeyserverEndpointCallback(!!newSessionChange); - } - return result; - } catch (e) { - if (callSingleKeyserverEndpointCallback) { - callSingleKeyserverEndpointCallback(!!newSessionChange); - } - throw e; - } + return await callSingleKeyServerEndpoint( + cookie, + innerBoundSetNewSession, + () => new Promise(r => r(null)), + () => new Promise(r => r(null)), + urlPrefix, + null, + false, + null, + null, + endpoint, + data, + dispatch, + options, + false, + keyserverID, + ); }; const boundCallKeyserverEndpoint = ( @@ -125,28 +110,10 @@ return Promise.resolve({}); }; - const dispatchRecoveryAttempt = ( - actionTypes: ActionTypes< - 'LOG_IN_STARTED', - 'LOG_IN_SUCCESS', - 'LOG_IN_FAILED', - >, - promise: Promise, - inputStartingPayload: LogInStartingPayload, - ) => { - const startingPayload = { - ...inputStartingPayload, - authActionSource: recoveryActionSource, - }; - void dispatch( - wrapActionPromise(actionTypes, promise, null, startingPayload), - ); - return new Promise(r => (callSingleKeyserverEndpointCallback = r)); - }; await resolveKeyserverSessionInvalidationUsingNativeCredentials( boundCallSingleKeyserverEndpoint, boundCallKeyserverEndpoint, - dispatchRecoveryAttempt, + dispatchActionPromise, recoveryActionSource, keyserverID, getInitialNotificationsEncryptedMessage, diff --git a/lib/utils/config.js b/lib/utils/config.js --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -3,20 +3,18 @@ import invariant from 'invariant'; import type { CallSingleKeyserverEndpoint } from './call-single-keyserver-endpoint.js'; -import type { - DispatchRecoveryAttempt, - CallKeyserverEndpoint, -} from '../keyserver-conn/keyserver-conn-types.js'; +import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js'; import type { InitialNotifMessageOptions } from '../shared/crypto-utils.js'; import type { RecoveryActionSource } from '../types/account-types.js'; import type { OlmAPI } from '../types/crypto-types.js'; import type { PlatformDetails } from '../types/device-types.js'; +import type { DispatchActionPromise } from '../utils/redux-promise-utils.js'; export type Config = { +resolveKeyserverSessionInvalidationUsingNativeCredentials: ?( callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, callKeyserverEndpoint: CallKeyserverEndpoint, - dispatchRecoveryAttempt: DispatchRecoveryAttempt, + dispatchActionPromise: DispatchActionPromise, recoveryActionSource: RecoveryActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage: ( diff --git a/native/account/legacy-recover-keyserver-session.js b/native/account/legacy-recover-keyserver-session.js --- a/native/account/legacy-recover-keyserver-session.js +++ b/native/account/legacy-recover-keyserver-session.js @@ -2,13 +2,13 @@ import { logInActionTypes, logInRawAction } from 'lib/actions/user-actions.js'; import { - type DispatchRecoveryAttempt, type CallKeyserverEndpoint, CANCELLED_ERROR, } from 'lib/keyserver-conn/keyserver-conn-types.js'; import type { InitialNotifMessageOptions } from 'lib/shared/crypto-utils.js'; import type { RecoveryActionSource } from 'lib/types/account-types.js'; import type { CallSingleKeyserverEndpoint } from 'lib/utils/call-single-keyserver-endpoint.js'; +import type { DispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; import { fetchNativeKeychainCredentials } from './native-credentials.js'; import { store } from '../redux/redux-setup.js'; @@ -17,7 +17,7 @@ async function resolveKeyserverSessionInvalidationUsingNativeCredentials( callSingleKeyserverEndpoint: CallSingleKeyserverEndpoint, callKeyserverEndpoint: CallKeyserverEndpoint, - dispatchRecoveryAttempt: DispatchRecoveryAttempt, + dispatchActionPromise: DispatchActionPromise, recoveryActionSource: RecoveryActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage: ( @@ -43,7 +43,11 @@ const extraInfo = { ...baseExtraInfo, initialNotificationsEncryptedMessage }; const { calendarQuery } = extraInfo; - await dispatchRecoveryAttempt( + const startingPayload = { + calendarQuery, + authActionSource: recoveryActionSource, + }; + await dispatchActionPromise( logInActionTypes, logInRawAction(callKeyserverEndpoint)({ ...keychainCredentials, @@ -51,7 +55,8 @@ authActionSource: recoveryActionSource, keyserverIDs: [keyserverID], }), - { calendarQuery }, + undefined, + startingPayload, ); } 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 @@ -23,6 +23,7 @@ type RecoveryActionSource, } from 'lib/types/account-types.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 { authoritativeKeyserverID } from '../authoritative-keyserver.js'; @@ -47,6 +48,8 @@ const storeLoaded = useSelector(state => state.storeLoaded); const dispatch = useDispatch(); + const dispatchActionPromise = useDispatchActionPromise(); + const rehydrateConcluded = useSelector( state => !!(state._persist && state._persist.rehydrated), ); @@ -68,6 +71,7 @@ try { await resolveKeyserverSessionInvalidation( dispatch, + dispatchActionPromise, cookie, urlPrefix, source, @@ -92,6 +96,7 @@ [ cookie, dispatch, + dispatchActionPromise, staffCanSee, urlPrefix, getInitialNotificationsEncryptedMessage,