Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3182308
D9501.id32035.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.id32035.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,25 @@
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 response = (
+ await callKeyserverEndpoint('claim_username', requests, {
+ ...claimUsernameCallServerEndpointOptions,
+ })
+ )[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',
@@ -251,21 +263,29 @@
});
const updateSubscription =
(
- callServerEndpoint: CallServerEndpoint,
+ callKeyserverEndpoint: CallKeyserverEndpoint,
): ((
- subscriptionUpdate: SubscriptionUpdateRequest,
+ input: SubscriptionUpdateRequest,
) => Promise<SubscriptionUpdateResult>) =>
- async subscriptionUpdate => {
- const response = await callServerEndpoint(
- 'update_user_subscription',
- subscriptionUpdate,
- );
+ async input => {
+ const keyserverID = extractKeyserverIDFromID(input.threadID);
+ const requests = { [keyserverID]: input };
+
+ const response = (
+ await callKeyserverEndpoint('update_user_subscription', requests)
+ )[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',
@@ -274,12 +294,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,
@@ -348,7 +379,7 @@
changeUserPasswordActionTypes,
changeUserPassword,
claimUsernameActionTypes,
- claimUsername,
+ useClaimUsername,
deleteAccount,
deleteAccountActionTypes,
getSessionPublicKeys,
@@ -365,9 +396,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
Sat, Nov 9, 7:43 AM (20 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2450237
Default Alt Text
D9501.id32035.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