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 @@ -31,7 +31,11 @@ SubscriptionUpdateRequest, SubscriptionUpdateResult, } from '../types/subscription-types.js'; -import type { UserInfo, PasswordUpdate } from '../types/user-types.js'; +import type { + UserInfo, + PasswordUpdate, + LoggedOutUserInfo, +} from '../types/user-types.js'; import { extractKeyserverIDFromID } from '../utils/action-utils.js'; import type { CallServerEndpoint, @@ -43,6 +47,10 @@ import sleep from '../utils/sleep.js'; import { ashoatKeyserverID } from '../utils/validation-utils.js'; +const loggedOutUserInfo: LoggedOutUserInfo = { + anonymous: true, +}; + const logOutActionTypes = Object.freeze({ started: 'LOG_OUT_STARTED', success: 'LOG_OUT_SUCCESS', @@ -50,23 +58,33 @@ }); const logOut = ( - callServerEndpoint: CallServerEndpoint, - ): ((preRequestUserState: PreRequestUserState) => Promise) => + callKeyserverEndpoint: CallKeyserverEndpoint, + allKeyserverIDs: $ReadOnlyArray, + ): ((input: PreRequestUserState) => Promise) => async preRequestUserState => { + const requests = {}; + for (const keyserverID of allKeyserverIDs) { + requests[keyserverID] = {}; + } + let response = null; try { response = await Promise.race([ - callServerEndpoint('log_out', {}), + callKeyserverEndpoint('log_out', requests), (async () => { await sleep(500); throw new Error('log_out took more than 500ms'); })(), ]); } catch {} - const currentUserInfo = response ? response.currentUserInfo : null; + const currentUserInfo = response ? loggedOutUserInfo : null; return { currentUserInfo, preRequestUserState }; }; +function useLogOut(): (input: PreRequestUserState) => Promise { + return useKeyserverCall(logOut); +} + const claimUsernameActionTypes = Object.freeze({ started: 'CLAIM_USERNAME_STARTED', success: 'CLAIM_USERNAME_SUCCESS', @@ -101,13 +119,25 @@ }); const deleteAccount = ( - callServerEndpoint: CallServerEndpoint, - ): ((preRequestUserState: PreRequestUserState) => Promise) => + callKeyserverEndpoint: CallKeyserverEndpoint, + allKeyserverIDs: $ReadOnlyArray, + ): ((input: PreRequestUserState) => Promise) => async preRequestUserState => { - const response = await callServerEndpoint('delete_account'); - return { currentUserInfo: response.currentUserInfo, preRequestUserState }; + const requests = {}; + for (const keyserverID of allKeyserverIDs) { + requests[keyserverID] = {}; + } + + await callKeyserverEndpoint('delete_account', requests); + return { currentUserInfo: loggedOutUserInfo, preRequestUserState }; }; +function useDeleteAccount(): ( + input: PreRequestUserState, +) => Promise { + return useKeyserverCall(deleteAccount); +} + const registerActionTypes = Object.freeze({ started: 'REGISTER_STARTED', success: 'REGISTER_SUCCESS', @@ -385,7 +415,7 @@ changeUserPassword, claimUsernameActionTypes, useClaimUsername, - deleteAccount, + useDeleteAccount, deleteAccountActionTypes, getSessionPublicKeys, getOlmSessionInitializationDataActionTypes, @@ -393,7 +423,7 @@ mergeUserInfos, logIn, logInActionTypes, - logOut, + useLogOut, logOutActionTypes, register, registerActionTypes, diff --git a/native/crash.react.js b/native/crash.react.js --- a/native/crash.react.js +++ b/native/crash.react.js @@ -18,7 +18,7 @@ sendReportActionTypes, sendReport, } from 'lib/actions/report-actions.js'; -import { logOutActionTypes, logOut } from 'lib/actions/user-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 ErrorData, reportTypes } from 'lib/types/report-types.js'; @@ -26,7 +26,6 @@ import { actionLogger } from 'lib/utils/action-logger.js'; import { type DispatchActionPromise, - useServerCall, useDispatchActionPromise, } from 'lib/utils/action-utils.js'; import { @@ -278,7 +277,7 @@ const preRequestUserState = useSelector(preRequestUserStateSelector); const dispatchActionPromise = useDispatchActionPromise(); - const callLogOut = useServerCall(logOut); + const callLogOut = useLogOut(); const crashReportingEnabled = useIsReportEnabled('crashReports'); return ( { if (!accountHasPassword(currentUserInfo)) { 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 @@ -3,17 +3,14 @@ import * as React from 'react'; import { - deleteAccount, + useDeleteAccount, deleteAccountActionTypes, } 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, - useServerCall, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import css from './account-delete-modal.css'; import Button, { buttonThemes } from '../components/button.react.js'; @@ -30,7 +27,7 @@ const inputDisabled = useSelector( state => deleteAccountLoadingStatusSelector(state) === 'loading', ); - const callDeleteAccount = useServerCall(deleteAccount); + const callDeleteAccount = useDeleteAccount(); const dispatchActionPromise = useDispatchActionPromise(); const { popModal } = useModalContext(); diff --git a/web/settings/account-settings.react.js b/web/settings/account-settings.react.js --- a/web/settings/account-settings.react.js +++ b/web/settings/account-settings.react.js @@ -2,16 +2,13 @@ import * as React from 'react'; -import { logOut, logOutActionTypes } from 'lib/actions/user-actions.js'; +import { useLogOut, logOutActionTypes } from 'lib/actions/user-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import SWMansionIcon from 'lib/components/SWMansionIcon.react.js'; import { useStringForUser } from 'lib/hooks/ens-cache.js'; import { preRequestUserStateSelector } from 'lib/selectors/account-selectors.js'; import { accountHasPassword } from 'lib/shared/account-utils.js'; -import { - useDispatchActionPromise, - useServerCall, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import css from './account-settings.css'; import AppearanceChangeModal from './appearance-change-modal.react.js'; @@ -24,7 +21,7 @@ import { useStaffCanSee } from '../utils/staff-utils.js'; function AccountSettings(): React.Node { - const sendLogoutRequest = useServerCall(logOut); + const sendLogoutRequest = useLogOut(); const preRequestUserState = useSelector(preRequestUserStateSelector); const dispatchActionPromise = useDispatchActionPromise(); const logOutUser = React.useCallback( diff --git a/web/socket.react.js b/web/socket.react.js --- a/web/socket.react.js +++ b/web/socket.react.js @@ -4,7 +4,7 @@ import * as React from 'react'; import { useDispatch } from 'react-redux'; -import { logOut } from 'lib/actions/user-actions.js'; +import { useLogOut } from 'lib/actions/user-actions.js'; import { preRequestUserStateSelector } from 'lib/selectors/account-selectors.js'; import { cookieSelector, @@ -13,10 +13,7 @@ lastCommunicatedPlatformDetailsSelector, } from 'lib/selectors/keyserver-selectors.js'; import Socket, { type BaseSocketProps } from 'lib/socket/socket.react.js'; -import { - useServerCall, - useDispatchActionPromise, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { useSelector } from './redux/redux-utils.js'; @@ -65,7 +62,7 @@ const dispatch = useDispatch(); const dispatchActionPromise = useDispatchActionPromise(); - const callLogOut = useServerCall(logOut); + const callLogOut = useLogOut(); const lastCommunicatedPlatformDetails = useSelector( lastCommunicatedPlatformDetailsSelector(ashoatKeyserverID),