From d50f536f79d47b668d609341ee10fdf386cda81d Mon Sep 17 00:00:00 2001 From: Gabriel Jablonski Date: Fri, 8 Aug 2025 15:25:52 -0300 Subject: [PATCH] fix: recorded audio race conditions (#91) * fix: audio recorder race condition * fix: send audio race condition * fix: streamline audio attachment handling by consolidating removal logic --- .../components/widgets/conversation/ReplyBox.vue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue index 2e595f53a..68710118e 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ReplyBox.vue @@ -117,7 +117,6 @@ export default { showVariablesMenu: false, newConversationModalActive: false, showArticleSearchPopover: false, - hasRecordedAudio: false, }; }, computed: { @@ -294,6 +293,9 @@ export default { hasAttachments() { return this.attachedFiles.length; }, + hasRecordedAudio() { + return this.attachedFiles.some(file => file.isRecordedAudio); + }, isRichEditorEnabled() { return this.isAWebWidgetInbox || this.isAnEmailChannel; }, @@ -898,7 +900,9 @@ export default { }, onFinishRecorder(file) { this.recordingAudioState = 'stopped'; - this.hasRecordedAudio = true; + + this.removeRecordedAudio(); + // Added a new key isRecordedAudio to the file to find it's and recorded audio // Because to filter and show only non recorded audio and other attachments const autoRecordedFile = { @@ -922,6 +926,10 @@ export default { }); }, attachFile({ blob, file }) { + if (file?.isRecordedAudio) { + this.removeRecordedAudio(); + } + const reader = new FileReader(); reader.readAsDataURL(file.file); reader.onloadend = () => { @@ -1094,8 +1102,10 @@ export default { this.recordingAudioDurationText = '00:00'; this.isRecordingAudio = false; this.recordingAudioState = ''; - this.hasRecordedAudio = false; // Only clear the recorded audio when we click toggle button. + this.removeRecordedAudio(); + }, + removeRecordedAudio() { this.attachedFiles = this.attachedFiles.filter( file => !file?.isRecordedAudio );