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) => 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 { + 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) => - 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 { + 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) => - async userSettingsRequest => { - await callServerEndpoint('update_user_settings', userSettingsRequest); + callKeyserverEndpoint: CallKeyserverEndpoint, + allKeyserverIDs: $ReadOnlyArray, + ): ((input: UpdateUserSettingsRequest) => Promise) => + async input => { + const requests = {}; + for (const keyserverID of allKeyserverIDs) { + requests[keyserverID] = input; + } + await callKeyserverEndpoint('update_user_settings', requests); }; +function useSetUserSettings(): ( + input: UpdateUserSettingsRequest, +) => Promise { + 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 ( 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( 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(