Voice Messages: Fix sending (#2326)

This commit is contained in:
Alexander Zinchuk 2023-01-22 19:16:27 +01:00
parent 6f24d71bcd
commit 00e7381a03
2 changed files with 36 additions and 12 deletions

View File

@ -665,15 +665,25 @@ const Composer: FC<OwnProps & StateProps> = ({
return true; return true;
}, [isAdmin, lang, showDialog, slowMode]); }, [isAdmin, lang, showDialog, slowMode]);
const handleSendAttachments = useCallback(( const sendAttachments = useCallback(({
sendCompressed: boolean, sendGrouped: boolean, isSilent?: boolean, scheduledAt?: number, attachments: attachmentsToSend,
) => { sendCompressed,
sendGrouped,
isSilent,
scheduledAt,
} : {
attachments: ApiAttachment[];
sendCompressed?: boolean;
sendGrouped?: boolean;
isSilent?: boolean;
scheduledAt?: number;
}) => {
if (connectionState !== 'connectionStateReady') { if (connectionState !== 'connectionStateReady') {
return; return;
} }
const { text, entities } = parseMessageInput(htmlRef.current!); const { text, entities } = parseMessageInput(htmlRef.current!);
if (!text && !attachments.length) { if (!text && !attachmentsToSend.length) {
return; return;
} }
if (!validateTextLength(text, true)) return; if (!validateTextLength(text, true)) return;
@ -685,7 +695,7 @@ const Composer: FC<OwnProps & StateProps> = ({
scheduledAt, scheduledAt,
isSilent, isSilent,
shouldUpdateStickerSetsOrder: true, shouldUpdateStickerSetsOrder: true,
attachments: prepareAttachmentsToSend(attachments, sendCompressed), attachments: prepareAttachmentsToSend(attachmentsToSend, sendCompressed),
shouldGroupMessages: sendGrouped, shouldGroupMessages: sendGrouped,
}); });
@ -697,10 +707,22 @@ const Composer: FC<OwnProps & StateProps> = ({
requestAnimationFrame(() => { requestAnimationFrame(() => {
resetComposer(); resetComposer();
}); });
}, [ }, [chatId, checkSlowMode, clearDraft, htmlRef, resetComposer, sendMessage, validateTextLength, connectionState]);
attachments, chatId, checkSlowMode, clearDraft, htmlRef, resetComposer, sendMessage, validateTextLength,
connectionState, const handleSendAttachments = useCallback((
]); sendCompressed: boolean,
sendGrouped: boolean,
isSilent?: boolean,
scheduledAt?: number,
) => {
sendAttachments({
attachments,
sendCompressed,
sendGrouped,
isSilent,
scheduledAt,
});
}, [attachments, sendAttachments]);
const handleSend = useCallback(async (isSilent = false, scheduledAt?: number) => { const handleSend = useCallback(async (isSilent = false, scheduledAt?: number) => {
if (connectionState !== 'connectionStateReady') { if (connectionState !== 'connectionStateReady') {
@ -724,7 +746,9 @@ const Composer: FC<OwnProps & StateProps> = ({
const { text, entities } = parseMessageInput(htmlRef.current!); const { text, entities } = parseMessageInput(htmlRef.current!);
if (currentAttachments.length) { if (currentAttachments.length) {
handleSendAttachments(false, false); sendAttachments({
attachments: currentAttachments,
});
return; return;
} }
@ -769,7 +793,7 @@ const Composer: FC<OwnProps & StateProps> = ({
}); });
}, [ }, [
connectionState, attachments, activeVoiceRecording, htmlRef, isForwarding, validateTextLength, clearDraft, connectionState, attachments, activeVoiceRecording, htmlRef, isForwarding, validateTextLength, clearDraft,
chatId, stopRecordingVoice, handleSendAttachments, checkSlowMode, sendMessage, forwardMessages, resetComposer, chatId, stopRecordingVoice, sendAttachments, checkSlowMode, sendMessage, forwardMessages, resetComposer,
]); ]);
const handleClickBotMenu = useCallback(() => { const handleClickBotMenu = useCallback(() => {

View File

@ -77,6 +77,6 @@ export default async function buildAttachment(
export function prepareAttachmentsToSend(attachments: ApiAttachment[], shouldSendCompressed?: boolean) { export function prepareAttachmentsToSend(attachments: ApiAttachment[], shouldSendCompressed?: boolean) {
return !shouldSendCompressed return !shouldSendCompressed
? attachments.map((attachment) => ({ ...attachment, shouldSendAsFile: true })) ? attachments.map((attachment) => ({ ...attachment, shouldSendAsFile: !attachment.voice ? true : undefined }))
: attachments; : attachments;
} }