2023-03-02 20:55:40 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo, useCallback } from 'react';
|
2023-03-02 20:55:40 +00:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { CompositionRecording } from '../../components/CompositionRecording';
|
|
|
|
import { useAudioRecorderActions } from '../ducks/audioRecorder';
|
|
|
|
import { useComposerActions } from '../ducks/composer';
|
2024-01-29 20:09:54 +00:00
|
|
|
import { useToastActions } from '../ducks/toast';
|
2023-03-02 20:55:40 +00:00
|
|
|
import { getSelectedConversationId } from '../selectors/conversations';
|
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
|
|
|
|
export type SmartCompositionRecordingProps = {
|
|
|
|
onBeforeSend: () => void;
|
|
|
|
};
|
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartCompositionRecording = memo(
|
|
|
|
function SmartCompositionRecording({
|
2023-03-02 20:55:40 +00:00
|
|
|
onBeforeSend,
|
2024-03-13 20:44:13 +00:00
|
|
|
}: SmartCompositionRecordingProps) {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const selectedConversationId = useSelector(getSelectedConversationId);
|
2024-03-19 17:12:32 +00:00
|
|
|
const { errorRecording, cancelRecording, completeRecording } =
|
|
|
|
useAudioRecorderActions();
|
2023-03-02 20:55:40 +00:00
|
|
|
|
2024-06-18 19:53:14 +00:00
|
|
|
const { sendMultiMediaMessage, addAttachment, saveDraftRecordingIfNeeded } =
|
|
|
|
useComposerActions();
|
2024-03-13 20:44:13 +00:00
|
|
|
const { hideToast, showToast } = useToastActions();
|
|
|
|
|
|
|
|
const handleCancel = useCallback(() => {
|
|
|
|
cancelRecording();
|
|
|
|
}, [cancelRecording]);
|
|
|
|
|
|
|
|
const handleSend = useCallback(() => {
|
|
|
|
if (selectedConversationId) {
|
|
|
|
completeRecording(selectedConversationId, voiceNoteAttachment => {
|
|
|
|
onBeforeSend();
|
|
|
|
sendMultiMediaMessage(selectedConversationId, {
|
|
|
|
voiceNoteAttachment,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
selectedConversationId,
|
|
|
|
completeRecording,
|
|
|
|
onBeforeSend,
|
|
|
|
sendMultiMediaMessage,
|
|
|
|
]);
|
2023-03-02 20:55:40 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
if (!selectedConversationId) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CompositionRecording
|
|
|
|
i18n={i18n}
|
|
|
|
onCancel={handleCancel}
|
|
|
|
onSend={handleSend}
|
2024-03-19 17:12:32 +00:00
|
|
|
errorRecording={errorRecording}
|
|
|
|
addAttachment={addAttachment}
|
|
|
|
completeRecording={completeRecording}
|
2024-06-18 19:53:14 +00:00
|
|
|
saveDraftRecordingIfNeeded={saveDraftRecordingIfNeeded}
|
2024-03-13 20:44:13 +00:00
|
|
|
showToast={showToast}
|
|
|
|
hideToast={hideToast}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|