Skip to content

Commit

Permalink
Merge pull request #7517 from lindoelio/develop
Browse files Browse the repository at this point in the history
[NEW] Configurable Volume for Notifications #6087
  • Loading branch information
rodrigok authored Jul 27, 2017
2 parents d6d4d6a + 48cad72 commit 82b7845
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
.env
.externalToolBuilders
.idea
.vscode
.loadpath
.map
.metadata
Expand Down
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ rocketchat:slashcommands-mute
rocketchat:slashcommands-open
rocketchat:slashcommands-topic
rocketchat:slashcommands-unarchive
rocketchat:slider
rocketchat:smarsh-connector
rocketchat:spotify
rocketchat:statistics
Expand Down
3 changes: 2 additions & 1 deletion .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ [email protected]
[email protected]
[email protected]
[email protected]
ostrio:[email protected].1
ostrio:[email protected].2
pauli:[email protected]
pauli:[email protected]
percolate:[email protected]
Expand Down Expand Up @@ -202,6 +202,7 @@ rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
rocketchat:[email protected]
Expand Down
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 @@ -1105,6 +1105,7 @@
"Notification_Duration": "Notification Duration",
"Notifications": "Notifications",
"Notifications_Muted_Description": "If you choose to mute everything, you won't see the room highlight in the list when there are new messages, except for mentions. Muting notifications will override notifications settings.",
"Notifications_Sound_Volume": "Notifications sound volume",
"Notify_all_in_this_room": "Notify all in this room",
"Notify_active_in_this_room": "Notify active users in this room",
"Num_Agents": "# Agents",
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-i18n/i18n/es.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@
"Nothing_found": "No se encontró nada",
"Notification_Duration": "Duración de la notificación",
"Notifications": "Notificaciones",
"Notifications_Sound_Volume": "Volumen del sonido de las notificaciones",
"Notify_all_in_this_room": "Notificar a todos en este canal",
"Num_Agents": "# de Agentes",
"Number_of_messages": "Número de mensajes",
Expand Down Expand Up @@ -1362,4 +1363,4 @@
"Your_mail_was_sent_to_s": "Su correo electrónico fue enviado a %s",
"Your_password_is_wrong": "Su contraseña es incorrecta!",
"Your_push_was_sent_to_s_devices": "Su push fue enviado a los dispositivos %s"
}
}
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@
"Nothing": "Nada",
"Nothing_found": "Nada encontrado",
"Notifications": "Notificações",
"Notifications_Sound_Volume": "Volume do som de notificações",
"Notify_all_in_this_room": "Notificar todos nesta sala",
"Num_Agents": "# Agentes",
"Number_of_messages": "Número de mensagens",
Expand Down
3 changes: 2 additions & 1 deletion packages/rocketchat-i18n/i18n/sq.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@
"Nothing": "asgjë",
"Nothing_found": "Asgjë për të gjetur",
"Notifications": "Njoftime",
"Notifications_Sound_Volume": "Vëllimi i tingullit të njoftimeve",
"Notify_all_in_this_room": "Njoftojë të gjithë në këtë dhomë",
"Num_Agents": "# Agents",
"Number_of_messages": "Numri i mesazheve",
Expand Down Expand Up @@ -1219,4 +1220,4 @@
"Your_mail_was_sent_to_s": "maili juaj u dërgua në %s",
"Your_password_is_wrong": "Fjalëkalimi juaj është e gabuar!",
"Your_push_was_sent_to_s_devices": "shtytje juaj u dërgua në pajisjet %s"
}
}
5 changes: 4 additions & 1 deletion packages/rocketchat-livechat/app/client/lib/_visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ this.visitor = new class {

// notification sound
if (Session.equals('sound', true) && msg.u._id !== Meteor.userId()) {
$('#chatAudioNotification')[0].play();
const audioVolume = Meteor.user() && Meteor.user().settings && Meteor.user().settings.preferences && Meteor.user().settings.preferences.notificationsSoundVolume || 100;
const audio = document.getElementById('chatAudioNotification');
audio.volume = Number((audioVolume/100).toPrecision(2));
audio.play();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,29 +255,37 @@ Template.pushNotificationsFlexTab.events({

'click [data-play]'(e) {
e.preventDefault();

let audio = $(e.currentTarget).data('play');
const user = Meteor.user();

if (!audio || audio === 'none') {
audio = user && user.settings && user.settings.preferences && user.settings.preferences.newMessageNotification || 'chime';
}

if (audio && audio !== 'none') {
const audioVolume = user && user.settings && user.settings.preferences && user.settings.preferences.notificationsSoundVolume || 100;
const $audio = $(`audio#${ audio }`);

if ($audio && $audio[0] && $audio[0].play) {
$audio[0].volume = Number((audioVolume/100).toPrecision(2));
$audio[0].play();
}
} else {
audio = Meteor.user() && Meteor.user().settings && Meteor.user().settings.preferences && Meteor.user().settings.preferences.newMessageNotification || 'chime';
if (audio && audio !== 'none') {
const $audio = $(`audio#${ audio }`);
if ($audio && $audio[0] && $audio[0].play) {
$audio[0].play();
}
}
}
},

'change select[name=audioNotification]'(e) {
e.preventDefault();

const audio = $(e.currentTarget).val();
const user = Meteor.user();

if (audio && audio !== 'none') {
const audioVolume = user && user.settings && user.settings.preferences && user.settings.preferences.notificationsSoundVolume || 100;
const $audio = $(`audio#${ audio }`);

if ($audio && $audio[0] && $audio[0].play) {
$audio[0].volume = Number((audioVolume/100).toPrecision(2));
$audio[0].play();
}
}
Expand Down
Empty file.
16 changes: 16 additions & 0 deletions packages/rocketchat-slider/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Package.describe({
name: 'rocketchat:slider',
version: '0.0.1',
summary: 'UI slider component for input range.',
git: '',
documentation: 'README.md'
});

Package.onUse(function(api) {
api.use('ecmascript');
api.use('templating', 'client');
api.use('rocketchat:theme');

api.addFiles('rocketchat-slider.html', 'client');
api.addFiles('rocketchat-slider.js', 'client');
});
6 changes: 6 additions & 0 deletions packages/rocketchat-slider/rocketchat-slider.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template name="slider">
<div class="range-slider">
<input class="range-slider-range tertiary-background-color" type="range" id="{{id}}" value="{{value}}" min="{{min}}" max="{{max}}">
<span class="range-slider-value" id="{{id}}_value"></span>
</div>
</template>
17 changes: 17 additions & 0 deletions packages/rocketchat-slider/rocketchat-slider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Template.slider.onRendered(function() {
const params = this.data;

const rangeSlider = function() {

const range = $(`#${ params.id }`);
const labelValue = $(`#${ params.id }_value`);

labelValue.html(params.value);

range.on('input', function() {
labelValue.html(this.value);
});
};

rangeSlider();
});
61 changes: 61 additions & 0 deletions packages/rocketchat-theme/client/imports/slider.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.range-slider {
margin: 0;
width: 100%;
}

.range-slider-range {
appearance: none;
width: calc(100% - 73px);
height: 10px;
border-radius: 5px;
outline: none;
padding: 0;
margin: 0;
}

.range-slider-range::-webkit-slider-thumb {
appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
cursor: pointer;
transition: background 0.15s ease-in-out;
}

.range-slider-range::-moz-range-thumb {
width: 20px;
height: 20px;
border: 0;
border-radius: 50%;
cursor: pointer;
transition: background 0.15s ease-in-out;
}

.range-slider-value {
display: inline-block;
position: relative;
width: 60px;
line-height: 20px;
text-align: center;
border-radius: 3px;
padding: 5px 10px;
margin-left: 8px;
}

.range-slider-value::after {
position: absolute;
top: 8px;
left: -7px;
width: 0;
height: 0;
border-top: 7px solid;
border-right: 7px solid;
border-bottom: 7px solid;
content: '';
}

.range-slider-range::-moz-range-track,
.range-slider-range::-moz-focus-inner,
.range-slider-range::-moz-focus-outer {
border: 0;
}
2 changes: 1 addition & 1 deletion packages/rocketchat-theme/client/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
@import 'imports/forms.css';
@import 'imports/base.css';
@import 'imports/rtl.css';

@import 'imports/slider.css';
43 changes: 43 additions & 0 deletions packages/rocketchat-theme/server/colors.less
Original file line number Diff line number Diff line change
Expand Up @@ -916,3 +916,46 @@ label.required::after {
opacity: inherit;
}
}

/** ----------------------------------------------------------------------------
* Input Range Slider
*/

.range-slider-range::-webkit-slider-thumb {
background-color: @primary-background-color;
}

.range-slider-range::-webkit-slider-thumb:hover {
background-color: darken(@success-color, 30%);
}

.range-slider-range:active::-webkit-slider-thumb {
background-color: darken(@success-color, 10%);
}

.range-slider-range::-moz-range-thumb {
background-color: @primary-background-color;
}

.range-slider-range::-moz-range-thumb:hover {
background-color: darken(@success-color, 30%);
}

.range-slider-range:active::-moz-range-thumb {
background-color: darken(@success-color, 10%);
}

.range-slider-value {
color: lighten(@tertiary-background-color, 50%);
background-color: @primary-background-color;
}

.range-slider-value::after {
border-top-color: transparent;
border-right-color: @primary-background-color;
border-bottom-color: transparent;
}

.range-slider-range::-moz-range-track {
background-color: @tertiary-background-color;
}
6 changes: 6 additions & 0 deletions packages/rocketchat-ui-account/client/accountPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ <h1>{{_ "Sound"}}</h1>
</select>
</div>
</div>
<div class="input-line double-col">
<label>{{_ "Notifications_Sound_Volume"}}</label>
<div>
{{> slider id="notificationsSoundVolume" min="0" max="100" value=notificationsSoundVolume}}
</div>
</div>
</div>
</div>
</fieldset>
Expand Down
6 changes: 6 additions & 0 deletions packages/rocketchat-ui-account/client/accountPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Template.accountPreferences.helpers({
},
showRoles() {
return RocketChat.settings.get('UI_DisplayRoles');
},
notificationsSoundVolume() {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences.notificationsSoundVolume || 100;
}
});

Expand Down Expand Up @@ -123,6 +127,8 @@ Template.accountPreferences.onCreated(function() {
}));
data.desktopNotificationDuration = $('input[name=desktopNotificationDuration]').val();
data.unreadAlert = $('#unreadAlert').find('input:checked').val();
data.notificationsSoundVolume = parseInt($('#notificationsSoundVolume').val());

Meteor.call('saveUserPreferences', data, function(error, results) {
if (results) {
toastr.success(t('Preferences_saved'));
Expand Down
37 changes: 25 additions & 12 deletions packages/rocketchat-ui/client/lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,23 @@ const KonchatNotification = {
if (!Session.equals(`user_${ Meteor.userId() }_status`, 'busy')) {
const user = Meteor.user();
const newMessageNotification = user && user.settings && user.settings.preferences && user.settings.preferences.newMessageNotification || 'chime';
const audioVolume = user && user.settings && user.settings.preferences && user.settings.preferences.notificationsSoundVolume || 100;

const sub = ChatSubscription.findOne({ rid }, { fields: { audioNotification: 1 } });

if (sub && sub.audioNotification !== 'none') {
if (sub && sub.audioNotification) {
const [audio] = $(`audio#${ sub.audioNotification }`);
return audio && audio.play && audio.play();
if (audio && audio.play) {
audio.volume = Number((audioVolume/100).toPrecision(2));
return audio.play();
}
} else if (newMessageNotification !== 'none') {
const [audio] = $(`audio#${ newMessageNotification }`);
return audio && audio.play && audio.play();
if (audio && audio.play) {
audio.volume = Number((audioVolume/100).toPrecision(2));
return audio.play();
}
}
}
}
Expand Down Expand Up @@ -116,24 +125,28 @@ const KonchatNotification = {
};

Tracker.autorun(function() {
let audio;
const user = Meteor.user();
const newRoomNotification = user && user.settings && user.settings.preferences && user.settings.preferences.newRoomNotification || 'door';
const audioVolume = user && user.settings && user.settings.preferences && user.settings.preferences.notificationsSoundVolume || 100;

if ((Session.get('newRoomSound') || []).length > 0) {
Tracker.nonreactive(function() {
const user = RocketChat.models.Users.findOne({ _id: Meteor.userId() }, { fields: { 'settings.preferences.newRoomNotification': 1 } });
const newRoomNotification = user && user.settings && user.settings.preferences && user.settings.preferences.newRoomNotification || 'door';
if (!Session.equals(`user_${ Meteor.userId() }_status`, 'busy') && newRoomNotification !== 'none') {
[audio] = $(`audio#${ newRoomNotification }`);
return audio && audio.play && audio.play();
const [audio] = $(`audio#${ newRoomNotification }`);
if (audio && audio.play) {
audio.volume = Number((audioVolume/100).toPrecision(2));
return audio.play();
}
}
});
} else {
if (!audio) {
const [room] = $(`audio#${ newRoomNotification }`);
if (!room) {
return;
}
if (audio.pause) {
audio.pause();
audio.currentTime = 0;
audio = null;
if (room.pause) {
room.pause();
return room.currentTime = 0;
}
}
});
Expand Down
Loading

0 comments on commit 82b7845

Please sign in to comment.