Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Continuous sound notifications for new LiveChat rooms #10151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@
"Conversation_closed": "Conversation closed: __comment__.",
"Conversation_finished_message": "Conversation Finished Message",
"Convert_Ascii_Emojis": "Convert ASCII to Emoji",
"Continuous_sound_notifications_for_new_livechat_room": "Continuous sound notifications for new livechat room",
"Copied": "Copied",
"Copy": "Copy",
"Copy_to_clipboard": "Copy to clipboard",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/pt.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@
"Conversation_closed": "Chat encerrado: __comment__.",
"Conversation_finished_message": "Mensagem ao encerrar chat",
"Convert_Ascii_Emojis": "Converter ASCII para Emoji",
"Continuous_sound_notifications_for_new_livechat_room": "Notificações contínuas de som para nova sala de livechat",
"Copied": "Copiado",
"Copy": "Cópia",
"Copy_to_clipboard": "Copiar para área de transferência",
Expand Down
44 changes: 44 additions & 0 deletions packages/rocketchat-livechat/client/startup/notifyUnreadRooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
let audio = null;

const stop = audio => {
if (!audio) {
return;
}
audio.loop = false;
return audio.pause && audio.pause();
};
const play = audio => {
if (!audio) {
return;
}
audio.loop = true;
return audio.play && audio.play();
};

Meteor.startup(function() {
Tracker.autorun(function() {

if (!RocketChat.settings.get('Livechat_continuous_sound_notification_new_livechat_room')) {
stop(audio);
return;
}

const subs = RocketChat.models.Subscriptions.find({ t: 'l', ls : { $exists: 0 }, open: true }).count();
if (subs === 0) {
stop(audio);
return;
}

const user = RocketChat.models.Users.findOne(Meteor.userId(), {
fields: {
'settings.preferences.newRoomNotification': 1
}
});

const newRoomNotification = RocketChat.getUserPreference(user, 'newRoomNotification');

[audio] = $(`#${ newRoomNotification }`);
play(audio);

});
});
7 changes: 7 additions & 0 deletions packages/rocketchat-livechat/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ Meteor.startup(function() {
i18nLabel: 'Office_hours_enabled'
});

RocketChat.settings.add('Livechat_continuous_sound_notification_new_livechat_room', false, {
type: 'boolean',
group: 'Livechat',
public: true,
i18nLabel: 'Continuous_sound_notifications_for_new_livechat_room'
});

RocketChat.settings.add('Livechat_videocall_enabled', false, {
type: 'boolean',
group: 'Livechat',
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-livechat/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Package.onUse(function(api) {

api.addFiles('client/methods/changeLivechatStatus.js', 'client');

//client startup
api.addFiles('client/startup/notifyUnreadRooms.js', 'client');

// client views
api.addFiles('client/views/app/livechatAppearance.html', 'client');
api.addFiles('client/views/app/livechatAppearance.js', 'client');
Expand Down
4 changes: 3 additions & 1 deletion packages/rocketchat-ui/client/lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ const KonchatNotification = {
// $('.link-room-' + rid).addClass('new-room-highlight')

removeRoomNotification(rid) {
Tracker.nonreactive(() => Session.set('newRoomSound', []));
let newRoomSound = Session.get('newRoomSound');
newRoomSound = _.without(newRoomSound, rid);
Tracker.nonreactive(() => Session.set('newRoomSound', newRoomSound));

return $(`.link-room-${ rid }`).removeClass('new-room-highlight');
}
Expand Down