Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3378638
D9501.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D9501.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
@@ -32,12 +32,16 @@
SubscriptionUpdateResult,
} from '../types/subscription-types.js';
import type { UserInfo, PasswordUpdate } from '../types/user-types.js';
+import { extractKeyserverIDFromID } from '../utils/action-utils.js';
import type {
CallServerEndpoint,
CallServerEndpointOptions,
} from '../utils/call-server-endpoint.js';
import { getConfig } from '../utils/config.js';
+import type { CallKeyserverEndpoint } from '../utils/keyserver-call';
+import { useKeyserverCall } from '../utils/keyserver-call.js';
import sleep from '../utils/sleep.js';
+import { ashoatKeyserverID } from '../utils/validation-utils.js';
const logOutActionTypes = Object.freeze({
started: 'LOG_OUT_STARTED',
@@ -71,17 +75,24 @@
const claimUsernameCallServerEndpointOptions = { timeout: 500 };
const claimUsername =
(
- callServerEndpoint: CallServerEndpoint,
+ callKeyserverEndpoint: CallKeyserverEndpoint,
): (() => Promise<ClaimUsernameResponse>) =>
async () => {
- const response = await callServerEndpoint(
- 'claim_username',
- {},
- { ...claimUsernameCallServerEndpointOptions },
- );
- return response;
+ const requests = { [ashoatKeyserverID]: {} };
+ const responses = await callKeyserverEndpoint('claim_username', requests, {
+ ...claimUsernameCallServerEndpointOptions,
+ });
+ const response = responses[ashoatKeyserverID];
+ return {
+ message: response.message,
+ signature: response.signature,
+ };
};
+function useClaimUsername(): () => Promise<ClaimUsernameResponse> {
+ return useKeyserverCall(claimUsername);
+}
+
const deleteAccountActionTypes = Object.freeze({
started: 'DELETE_ACCOUNT_STARTED',
success: 'DELETE_ACCOUNT_SUCCESS',
@@ -248,21 +259,31 @@
});
const updateSubscription =
(
- callServerEndpoint: CallServerEndpoint,
+ callKeyserverEndpoint: CallKeyserverEndpoint,
): ((
- subscriptionUpdate: SubscriptionUpdateRequest,
+ input: SubscriptionUpdateRequest,
) => Promise<SubscriptionUpdateResult>) =>
- async subscriptionUpdate => {
- const response = await callServerEndpoint(
+ async input => {
+ const keyserverID = extractKeyserverIDFromID(input.threadID);
+ const requests = { [keyserverID]: input };
+
+ const responses = await callKeyserverEndpoint(
'update_user_subscription',
- subscriptionUpdate,
+ requests,
);
+ const response = responses[keyserverID];
return {
- threadID: subscriptionUpdate.threadID,
+ threadID: input.threadID,
subscription: response.threadSubscription,
};
};
+function useUpdateSubscription(): (
+ input: SubscriptionUpdateRequest,
+) => Promise<SubscriptionUpdateResult> {
+ return useKeyserverCall(updateSubscription);
+}
+
const setUserSettingsActionTypes = Object.freeze({
started: 'SET_USER_SETTINGS_STARTED',
success: 'SET_USER_SETTINGS_SUCCESS',
@@ -271,12 +292,23 @@
const setUserSettings =
(
- callServerEndpoint: CallServerEndpoint,
- ): ((userSettingsRequest: UpdateUserSettingsRequest) => Promise<void>) =>
- async userSettingsRequest => {
- await callServerEndpoint('update_user_settings', userSettingsRequest);
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ allKeyserverIDs: $ReadOnlyArray<string>,
+ ): ((input: UpdateUserSettingsRequest) => Promise<void>) =>
+ async input => {
+ const requests = {};
+ for (const keyserverID of allKeyserverIDs) {
+ requests[keyserverID] = input;
+ }
+ await callKeyserverEndpoint('update_user_settings', requests);
};
+function useSetUserSettings(): (
+ input: UpdateUserSettingsRequest,
+) => Promise<void> {
+ return useKeyserverCall(setUserSettings);
+}
+
const getSessionPublicKeys =
(
callServerEndpoint: CallServerEndpoint,
@@ -345,7 +377,7 @@
changeUserPasswordActionTypes,
changeUserPassword,
claimUsernameActionTypes,
- claimUsername,
+ useClaimUsername,
deleteAccount,
deleteAccountActionTypes,
getSessionPublicKeys,
@@ -362,9 +394,9 @@
searchUsersActionTypes,
exactSearchUser,
exactSearchUserActionTypes,
- setUserSettings,
+ useSetUserSettings,
setUserSettingsActionTypes,
- updateSubscription,
+ useUpdateSubscription,
updateSubscriptionActionTypes,
policyAcknowledgment,
policyAcknowledgmentActionTypes,
diff --git a/native/chat/settings/thread-settings-home-notifs.react.js b/native/chat/settings/thread-settings-home-notifs.react.js
--- a/native/chat/settings/thread-settings-home-notifs.react.js
+++ b/native/chat/settings/thread-settings-home-notifs.react.js
@@ -5,7 +5,7 @@
import {
updateSubscriptionActionTypes,
- updateSubscription,
+ useUpdateSubscription,
} from 'lib/actions/user-actions.js';
import type {
SubscriptionUpdateRequest,
@@ -13,10 +13,7 @@
} from 'lib/types/subscription-types.js';
import { type ThreadInfo } from 'lib/types/thread-types.js';
import type { DispatchActionPromise } from 'lib/utils/action-utils.js';
-import {
- useServerCall,
- useDispatchActionPromise,
-} from 'lib/utils/action-utils.js';
+import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import SingleLine from '../../components/single-line.react.js';
import { useStyles } from '../../themes/colors.js';
@@ -105,7 +102,7 @@
) {
const styles = useStyles(unboundStyles);
const dispatchActionPromise = useDispatchActionPromise();
- const callUpdateSubscription = useServerCall(updateSubscription);
+ const callUpdateSubscription = useUpdateSubscription();
return (
<ThreadSettingsHomeNotifs
{...props}
diff --git a/native/chat/settings/thread-settings-push-notifs.react.js b/native/chat/settings/thread-settings-push-notifs.react.js
--- a/native/chat/settings/thread-settings-push-notifs.react.js
+++ b/native/chat/settings/thread-settings-push-notifs.react.js
@@ -6,7 +6,7 @@
import {
updateSubscriptionActionTypes,
- updateSubscription,
+ useUpdateSubscription,
} from 'lib/actions/user-actions.js';
import type {
SubscriptionUpdateRequest,
@@ -14,10 +14,7 @@
} from 'lib/types/subscription-types.js';
import { type ThreadInfo } from 'lib/types/thread-types.js';
import type { DispatchActionPromise } from 'lib/utils/action-utils.js';
-import {
- useServerCall,
- useDispatchActionPromise,
-} from 'lib/utils/action-utils.js';
+import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import SingleLine from '../../components/single-line.react.js';
import SWMansionIcon from '../../components/swmansion-icon.react.js';
@@ -176,7 +173,7 @@
) {
const styles = useStyles(unboundStyles);
const dispatchActionPromise = useDispatchActionPromise();
- const callUpdateSubscription = useServerCall(updateSubscription);
+ const callUpdateSubscription = useUpdateSubscription();
const hasPushPermissions = useSelector(
state => state.deviceToken !== null && state.deviceToken !== undefined,
);
diff --git a/native/profile/default-notifications-preferences.react.js b/native/profile/default-notifications-preferences.react.js
--- a/native/profile/default-notifications-preferences.react.js
+++ b/native/profile/default-notifications-preferences.react.js
@@ -5,7 +5,7 @@
import { ScrollView } from 'react-native-gesture-handler';
import {
- setUserSettings,
+ useSetUserSettings,
setUserSettingsActionTypes,
} from 'lib/actions/user-actions.js';
import { registerFetchKey } from 'lib/reducers/loading-reducer.js';
@@ -18,7 +18,6 @@
} from 'lib/types/account-types.js';
import {
type DispatchActionPromise,
- useServerCall,
useDispatchActionPromise,
} from 'lib/utils/action-utils.js';
@@ -185,7 +184,7 @@
) {
const styles = useStyles(unboundStyles);
const dispatchActionPromise = useDispatchActionPromise();
- const changeNotificationSettings = useServerCall(setUserSettings);
+ const changeNotificationSettings = useSetUserSettings();
const defaultNotification = userSettingsTypes.DEFAULT_NOTIFICATIONS;
const selectedDefaultNotification = useSelector<NotificationTypes>(
diff --git a/web/modals/threads/notifications/notifications-modal.react.js b/web/modals/threads/notifications/notifications-modal.react.js
--- a/web/modals/threads/notifications/notifications-modal.react.js
+++ b/web/modals/threads/notifications/notifications-modal.react.js
@@ -3,16 +3,13 @@
import * as React from 'react';
import {
- updateSubscription,
+ useUpdateSubscription,
updateSubscriptionActionTypes,
} from 'lib/actions/user-actions.js';
import { canPromoteSidebar } from 'lib/hooks/promote-sidebar.react.js';
import { threadInfoSelector } from 'lib/selectors/thread-selectors.js';
import { threadIsSidebar } from 'lib/shared/thread-utils.js';
-import {
- useServerCall,
- useDispatchActionPromise,
-} from 'lib/utils/action-utils.js';
+import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
import css from './notifications-modal.css';
import AllNotifsIllustration from '../../../assets/all-notifs.react.js';
@@ -169,7 +166,7 @@
const dispatchActionPromise = useDispatchActionPromise();
- const callUpdateSubscription = useServerCall(updateSubscription);
+ const callUpdateSubscription = useUpdateSubscription();
const onClickSave = React.useCallback(() => {
dispatchActionPromise(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 12:03 PM (21 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2593934
Default Alt Text
D9501.diff (9 KB)
Attached To
Mode
D9501: [lib][web][native] Refactor actions in user-actions.js pt.1
Attached
Detach File
Event Timeline
Log In to Comment