diff --git a/lib/actions/message-report-actions.js b/lib/actions/message-report-actions.js index d8e7ff87e..fa3e0e6f2 100644 --- a/lib/actions/message-report-actions.js +++ b/lib/actions/message-report-actions.js @@ -1,24 +1,41 @@ // @flow import type { MessageReportCreationRequest, MessageReportCreationResult, } from '../types/message-report-types.js'; -import type { CallServerEndpoint } from '../utils/call-server-endpoint.js'; +import { extractKeyserverIDFromID } from '../utils/action-utils.js'; +import type { CallKeyserverEndpoint } from '../utils/keyserver-call.js'; +import { useKeyserverCall } from '../utils/keyserver-call.js'; const sendMessageReportActionTypes = Object.freeze({ started: 'SEND_MESSAGE_REPORT_STARTED', success: 'SEND_MESSAGE_REPORT_SUCCESS', failed: 'SEND_MESSAGE_REPORT_FAILED', }); const sendMessageReport = ( - callServerEndpoint: CallServerEndpoint, + callKeyserverEndpoint: CallKeyserverEndpoint, ): (( - request: MessageReportCreationRequest, + input: MessageReportCreationRequest, ) => Promise) => - async request => { - return await callServerEndpoint('create_message_report', request); + async input => { + const keyserverID = extractKeyserverIDFromID(input.messageID); + const requests = { [keyserverID]: input }; + + const responses = await callKeyserverEndpoint( + 'create_message_report', + requests, + ); + const response = responses[keyserverID]; + + return { messageInfo: response.messageInfo }; }; -export { sendMessageReportActionTypes, sendMessageReport }; +function useSendMessageReport(): ( + input: MessageReportCreationRequest, +) => Promise { + return useKeyserverCall(sendMessageReport); +} + +export { sendMessageReportActionTypes, useSendMessageReport }; diff --git a/native/chat/message-report-utils.js b/native/chat/message-report-utils.js index 83521621e..d7cd59a9e 100644 --- a/native/chat/message-report-utils.js +++ b/native/chat/message-report-utils.js @@ -1,61 +1,58 @@ // @flow import * as React from 'react'; import { - sendMessageReport, + useSendMessageReport, sendMessageReportActionTypes, } from 'lib/actions/message-report-actions.js'; -import { - useServerCall, - useDispatchActionPromise, -} from 'lib/utils/action-utils.js'; +import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; import { displayActionResultModal } from '../navigation/action-result-modal.js'; import type { TooltipRoute } from '../tooltip/tooltip.react.js'; import Alert from '../utils/alert.js'; const confirmReport = () => displayActionResultModal('reported to admin'); function useOnPressReport( route: | TooltipRoute<'TextMessageTooltipModal'> | TooltipRoute<'MultimediaMessageTooltipModal'>, ): () => mixed { const messageID = route.params.item.messageInfo.id; const dispatchActionPromise = useDispatchActionPromise(); - const callSendMessageReport = useServerCall(sendMessageReport); + const callSendMessageReport = useSendMessageReport(); return React.useCallback(() => { if (!messageID) { Alert.alert( 'Couldn’t send the report', 'Uhh... try again?', [{ text: 'OK' }], { cancelable: false, }, ); return; } const messageReportPromise = (async () => { try { const result = await callSendMessageReport({ messageID }); confirmReport(); return result; } catch (e) { Alert.alert( 'Couldn’t send the report', 'Uhh... try again?', [{ text: 'OK' }], { cancelable: false, }, ); throw e; } })(); dispatchActionPromise(sendMessageReportActionTypes, messageReportPromise); }, [callSendMessageReport, messageID, dispatchActionPromise]); } export { useOnPressReport };