diff --git a/lib/actions/thread-actions.js b/lib/actions/thread-actions.js --- a/lib/actions/thread-actions.js +++ b/lib/actions/thread-actions.js @@ -24,6 +24,10 @@ import { useKeyserverCall } from '../utils/keyserver-call.js'; import { values } from '../utils/objects.js'; +export type DeleteThreadInput = { + +threadID: string, +}; + const deleteThreadActionTypes = Object.freeze({ started: 'DELETE_THREAD_STARTED', success: 'DELETE_THREAD_SUCCESS', @@ -32,20 +36,23 @@ const deleteThread = ( callServerEndpoint: CallServerEndpoint, - ): (( - threadID: string, - currentAccountPassword: ?string, - ) => Promise) => - async (threadID, currentAccountPassword) => { - const response = await callServerEndpoint('delete_thread', { - threadID, - accountPassword: currentAccountPassword, - }); + ): ((input: DeleteThreadInput) => Promise) => + async input => { + const keyserverID = extractKeyserverIDFromID(input.threadID); + const requests = { [keyserverID]: input }; + + const responses = await callServerEndpoint('delete_thread', requests); + const response = responses[keyserverID]; return { updatesResult: response.updatesResult, }; }; +function useDeleteThread(): ( + input: DeleteThreadInput, +) => Promise { + return useKeyserverCall(deleteThread); +} const changeThreadSettingsActionTypes = Object.freeze({ started: 'CHANGE_THREAD_SETTINGS_STARTED', success: 'CHANGE_THREAD_SETTINGS_SUCCESS', @@ -53,21 +60,31 @@ }); const changeThreadSettings = ( - callServerEndpoint: CallServerEndpoint, - ): ((request: UpdateThreadRequest) => Promise) => - async request => { + callKeyserverEndpoint: CallKeyserverEndpoint, + ): ((input: UpdateThreadRequest) => Promise) => + async input => { invariant( - Object.keys(request.changes).length > 0, + Object.keys(input.changes).length > 0, 'No changes provided to changeThreadSettings!', ); - const response = await callServerEndpoint('update_thread', request); + const keyserverID = extractKeyserverIDFromID(input.threadID); + const requests = { [keyserverID]: input }; + + const responses = await callKeyserverEndpoint('update_thread', requests); + const response = responses[keyserverID]; return { - threadID: request.threadID, + threadID: input.threadID, updatesResult: response.updatesResult, newMessageInfos: response.newMessageInfos, }; }; +function useChangeThreadSettings(): ( + input: UpdateThreadRequest, +) => Promise { + return useKeyserverCall(changeThreadSettings); +} + export type RemoveUsersFromThreadInput = { +threadID: string, +memberIDs: $ReadOnlyArray, @@ -320,9 +337,9 @@ export { deleteThreadActionTypes, - deleteThread, + useDeleteThread, changeThreadSettingsActionTypes, - changeThreadSettings, + useChangeThreadSettings, removeUsersFromThreadActionTypes, useRemoveUsersFromThread, changeThreadMemberRolesActionTypes, diff --git a/lib/components/base-edit-thread-avatar-provider.react.js b/lib/components/base-edit-thread-avatar-provider.react.js --- a/lib/components/base-edit-thread-avatar-provider.react.js +++ b/lib/components/base-edit-thread-avatar-provider.react.js @@ -3,17 +3,14 @@ import * as React from 'react'; import { - changeThreadSettings, + useChangeThreadSettings, changeThreadSettingsActionTypes, } from '../actions/thread-actions.js'; import { createLoadingStatusSelector } from '../selectors/loading-selectors.js'; import type { UpdateUserAvatarRequest } from '../types/avatar-types.js'; import type { LoadingStatus } from '../types/loading-types.js'; import type { UpdateThreadRequest } from '../types/thread-types.js'; -import { - useDispatchActionPromise, - useServerCall, -} from '../utils/action-utils.js'; +import { useDispatchActionPromise } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; export type EditThreadAvatarContextType = { @@ -43,7 +40,7 @@ ); const dispatchActionPromise = useDispatchActionPromise(); - const changeThreadSettingsCall = useServerCall(changeThreadSettings); + const changeThreadSettingsCall = useChangeThreadSettings(); const [ threadAvatarMediaUploadInProgress, diff --git a/lib/hooks/promote-sidebar.react.js b/lib/hooks/promote-sidebar.react.js --- a/lib/hooks/promote-sidebar.react.js +++ b/lib/hooks/promote-sidebar.react.js @@ -4,7 +4,7 @@ import { changeThreadSettingsActionTypes, - changeThreadSettings, + useChangeThreadSettings, } from '../actions/thread-actions.js'; import { createLoadingStatusSelector } from '../selectors/loading-selectors.js'; import { threadInfoSelector } from '../selectors/thread-selectors.js'; @@ -16,10 +16,7 @@ import { threadPermissions } from '../types/thread-permission-types.js'; import { threadTypes } from '../types/thread-types-enum.js'; import { type ThreadInfo } from '../types/thread-types.js'; -import { - useServerCall, - useDispatchActionPromise, -} from '../utils/action-utils.js'; +import { useDispatchActionPromise } from '../utils/action-utils.js'; import { useSelector } from '../utils/redux-utils.js'; function canPromoteSidebar( @@ -52,7 +49,7 @@ onError?: () => mixed, ): PromoteSidebarType { const dispatchActionPromise = useDispatchActionPromise(); - const callChangeThreadSettings = useServerCall(changeThreadSettings); + const callChangeThreadSettings = useChangeThreadSettings(); const loadingStatusSelector = createLoadingStatusSelector( changeThreadSettingsActionTypes, ); diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js --- a/lib/shared/messages/text-message-spec.js +++ b/lib/shared/messages/text-message-spec.js @@ -12,7 +12,7 @@ import { assertSingleMessageInfo, joinResult } from './utils.js'; import { changeThreadSettingsActionTypes, - changeThreadSettings, + useChangeThreadSettings, } from '../../actions/thread-actions.js'; import { messageTypes } from '../../types/message-types-enum.js'; import type { @@ -29,10 +29,7 @@ import { threadTypes } from '../../types/thread-types-enum.js'; import type { ThreadInfo } from '../../types/thread-types.js'; import type { RelativeUserInfo } from '../../types/user-types.js'; -import { - useDispatchActionPromise, - useServerCall, -} from '../../utils/action-utils.js'; +import { useDispatchActionPromise } from '../../utils/action-utils.js'; import { ET } from '../../utils/entity-text.js'; import { type ASTNode, @@ -285,7 +282,7 @@ useCreationSideEffectsFunc: () => { const dispatchActionPromise = useDispatchActionPromise(); - const callChangeThreadSettings = useServerCall(changeThreadSettings); + const callChangeThreadSettings = useChangeThreadSettings(); return async ( messageInfo: RawTextMessageInfo, threadInfo: ThreadInfo, diff --git a/lib/types/thread-types.js b/lib/types/thread-types.js --- a/lib/types/thread-types.js +++ b/lib/types/thread-types.js @@ -242,7 +242,7 @@ export type ThreadDeletionRequest = { +threadID: string, - +accountPassword?: ?string, + +accountPassword?: empty, }; export type RemoveMembersRequest = { diff --git a/native/chat/settings/add-users-modal.react.js b/native/chat/settings/add-users-modal.react.js --- a/native/chat/settings/add-users-modal.react.js +++ b/native/chat/settings/add-users-modal.react.js @@ -5,7 +5,7 @@ import { changeThreadSettingsActionTypes, - changeThreadSettings, + useChangeThreadSettings, } from 'lib/actions/thread-actions.js'; import { useENSNames } from 'lib/hooks/ens-cache.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; @@ -18,10 +18,7 @@ import { threadActualMembers } from 'lib/shared/thread-utils.js'; import { type ThreadInfo } from 'lib/types/thread-types.js'; import { type AccountUserInfo } from 'lib/types/user-types.js'; -import { - useServerCall, - useDispatchActionPromise, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import Button from '../../components/button.react.js'; import Modal from '../../components/modal.react.js'; @@ -71,7 +68,7 @@ goBackOnce(); }, [goBackOnce]); - const callChangeThreadSettings = useServerCall(changeThreadSettings); + const callChangeThreadSettings = useChangeThreadSettings(); const userInfoInputIDs = userInfoInputArray.map(userInfo => userInfo.id); const { route } = props; const { threadInfo } = route.params; diff --git a/native/chat/settings/color-selector-modal.react.js b/native/chat/settings/color-selector-modal.react.js --- a/native/chat/settings/color-selector-modal.react.js +++ b/native/chat/settings/color-selector-modal.react.js @@ -6,7 +6,7 @@ import { changeThreadSettingsActionTypes, - changeThreadSettings, + useChangeThreadSettings, } from 'lib/actions/thread-actions.js'; import { type ThreadInfo, @@ -14,10 +14,7 @@ type UpdateThreadRequest, } 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 ColorSelector from '../../components/color-selector.react.js'; import Modal from '../../components/modal.react.js'; @@ -176,7 +173,7 @@ const windowWidth = useSelector(state => state.dimensions.width); const dispatchActionPromise = useDispatchActionPromise(); - const callChangeThreadSettings = useServerCall(changeThreadSettings); + const callChangeThreadSettings = useChangeThreadSettings(); return ( Promise, + +deleteThread: (input: DeleteThreadInput) => Promise, // withNavContext +navDispatch: (action: NavAction) => void, }; @@ -161,7 +161,7 @@ payload: { threadIDs: [threadInfo.id] }, }); try { - const result = await this.props.deleteThread(threadInfo.id); + const result = await this.props.deleteThread({ threadID: threadInfo.id }); const invalidated = identifyInvalidatedThreads( result.updatesResult.newUpdates, ); @@ -272,7 +272,7 @@ const styles = useStyles(unboundStyles); const dispatchActionPromise = useDispatchActionPromise(); - const callDeleteThread = useServerCall(deleteThread); + const callDeleteThread = useDeleteThread(); const navContext = React.useContext(NavContext); invariant(navContext, 'NavContext should be set in DeleteThread'); diff --git a/native/chat/settings/thread-settings-description.react.js b/native/chat/settings/thread-settings-description.react.js --- a/native/chat/settings/thread-settings-description.react.js +++ b/native/chat/settings/thread-settings-description.react.js @@ -11,7 +11,7 @@ import { changeThreadSettingsActionTypes, - changeThreadSettings, + useChangeThreadSettings, } from 'lib/actions/thread-actions.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; import { threadHasPermission } from 'lib/shared/thread-utils.js'; @@ -24,7 +24,6 @@ } from 'lib/types/thread-types.js'; import { type DispatchActionPromise, - useServerCall, useDispatchActionPromise, } from 'lib/utils/action-utils.js'; @@ -307,7 +306,7 @@ const styles = useStyles(unboundStyles); const dispatchActionPromise = useDispatchActionPromise(); - const callChangeThreadSettings = useServerCall(changeThreadSettings); + const callChangeThreadSettings = useChangeThreadSettings(); return ( { dispatchActionPromise( diff --git a/web/modals/threads/settings/thread-settings-delete-tab.react.js b/web/modals/threads/settings/thread-settings-delete-tab.react.js --- a/web/modals/threads/settings/thread-settings-delete-tab.react.js +++ b/web/modals/threads/settings/thread-settings-delete-tab.react.js @@ -4,17 +4,14 @@ import { deleteThreadActionTypes, - deleteThread, + useDeleteThread, } from 'lib/actions/thread-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import SWMansionIcon from 'lib/components/SWMansionIcon.react.js'; import { containedThreadInfos } from 'lib/selectors/thread-selectors.js'; import { type SetState } from 'lib/types/hook-types.js'; import { type ThreadInfo } from 'lib/types/thread-types.js'; -import { - useDispatchActionPromise, - useServerCall, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import SubmitSection from './submit-section.react.js'; import ThreadDeleteConfirmationModal from './thread-settings-delete-confirmation-modal.react.js'; @@ -41,7 +38,7 @@ const modalContext = useModalContext(); const dispatchActionPromise = useDispatchActionPromise(); - const callDeleteThread = useServerCall(deleteThread); + const callDeleteThread = useDeleteThread(); const containedThreads = useSelector( state => containedThreadInfos(state)[threadInfo.id], ); @@ -58,7 +55,7 @@ const deleteThreadAction = React.useCallback(async () => { try { setErrorMessage(''); - const response = await callDeleteThread(threadInfo.id); + const response = await callDeleteThread({ threadID: threadInfo.id }); popThreadDeleteConfirmationModal(); modalContext.popModal(); return response; diff --git a/web/modals/threads/settings/thread-settings-general-tab.react.js b/web/modals/threads/settings/thread-settings-general-tab.react.js --- a/web/modals/threads/settings/thread-settings-general-tab.react.js +++ b/web/modals/threads/settings/thread-settings-general-tab.react.js @@ -5,16 +5,13 @@ import { changeThreadSettingsActionTypes, - changeThreadSettings, + useChangeThreadSettings, } from 'lib/actions/thread-actions.js'; import { threadHasPermission } from 'lib/shared/thread-utils.js'; import { type SetState } from 'lib/types/hook-types.js'; import { threadPermissions } from 'lib/types/thread-permission-types.js'; import { type ThreadInfo, type ThreadChanges } from 'lib/types/thread-types.js'; -import { - useDispatchActionPromise, - useServerCall, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import { firstLine } from 'lib/utils/string-utils.js'; import { chatNameMaxLength } from 'lib/utils/validation-utils.js'; @@ -48,7 +45,7 @@ } = props; const dispatchActionPromise = useDispatchActionPromise(); - const callChangeThreadSettings = useServerCall(changeThreadSettings); + const callChangeThreadSettings = useChangeThreadSettings(); const nameInputRef = React.useRef(); diff --git a/web/modals/threads/settings/thread-settings-privacy-tab.react.js b/web/modals/threads/settings/thread-settings-privacy-tab.react.js --- a/web/modals/threads/settings/thread-settings-privacy-tab.react.js +++ b/web/modals/threads/settings/thread-settings-privacy-tab.react.js @@ -3,7 +3,7 @@ import * as React from 'react'; import { - changeThreadSettings, + useChangeThreadSettings, changeThreadSettingsActionTypes, } from 'lib/actions/thread-actions.js'; import { useModalContext } from 'lib/components/modal-provider.react.js'; @@ -12,10 +12,7 @@ import { type SetState } from 'lib/types/hook-types.js'; import { threadTypes } from 'lib/types/thread-types-enum.js'; import { type ThreadInfo, type ThreadChanges } from 'lib/types/thread-types.js'; -import { - useDispatchActionPromise, - useServerCall, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import SubmitSection from './submit-section.react.js'; import css from './thread-settings-privacy-tab.css'; @@ -61,7 +58,7 @@ const modalContext = useModalContext(); const dispatchActionPromise = useDispatchActionPromise(); - const callChangeThreadSettings = useServerCall(changeThreadSettings); + const callChangeThreadSettings = useChangeThreadSettings(); const changeQueued: boolean = React.useMemo( () => Object.values(queuedChanges).some(v => v !== null && v !== undefined),