Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3366323
D9645.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D9645.diff
View Options
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<LogOutResult>) =>
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ allKeyserverIDs: $ReadOnlyArray<string>,
+ ): ((input: PreRequestUserState) => Promise<LogOutResult>) =>
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<LogOutResult> {
+ return useKeyserverCall(logOut);
+}
+
const claimUsernameActionTypes = Object.freeze({
started: 'CLAIM_USERNAME_STARTED',
success: 'CLAIM_USERNAME_SUCCESS',
@@ -100,13 +118,25 @@
});
const deleteAccount =
(
- callServerEndpoint: CallServerEndpoint,
- ): ((preRequestUserState: PreRequestUserState) => Promise<LogOutResult>) =>
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ allKeyserverIDs: $ReadOnlyArray<string>,
+ ): ((input: PreRequestUserState) => Promise<LogOutResult>) =>
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<LogOutResult> {
+ return useKeyserverCall(deleteAccount);
+}
+
const registerActionTypes = Object.freeze({
started: 'REGISTER_STARTED',
success: 'REGISTER_SUCCESS',
@@ -386,7 +416,7 @@
changeUserPassword,
claimUsernameActionTypes,
useClaimUsername,
- deleteAccount,
+ useDeleteAccount,
deleteAccountActionTypes,
getSessionPublicKeys,
getOlmSessionInitializationDataActionTypes,
@@ -394,7 +424,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 (
<Crash
diff --git a/native/profile/delete-account.react.js b/native/profile/delete-account.react.js
--- a/native/profile/delete-account.react.js
+++ b/native/profile/delete-account.react.js
@@ -6,14 +6,11 @@
import {
deleteAccountActionTypes,
- deleteAccount,
+ useDeleteAccount,
} from 'lib/actions/user-actions.js';
import { preRequestUserStateSelector } from 'lib/selectors/account-selectors.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
-import {
- useServerCall,
- useDispatchActionPromise,
-} from 'lib/utils/action-utils.js';
+import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import { deleteNativeCredentialsFor } from '../account/native-credentials.js';
import Button from '../components/button.react.js';
@@ -32,7 +29,7 @@
const styles = useStyles(unboundStyles);
const dispatchActionPromise = useDispatchActionPromise();
- const callDeleteAccount = useServerCall(deleteAccount);
+ const callDeleteAccount = useDeleteAccount();
const buttonContent =
loadingStatus === 'loading' ? (
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
@@ -3,7 +3,7 @@
import * as React from 'react';
import { View, Text, Platform, ScrollView } from 'react-native';
-import { logOutActionTypes, logOut } from 'lib/actions/user-actions.js';
+import { logOutActionTypes, useLogOut } from 'lib/actions/user-actions.js';
import { useStringForUser } from 'lib/hooks/ens-cache.js';
import { preRequestUserStateSelector } from 'lib/selectors/account-selectors.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
@@ -14,7 +14,6 @@
import {
type DispatchActionPromise,
useDispatchActionPromise,
- useServerCall,
} from 'lib/utils/action-utils.js';
import type { ProfileNavigationProp } from './profile.react.js';
@@ -439,7 +438,7 @@
useSelector(logOutLoadingStatusSelector) === 'loading';
const colors = useColors();
const styles = useStyles(unboundStyles);
- const callLogOut = useServerCall(logOut);
+ const callLogOut = useLogOut();
const dispatchActionPromise = useDispatchActionPromise();
const staffCanSee = useStaffCanSee();
const stringForUser = useStringForUser(currentUserInfo);
diff --git a/native/socket.react.js b/native/socket.react.js
--- a/native/socket.react.js
+++ b/native/socket.react.js
@@ -4,7 +4,7 @@
import * as React from 'react';
import { useDispatch } from 'react-redux';
-import { logOut, logOutActionTypes } from 'lib/actions/user-actions.js';
+import { useLogOut, logOutActionTypes } from 'lib/actions/user-actions.js';
import { preRequestUserStateSelector } from 'lib/selectors/account-selectors.js';
import {
cookieSelector,
@@ -17,7 +17,6 @@
import Socket, { type BaseSocketProps } from 'lib/socket/socket.react.js';
import { logInActionSources } from 'lib/types/account-types.js';
import {
- useServerCall,
useDispatchActionPromise,
fetchNewCookieFromNativeCredentials,
} from 'lib/utils/action-utils.js';
@@ -107,7 +106,7 @@
const dispatch = useDispatch();
const dispatchActionPromise = useDispatchActionPromise();
- const callLogOut = useServerCall(logOut);
+ const callLogOut = useLogOut();
const socketCrashLoopRecovery = React.useCallback(async () => {
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,17 +2,14 @@
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 { useTunnelbroker } from 'lib/tunnelbroker/tunnelbroker-context.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';
@@ -27,7 +24,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 { useSelector } from './redux/redux-utils.js';
import {
@@ -64,7 +61,7 @@
const dispatch = useDispatch();
const dispatchActionPromise = useDispatchActionPromise();
- const callLogOut = useServerCall(logOut);
+ const callLogOut = useLogOut();
const lastCommunicatedPlatformDetails = useSelector(
lastCommunicatedPlatformDetailsSelector,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 10:52 AM (20 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2584323
Default Alt Text
D9645.diff (11 KB)
Attached To
Mode
D9645: [lib][web][native] Refactor actions in user-actions.js pt.2
Attached
Detach File
Event Timeline
Log In to Comment