diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -5,7 +5,6 @@ import { preRequestUserStateSelector } from '../selectors/account-selectors.js'; import threadWatcher from '../shared/thread-watcher.js'; import type { - LogOutResult, LogInInfo, LogInResult, RegisterResult, @@ -18,6 +17,7 @@ KeyserverAuthResult, KeyserverAuthInfo, KeyserverAuthRequest, + KeyserverLogOutResult, } from '../types/account-types.js'; import type { UpdateUserAvatarRequest, @@ -71,6 +71,11 @@ anonymous: true, }; +export type KeyserverLogOutInput = { + preRequestUserState: PreRequestUserState, + keyserverIDs?: $ReadOnlyArray, +}; + const logOutActionTypes = Object.freeze({ started: 'LOG_OUT_STARTED', success: 'LOG_OUT_SUCCESS', @@ -80,10 +85,12 @@ ( callKeyserverEndpoint: CallKeyserverEndpoint, allKeyserverIDs: $ReadOnlyArray, - ): ((input: PreRequestUserState) => Promise) => - async preRequestUserState => { + ): ((input: KeyserverLogOutInput) => Promise) => + async input => { + const { preRequestUserState } = input; + const keyserverIDs = input.keyserverIDs ?? allKeyserverIDs; const requests: { [string]: {} } = {}; - for (const keyserverID of allKeyserverIDs) { + for (const keyserverID of keyserverIDs) { requests[keyserverID] = {}; } @@ -98,15 +105,18 @@ ]); } catch {} const currentUserInfo = response ? loggedOutUserInfo : null; - return { currentUserInfo, preRequestUserState }; + return { currentUserInfo, preRequestUserState, keyserverIDs }; }; -function useLogOut(): () => Promise { +function useLogOut(): ( + keyserverIDs?: $ReadOnlyArray, +) => Promise { const preRequestUserState = useSelector(preRequestUserStateSelector); const callKeyserverLogOut = useKeyserverCall(logOut); return React.useCallback( - () => callKeyserverLogOut(preRequestUserState), + (keyserverIDs?: $ReadOnlyArray) => + callKeyserverLogOut({ preRequestUserState, keyserverIDs }), [callKeyserverLogOut, preRequestUserState], ); } @@ -146,21 +156,34 @@ ( callKeyserverEndpoint: CallKeyserverEndpoint, allKeyserverIDs: $ReadOnlyArray, - ): ((input: PreRequestUserState) => Promise) => - async preRequestUserState => { + ): ((input: KeyserverLogOutInput) => Promise) => + async input => { + const { preRequestUserState } = input; + const keyserverIDs = input.keyserverIDs ?? allKeyserverIDs; const requests: { [string]: {} } = {}; - for (const keyserverID of allKeyserverIDs) { + for (const keyserverID of keyserverIDs) { requests[keyserverID] = {}; } await callKeyserverEndpoint('delete_account', requests); - return { currentUserInfo: loggedOutUserInfo, preRequestUserState }; + return { + currentUserInfo: loggedOutUserInfo, + preRequestUserState, + keyserverIDs, + }; }; function useDeleteKeyserverAccount(): ( - input: PreRequestUserState, -) => Promise { - return useKeyserverCall(deleteKeyserverAccount); + keyserverIDs?: $ReadOnlyArray, +) => Promise { + const preRequestUserState = useSelector(preRequestUserStateSelector); + const callKeyserverDeleteAccount = useKeyserverCall(deleteKeyserverAccount); + + return React.useCallback( + (keyserverIDs?: $ReadOnlyArray) => + callKeyserverDeleteAccount({ preRequestUserState, keyserverIDs }), + [callKeyserverDeleteAccount, preRequestUserState], + ); } const deleteIdentityAccountActionTypes = Object.freeze({ diff --git a/lib/types/account-types.js b/lib/types/account-types.js --- a/lib/types/account-types.js +++ b/lib/types/account-types.js @@ -34,6 +34,11 @@ +preRequestUserState: PreRequestUserState, }; +export type KeyserverLogOutResult = { + ...LogOutResult, + +keyserverIDs: $ReadOnlyArray, +}; + export type LogOutResponse = { +currentUserInfo: LoggedOutUserInfo, }; diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -2,6 +2,7 @@ import type { LogOutResult, + KeyserverLogOutResult, LogInStartingPayload, LogInResult, RegisterResult, @@ -196,7 +197,7 @@ } | { +type: 'LOG_OUT_SUCCESS', - +payload: LogOutResult, + +payload: KeyserverLogOutResult, +loadingInfo: LoadingInfo, } | { @@ -228,7 +229,7 @@ } | { +type: 'DELETE_KEYSERVER_ACCOUNT_SUCCESS', - +payload: LogOutResult, + +payload: KeyserverLogOutResult, +loadingInfo: LoadingInfo, } | { diff --git a/native/crash.react.js b/native/crash.react.js --- a/native/crash.react.js +++ b/native/crash.react.js @@ -19,10 +19,8 @@ sendReport, } from 'lib/actions/report-actions.js'; import { logOutActionTypes, useLogOut } from 'lib/actions/user-actions.js'; -import { preRequestUserStateSelector } from 'lib/selectors/account-selectors.js'; -import type { LogOutResult } from 'lib/types/account-types.js'; +import type { KeyserverLogOutResult } from 'lib/types/account-types.js'; import { type ErrorData, reportTypes } from 'lib/types/report-types.js'; -import type { PreRequestUserState } from 'lib/types/session-types.js'; import { actionLogger } from 'lib/utils/action-logger.js'; import { type DispatchActionPromise, @@ -42,7 +40,6 @@ import ConnectedStatusBar from './connected-status-bar.react.js'; import { commCoreModule } from './native-modules.js'; import { persistConfig, codeVersion } from './redux/persist.js'; -import { useSelector } from './redux/redux-utils.js'; import { wipeAndExit } from './utils/crash-utils.js'; const errorTitles = ['Oh no!!', 'Womp womp womp...']; @@ -52,12 +49,10 @@ }; type Props = { ...BaseProps, - // Redux state - +preRequestUserState: PreRequestUserState, // Redux dispatch functions +dispatchActionPromise: DispatchActionPromise, // async functions that hit server APIs - +logOut: (preRequestUserState: PreRequestUserState) => Promise, + +logOut: () => Promise, +crashReportingEnabled: boolean, }; type State = { @@ -200,7 +195,7 @@ async logOutAndExit() { try { - await this.props.logOut(this.props.preRequestUserState); + await this.props.logOut(); } catch (e) {} await wipeAndExit(); } @@ -284,15 +279,12 @@ const ConnectedCrash: React.ComponentType = React.memo( function ConnectedCrash(props: BaseProps) { - const preRequestUserState = useSelector(preRequestUserStateSelector); - const dispatchActionPromise = useDispatchActionPromise(); const callLogOut = useLogOut(); const crashReportingEnabled = useIsReportEnabled('crashReports'); return ( { try { await deleteNativeCredentialsFor(); - return await callDeleteKeyserverAccount(preRequestUserState); + return await callDeleteKeyserverAccount(); } catch (e) { Alert.alert( 'Unknown error deleting keyserver account', @@ -83,7 +81,7 @@ ); throw e; } - }, [callDeleteKeyserverAccount, preRequestUserState]); + }, [callDeleteKeyserverAccount]); const deleteIdentityAction = React.useCallback(async () => { try { diff --git a/native/profile/profile-screen.react.js b/native/profile/profile-screen.react.js --- a/native/profile/profile-screen.react.js +++ b/native/profile/profile-screen.react.js @@ -7,7 +7,7 @@ import { useStringForUser } from 'lib/hooks/ens-cache.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; import { accountHasPassword } from 'lib/shared/account-utils.js'; -import type { LogOutResult } from 'lib/types/account-types.js'; +import type { KeyserverLogOutResult } from 'lib/types/account-types.js'; import { type CurrentUserInfo } from 'lib/types/user-types.js'; import { type DispatchActionPromise, @@ -152,7 +152,7 @@ +colors: Colors, +styles: $ReadOnly, +dispatchActionPromise: DispatchActionPromise, - +logOut: () => Promise, + +logOut: () => Promise, +staffCanSee: boolean, +stringForUser: ?string, +isAccountWithPassword: boolean, diff --git a/web/settings/account-delete-modal.react.js b/web/settings/account-delete-modal.react.js --- a/web/settings/account-delete-modal.react.js +++ b/web/settings/account-delete-modal.react.js @@ -10,7 +10,6 @@ } from 'lib/actions/user-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import SWMansionIcon from 'lib/components/SWMansionIcon.react.js'; -import { preRequestUserStateSelector } from 'lib/selectors/account-selectors.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import { usingCommServicesAccessToken } from 'lib/utils/services-utils.js'; @@ -30,7 +29,6 @@ const AccountDeleteModal: React.ComponentType<{}> = React.memo<{}>( function AccountDeleteModal(): React.Node { - const preRequestUserState = useSelector(preRequestUserStateSelector); const isDeleteKeyserverAccountLoading = useSelector( state => deleteKeyserverAccountLoadingStatusSelector(state) === 'loading', ); @@ -81,7 +79,7 @@ const deleteKeyserverAction = React.useCallback(async () => { try { setKeyserverErrorMessage(''); - const response = await callDeleteKeyserverAccount(preRequestUserState); + const response = await callDeleteKeyserverAccount(); // This check ensures that we don't call `popModal()` twice if (!usingCommServicesAccessToken) { popModal(); @@ -93,7 +91,7 @@ ); throw e; } - }, [callDeleteKeyserverAccount, preRequestUserState, popModal]); + }, [callDeleteKeyserverAccount, popModal]); const deleteIdentityAction = React.useCallback(async () => { try {