From 3c3e0bb3d8b8e28c89c70d64afc7169ba5d0f51e Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Wed, 5 May 2021 18:33:55 -0300 Subject: [PATCH 1/4] notify with sound queue chat --- app/ui/client/lib/notification.js | 40 ++++++++++++------- .../notifications/konchatNotifications.ts | 4 ++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/ui/client/lib/notification.js b/app/ui/client/lib/notification.js index ee8b8918d900..1004360da5d4 100644 --- a/app/ui/client/lib/notification.js +++ b/app/ui/client/lib/notification.js @@ -101,27 +101,39 @@ export const KonchatNotification = { }, newMessage(rid) { + const userId = Meteor.userId(); + const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); + + const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } }); + + if (sub && sub.audioNotificationValue !== 'none') { + if (sub && sub.audioNotificationValue && sub.audioNotificationValue !== '0') { + this.emmitSound(sub.audioNotificationValue); + } else if (newMessageNotification !== 'none') { + this.emmitSound(newMessageNotification); + } + } + }, + + emmitSound(sound) { if (!Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) { const userId = Meteor.userId(); - const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); + // const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); const audioVolume = getUserPreference(userId, 'notificationsSoundVolume'); - const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } }); - - if (sub && sub.audioNotificationValue !== 'none') { - if (sub && sub.audioNotificationValue && sub.audioNotificationValue !== '0') { - CustomSounds.play(sub.audioNotificationValue, { - volume: Number((audioVolume / 100).toPrecision(2)), - }); - } else if (newMessageNotification !== 'none') { - CustomSounds.play(newMessageNotification, { - volume: Number((audioVolume / 100).toPrecision(2)), - }); - } - } + CustomSounds.play(sound, { + volume: Number((audioVolume / 100).toPrecision(2)), + }); } }, + newInquiry() { + const userId = Meteor.userId(); + const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); + + this.emmitSound(newMessageNotification); + }, + newRoom(rid/* , withSound = true*/) { Tracker.nonreactive(function() { let newRoomSound = Session.get('newRoomSound'); diff --git a/client/startup/notifications/konchatNotifications.ts b/client/startup/notifications/konchatNotifications.ts index 3467a73bcd8e..1c70d52c50b2 100644 --- a/client/startup/notifications/konchatNotifications.ts +++ b/client/startup/notifications/konchatNotifications.ts @@ -98,6 +98,10 @@ Meteor.startup(() => { 'muteFocusedConversations', ); + if (notification.payload.type === 'l' /* && INQUIRY_TEST */) { + return KonchatNotification.newInquiry(); + } + if (Layout.isEmbedded()) { if (!hasFocus && messageIsInOpenedRoom) { // Play a notification sound From ed89844340fe597ade9eb006ae4fd00d7743edb7 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Wed, 12 May 2021 16:01:45 -0300 Subject: [PATCH 2/4] fix typo and remove comments --- app/ui/client/lib/notification.js | 12 +++++++----- client/startup/notifications/konchatNotifications.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/ui/client/lib/notification.js b/app/ui/client/lib/notification.js index 1004360da5d4..5556d3256024 100644 --- a/app/ui/client/lib/notification.js +++ b/app/ui/client/lib/notification.js @@ -108,17 +108,16 @@ export const KonchatNotification = { if (sub && sub.audioNotificationValue !== 'none') { if (sub && sub.audioNotificationValue && sub.audioNotificationValue !== '0') { - this.emmitSound(sub.audioNotificationValue); + this.emitSound(sub.audioNotificationValue); } else if (newMessageNotification !== 'none') { - this.emmitSound(newMessageNotification); + this.emitSound(newMessageNotification); } } }, - emmitSound(sound) { + emitSound(sound) { if (!Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) { const userId = Meteor.userId(); - // const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); const audioVolume = getUserPreference(userId, 'notificationsSoundVolume'); CustomSounds.play(sound, { @@ -130,8 +129,11 @@ export const KonchatNotification = { newInquiry() { const userId = Meteor.userId(); const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); + const audioNotificationValue = getUserPreference(userId, 'audioNotifications'); - this.emmitSound(newMessageNotification); + if (audioNotificationValue === 'all') { + this.emitSound(newMessageNotification); + } }, newRoom(rid/* , withSound = true*/) { diff --git a/client/startup/notifications/konchatNotifications.ts b/client/startup/notifications/konchatNotifications.ts index 1c70d52c50b2..57f0bab60259 100644 --- a/client/startup/notifications/konchatNotifications.ts +++ b/client/startup/notifications/konchatNotifications.ts @@ -98,7 +98,7 @@ Meteor.startup(() => { 'muteFocusedConversations', ); - if (notification.payload.type === 'l' /* && INQUIRY_TEST */) { + if (notification.payload.type === 'l') { return KonchatNotification.newInquiry(); } From 0be75a9a97c859585659851345bba4a66653ab45 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Fri, 14 May 2021 15:24:23 -0300 Subject: [PATCH 3/4] use added event --- .../client/lib/stream/queueManager.js | 18 +++++++++ app/ui/client/lib/notification.js | 40 ++++++------------- .../notifications/konchatNotifications.ts | 4 -- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/livechat/client/lib/stream/queueManager.js b/app/livechat/client/lib/stream/queueManager.js index 9d9223db22e3..7c6beea57535 100644 --- a/app/livechat/client/lib/stream/queueManager.js +++ b/app/livechat/client/lib/stream/queueManager.js @@ -1,14 +1,32 @@ +import { Meteor } from 'meteor/meteor'; + import { APIClient } from '../../../../utils/client'; import { LivechatInquiry } from '../../collections/LivechatInquiry'; import { inquiryDataStream } from './inquiry'; import { call } from '../../../../ui-utils/client'; +import { getUserPreference } from '../../../../utils'; +import { CustomSounds } from '../../../../custom-sounds/client/lib/CustomSounds'; const departments = new Set(); +const newInquirySound = () => { + const userId = Meteor.userId(); + const audioVolume = getUserPreference(userId, 'notificationsSoundVolume'); + const newRoomNotification = getUserPreference(userId, 'newRoomNotification'); + const audioNotificationValue = getUserPreference(userId, 'audioNotifications'); + + if (audioNotificationValue === 'all') { + CustomSounds.play(newRoomNotification, { + volume: Number((audioVolume / 100).toPrecision(2)), + }); + } +}; + const events = { added: (inquiry) => { delete inquiry.type; departments.has(inquiry.department) && LivechatInquiry.insert({ ...inquiry, alert: true, _updatedAt: new Date(inquiry._updatedAt) }); + newInquirySound(); }, changed: (inquiry) => { if (inquiry.status !== 'queued' || (inquiry.department && !departments.has(inquiry.department))) { diff --git a/app/ui/client/lib/notification.js b/app/ui/client/lib/notification.js index 5556d3256024..ee8b8918d900 100644 --- a/app/ui/client/lib/notification.js +++ b/app/ui/client/lib/notification.js @@ -101,38 +101,24 @@ export const KonchatNotification = { }, newMessage(rid) { - const userId = Meteor.userId(); - const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); - - const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } }); - - if (sub && sub.audioNotificationValue !== 'none') { - if (sub && sub.audioNotificationValue && sub.audioNotificationValue !== '0') { - this.emitSound(sub.audioNotificationValue); - } else if (newMessageNotification !== 'none') { - this.emitSound(newMessageNotification); - } - } - }, - - emitSound(sound) { if (!Session.equals(`user_${ Meteor.user().username }_status`, 'busy')) { const userId = Meteor.userId(); + const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); const audioVolume = getUserPreference(userId, 'notificationsSoundVolume'); - CustomSounds.play(sound, { - volume: Number((audioVolume / 100).toPrecision(2)), - }); - } - }, - - newInquiry() { - const userId = Meteor.userId(); - const newMessageNotification = getUserPreference(userId, 'newMessageNotification'); - const audioNotificationValue = getUserPreference(userId, 'audioNotifications'); + const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotificationValue: 1 } }); - if (audioNotificationValue === 'all') { - this.emitSound(newMessageNotification); + if (sub && sub.audioNotificationValue !== 'none') { + if (sub && sub.audioNotificationValue && sub.audioNotificationValue !== '0') { + CustomSounds.play(sub.audioNotificationValue, { + volume: Number((audioVolume / 100).toPrecision(2)), + }); + } else if (newMessageNotification !== 'none') { + CustomSounds.play(newMessageNotification, { + volume: Number((audioVolume / 100).toPrecision(2)), + }); + } + } } }, diff --git a/client/startup/notifications/konchatNotifications.ts b/client/startup/notifications/konchatNotifications.ts index 57f0bab60259..3467a73bcd8e 100644 --- a/client/startup/notifications/konchatNotifications.ts +++ b/client/startup/notifications/konchatNotifications.ts @@ -98,10 +98,6 @@ Meteor.startup(() => { 'muteFocusedConversations', ); - if (notification.payload.type === 'l') { - return KonchatNotification.newInquiry(); - } - if (Layout.isEmbedded()) { if (!hasFocus && messageIsInOpenedRoom) { // Play a notification sound From 5827c33596bf4a4f98ec265cb575ec0d92a25e0e Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Sun, 16 May 2021 22:52:07 -0300 Subject: [PATCH 4/4] Change audio check Co-authored-by: Renato Becker --- app/livechat/client/lib/stream/queueManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/livechat/client/lib/stream/queueManager.js b/app/livechat/client/lib/stream/queueManager.js index 7c6beea57535..69b91393feb2 100644 --- a/app/livechat/client/lib/stream/queueManager.js +++ b/app/livechat/client/lib/stream/queueManager.js @@ -15,7 +15,7 @@ const newInquirySound = () => { const newRoomNotification = getUserPreference(userId, 'newRoomNotification'); const audioNotificationValue = getUserPreference(userId, 'audioNotifications'); - if (audioNotificationValue === 'all') { + if (audioNotificationValue !== 'none') { CustomSounds.play(newRoomNotification, { volume: Number((audioVolume / 100).toPrecision(2)), });