Composer: Fix recording not stopped when closing chat on mobile

This commit is contained in:
Alexander Zinchuk 2021-08-25 16:29:24 +03:00
parent 6cc4a94407
commit 195a38b88d

View File

@ -424,16 +424,15 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
}
}, [closeStickerTooltip, closeCalendar, closeMentionTooltip, closeEmojiTooltip, closeSymbolMenu]);
// Handle chat change
const prevChatId = usePrevious(chatId);
// Handle chat change (ref is used to avoid redundant effect calls)
const stopRecordingVoiceRef = useRef<typeof stopRecordingVoice>();
stopRecordingVoiceRef.current = stopRecordingVoice;
useEffect(() => {
if (!prevChatId || chatId === prevChatId) {
return;
}
stopRecordingVoice();
resetComposer();
}, [chatId, prevChatId, resetComposer, stopRecordingVoice]);
return () => {
stopRecordingVoiceRef.current!();
resetComposer();
};
}, [chatId, resetComposer, stopRecordingVoiceRef]);
const handleEditComplete = useEditing(htmlRef, setHtml, editingMessage, resetComposer, openDeleteModal, editMessage);
useDraft(draft, chatId, threadId, html, htmlRef, setHtml, editingMessage, saveDraft, clearDraft);