diff --git a/app/javascript/dashboard/helper/AudioAlerts/AudioNotificationStore.js b/app/javascript/dashboard/helper/AudioAlerts/AudioNotificationStore.js index 233516b99..30deca003 100644 --- a/app/javascript/dashboard/helper/AudioAlerts/AudioNotificationStore.js +++ b/app/javascript/dashboard/helper/AudioAlerts/AudioNotificationStore.js @@ -3,6 +3,7 @@ import { CONVERSATION_PERMISSIONS, } from 'dashboard/constants/permissions'; import { getUserPermissions } from 'dashboard/helper/permissionsHelper'; +import wootConstants from 'dashboard/constants/globals'; class AudioNotificationStore { constructor(store) { @@ -18,6 +19,15 @@ class AudioNotificationStore { return mineConversation.some(conv => conv.unread_count > 0); }; + isMessageFromPendingConversation = (message = {}) => { + const { conversation_id: conversationId } = message || {}; + if (!conversationId) return false; + + const activeConversation = + this.store.getters.getConversationById(conversationId); + return activeConversation?.status === wootConstants.STATUS_TYPE.PENDING; + }; + isMessageFromCurrentConversation = message => { return this.store.getters.getSelectedChat?.id === message.conversation_id; }; diff --git a/app/javascript/dashboard/helper/AudioAlerts/DashboardAudioNotificationHelper.js b/app/javascript/dashboard/helper/AudioAlerts/DashboardAudioNotificationHelper.js index ca823fc31..21cb0fc9f 100644 --- a/app/javascript/dashboard/helper/AudioAlerts/DashboardAudioNotificationHelper.js +++ b/app/javascript/dashboard/helper/AudioAlerts/DashboardAudioNotificationHelper.js @@ -172,6 +172,12 @@ export class DashboardAudioNotificationHelper { return; } + // If the conversation status is pending, then dismiss the alert + // This case is common for all audio event types + if (this.store.isMessageFromPendingConversation(message)) { + return; + } + // If the message is sent by the current user then dismiss the alert if (isMessageFromCurrentUser(message, this.currentUser.id)) { return; diff --git a/app/javascript/dashboard/helper/AudioAlerts/specs/AudioNotificationStore.spec.js b/app/javascript/dashboard/helper/AudioAlerts/specs/AudioNotificationStore.spec.js index 5e8971c2d..8efcfb15b 100644 --- a/app/javascript/dashboard/helper/AudioAlerts/specs/AudioNotificationStore.spec.js +++ b/app/javascript/dashboard/helper/AudioAlerts/specs/AudioNotificationStore.spec.js @@ -4,6 +4,8 @@ import { CONVERSATION_PERMISSIONS, } from 'dashboard/constants/permissions'; import { getUserPermissions } from 'dashboard/helper/permissionsHelper'; +import wootConstants from 'dashboard/constants/globals'; + vi.mock('dashboard/helper/permissionsHelper', () => ({ getUserPermissions: vi.fn(), })); @@ -18,6 +20,7 @@ describe('AudioNotificationStore', () => { getMineChats: vi.fn(), getSelectedChat: null, getCurrentAccountId: 1, + getConversationById: vi.fn(), }, }; audioNotificationStore = new AudioNotificationStore(store); @@ -59,6 +62,63 @@ describe('AudioNotificationStore', () => { }); }); + describe('isMessageFromPendingConversation', () => { + it('should return true when conversation status is pending', () => { + store.getters.getConversationById.mockReturnValue({ + id: 123, + status: wootConstants.STATUS_TYPE.PENDING, + }); + const message = { conversation_id: 123 }; + + expect( + audioNotificationStore.isMessageFromPendingConversation(message) + ).toBe(true); + expect(store.getters.getConversationById).toHaveBeenCalledWith(123); + }); + + it('should return false when conversation status is not pending', () => { + store.getters.getConversationById.mockReturnValue({ + id: 123, + status: wootConstants.STATUS_TYPE.OPEN, + }); + const message = { conversation_id: 123 }; + + expect( + audioNotificationStore.isMessageFromPendingConversation(message) + ).toBe(false); + expect(store.getters.getConversationById).toHaveBeenCalledWith(123); + }); + + it('should return false when conversation is not found', () => { + store.getters.getConversationById.mockReturnValue(null); + const message = { conversation_id: 123 }; + + expect( + audioNotificationStore.isMessageFromPendingConversation(message) + ).toBe(false); + expect(store.getters.getConversationById).toHaveBeenCalledWith(123); + }); + + it('should return false when message has no conversation_id', () => { + const message = {}; + + expect( + audioNotificationStore.isMessageFromPendingConversation(message) + ).toBe(false); + expect(store.getters.getConversationById).not.toHaveBeenCalled(); + }); + + it('should return false when message is null or undefined', () => { + expect( + audioNotificationStore.isMessageFromPendingConversation(null) + ).toBe(false); + expect( + audioNotificationStore.isMessageFromPendingConversation(undefined) + ).toBe(false); + expect(store.getters.getConversationById).not.toHaveBeenCalled(); + }); + }); + describe('isMessageFromCurrentConversation', () => { it('should return true when message is from selected chat', () => { store.getters.getSelectedChat = { id: 6179 };