From f6e099c696cc354fa3a94de40f7884afda505e46 Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Thu, 9 Apr 2026 02:25:07 +0530 Subject: [PATCH] Fix notification sound to only alert for new or hidden-tab conversations --- frontend/apps/main/src/websocket.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/frontend/apps/main/src/websocket.js b/frontend/apps/main/src/websocket.js index 91536124..48fbebc5 100644 --- a/frontend/apps/main/src/websocket.js +++ b/frontend/apps/main/src/websocket.js @@ -66,22 +66,19 @@ export class WebSocketClient { const handlers = { // On new message, refresh list and fetch message if it's in current conversation. [WS_EVENT.NEW_MESSAGE]: () => { - this.convStore.refreshConversationList() - this.convStore.updateConversationMessage(data.data) - - // Play notification sound for incoming contact messages that appear - // in the agent's conversation list and are not currently being viewed. const isFromContact = data.data.sender_type === 'contact' - const isViewingConversation = this.convStore.conversation.data?.uuid === data.data.conversation_uuid - if (isFromContact && (!isViewingConversation || document.hidden)) { - if (this.convStore.isConversationInList(data.data.conversation_uuid)) { + if (isFromContact) { + if (document.hidden) { + // Tab is not visible - always play sound. playNotificationSound() - } else { - // New conversation not in list yet (debounced refresh pending). - // Store UUID so sound plays when refresh completes and it appears. + } else if (!this.convStore.isConversationInList(data.data.conversation_uuid)) { + // Tab is visible - only play for new conversations via deferred check. this.convStore.addPendingNotification(data.data.conversation_uuid) } } + + this.convStore.refreshConversationList() + this.convStore.updateConversationMessage(data.data) }, // Property updates for conversation and message. [WS_EVENT.MESSAGE_UPDATE]: () => this.convStore.mergeMessageUpdate(data.data),