chore: Disable audio alert for pending status conversation (#10777)
# Pull Request Template ## Description This PR disables audio alerts for conversations with a status of "pending." It applies to all notification event types, ensuring that audio will not play for conversations marked as "pending." Fixes https://linear.app/chatwoot/issue/CW-3951/audio-alerts-shouldnt-be-triggered-in-conversation-is-in-pending-state ## Type of change - [x] Breaking change (fix or feature that would cause existing functionality not to work as expected) ## How Has This Been Tested? Steps: 1. Create a conversation. 2. Then mark the conversation as pending. 3. Send message. 4. Make sure audio notification are enabled. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
|||||||
CONVERSATION_PERMISSIONS,
|
CONVERSATION_PERMISSIONS,
|
||||||
} from 'dashboard/constants/permissions';
|
} from 'dashboard/constants/permissions';
|
||||||
import { getUserPermissions } from 'dashboard/helper/permissionsHelper';
|
import { getUserPermissions } from 'dashboard/helper/permissionsHelper';
|
||||||
|
import wootConstants from 'dashboard/constants/globals';
|
||||||
|
|
||||||
class AudioNotificationStore {
|
class AudioNotificationStore {
|
||||||
constructor(store) {
|
constructor(store) {
|
||||||
@@ -18,6 +19,15 @@ class AudioNotificationStore {
|
|||||||
return mineConversation.some(conv => conv.unread_count > 0);
|
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 => {
|
isMessageFromCurrentConversation = message => {
|
||||||
return this.store.getters.getSelectedChat?.id === message.conversation_id;
|
return this.store.getters.getSelectedChat?.id === message.conversation_id;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -172,6 +172,12 @@ export class DashboardAudioNotificationHelper {
|
|||||||
return;
|
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 the message is sent by the current user then dismiss the alert
|
||||||
if (isMessageFromCurrentUser(message, this.currentUser.id)) {
|
if (isMessageFromCurrentUser(message, this.currentUser.id)) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import {
|
|||||||
CONVERSATION_PERMISSIONS,
|
CONVERSATION_PERMISSIONS,
|
||||||
} from 'dashboard/constants/permissions';
|
} from 'dashboard/constants/permissions';
|
||||||
import { getUserPermissions } from 'dashboard/helper/permissionsHelper';
|
import { getUserPermissions } from 'dashboard/helper/permissionsHelper';
|
||||||
|
import wootConstants from 'dashboard/constants/globals';
|
||||||
|
|
||||||
vi.mock('dashboard/helper/permissionsHelper', () => ({
|
vi.mock('dashboard/helper/permissionsHelper', () => ({
|
||||||
getUserPermissions: vi.fn(),
|
getUserPermissions: vi.fn(),
|
||||||
}));
|
}));
|
||||||
@@ -18,6 +20,7 @@ describe('AudioNotificationStore', () => {
|
|||||||
getMineChats: vi.fn(),
|
getMineChats: vi.fn(),
|
||||||
getSelectedChat: null,
|
getSelectedChat: null,
|
||||||
getCurrentAccountId: 1,
|
getCurrentAccountId: 1,
|
||||||
|
getConversationById: vi.fn(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
audioNotificationStore = new AudioNotificationStore(store);
|
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', () => {
|
describe('isMessageFromCurrentConversation', () => {
|
||||||
it('should return true when message is from selected chat', () => {
|
it('should return true when message is from selected chat', () => {
|
||||||
store.getters.getSelectedChat = { id: 6179 };
|
store.getters.getSelectedChat = { id: 6179 };
|
||||||
|
|||||||
Reference in New Issue
Block a user