mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 20:18:08 +00:00
# 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
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
import {
|
|
ROLES,
|
|
CONVERSATION_PERMISSIONS,
|
|
} from 'dashboard/constants/permissions';
|
|
import { getUserPermissions } from 'dashboard/helper/permissionsHelper';
|
|
import wootConstants from 'dashboard/constants/globals';
|
|
|
|
class AudioNotificationStore {
|
|
constructor(store) {
|
|
this.store = store;
|
|
}
|
|
|
|
hasUnreadConversation = () => {
|
|
const mineConversation = this.store.getters.getMineChats({
|
|
assigneeType: 'me',
|
|
status: 'open',
|
|
});
|
|
|
|
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;
|
|
};
|
|
|
|
hasConversationPermission = user => {
|
|
const currentAccountId = this.store.getters.getCurrentAccountId;
|
|
// Get the user permissions for the current account
|
|
const userPermissions = getUserPermissions(user, currentAccountId);
|
|
// Check if the user has the required permissions
|
|
const hasRequiredPermission = [...ROLES, ...CONVERSATION_PERMISSIONS].some(
|
|
permission => userPermissions.includes(permission)
|
|
);
|
|
return hasRequiredPermission;
|
|
};
|
|
}
|
|
|
|
export default AudioNotificationStore;
|