diff --git a/app/javascript/shared/helpers/AudioNotificationHelper.js b/app/javascript/shared/helpers/AudioNotificationHelper.js index 672816f90..d4fbc9e2c 100644 --- a/app/javascript/shared/helpers/AudioNotificationHelper.js +++ b/app/javascript/shared/helpers/AudioNotificationHelper.js @@ -3,7 +3,7 @@ import { IFrameHelper } from 'widget/helpers/utils'; import { showBadgeOnFavicon } from './faviconHelper'; -export const initOnEvents = ['click', 'touchstart', 'keypress']; +export const initOnEvents = ['click', 'touchstart', 'keypress', 'keydown']; export const getAlertAudio = async (baseUrl = '') => { const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); const playsound = audioBuffer => { @@ -53,6 +53,10 @@ export const shouldPlayAudio = ( message_type: messageType, private: isPrivate, } = message; + if (!isDocHidden && messageType === MESSAGE_TYPE.INCOMING) { + showBadgeOnFavicon(); + return false; + } const isFromCurrentUser = userId === senderId; const playAudio = diff --git a/app/javascript/shared/helpers/specs/AudioNotificationHelper.spec.js b/app/javascript/shared/helpers/specs/AudioNotificationHelper.spec.js index 7bdb6b059..7dc935400 100644 --- a/app/javascript/shared/helpers/specs/AudioNotificationHelper.spec.js +++ b/app/javascript/shared/helpers/specs/AudioNotificationHelper.spec.js @@ -17,7 +17,7 @@ describe('shouldPlayAudio', () => { message_type: 0, private: false, }; - const [conversationId, userId, isDocHiddden] = [1, 2, false]; + const [conversationId, userId, isDocHiddden] = [1, 2, true]; const result = shouldPlayAudio( message, conversationId,