Skip to content

Commit

Permalink
Merge pull request #9312 from RationalCoding/develop
Browse files Browse the repository at this point in the history
[NEW] Allow sounds when conversation is focused
  • Loading branch information
rodrigok authored Feb 15, 2018
2 parents 9b7eb38 + 515dac3 commit 6a292a7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
13 changes: 9 additions & 4 deletions client/notifications/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Meteor.startup(function() {
// This logic is duplicated in /client/startup/unread.coffee.
const hasFocus = readMessage.isEnable();
const messageIsInOpenedRoom = openedRoomId === notification.payload.rid;
const muteFocusedConversations = RocketChat.getUserPreference(Meteor.user(), 'muteFocusedConversations');

fireGlobalEvent('notification', {
notification,
Expand All @@ -42,10 +43,13 @@ Meteor.startup(function() {
KonchatNotification.newMessage(notification.payload.rid);
KonchatNotification.showDesktop(notification);
}
} else if (!(hasFocus && messageIsInOpenedRoom)) {
} else if (!hasFocus || !messageIsInOpenedRoom) {
// Play a sound and show a notification.
KonchatNotification.newMessage(notification.payload.rid);
KonchatNotification.showDesktop(notification);
} else if (!muteFocusedConversations) {
// Play a notification sound
KonchatNotification.newMessage(notification.payload.rid);
}
});

Expand All @@ -56,14 +60,15 @@ Meteor.startup(function() {
// This logic is duplicated in /client/startup/unread.coffee.
const hasFocus = readMessage.isEnable();
const messageIsInOpenedRoom = openedRoomId === notification.payload.rid;
const muteFocusedConversations = RocketChat.getUserPreference(Meteor.user(), 'muteFocusedConversations');

if (RocketChat.Layout.isEmbedded()) {
if (!hasFocus && messageIsInOpenedRoom) {
// Play a sound and show a notification.
// Play a notification sound
KonchatNotification.newMessage(notification.payload.rid);
}
} else if (!(hasFocus && messageIsInOpenedRoom)) {
// Play a sound and show a notification.
} else if (!hasFocus || !messageIsInOpenedRoom || !muteFocusedConversations) {
// Play a notification sound
KonchatNotification.newMessage(notification.payload.rid);
}
});
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 @@ -1300,6 +1300,7 @@
"Mute_all_notifications": "Mute all notifications",
"mute-user": "Mute User",
"mute-user_description": "Permission to mute other users in the same channel",
"Mute_Focused_Conversations": "Mute Focused Conversations",
"Mute_someone_in_room": "Mute someone in the room",
"Mute_user": "Mute user",
"Muted": "Muted",
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ RocketChat.settings.addGroup('Accounts', function() {
'public': true,
i18nLabel: 'New_Message_Notification'
});
this.add('Accounts_Default_User_Preferences_muteFocusedConversations', true, {
type: 'boolean',
'public': true,
i18nLabel: 'Mute_Focused_Conversations'
});
this.add('Accounts_Default_User_Preferences_notificationsSoundVolume', 100, {
type: 'int',
'public': true,
Expand Down
7 changes: 7 additions & 0 deletions packages/rocketchat-ui-account/client/accountPreferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ <h1>{{_ "Sound"}}</h1>
</select>
</div>
</div>
<div class="input-line double-col" id="muteFocusedConversations">
<label>{{_ "Mute_Focused_Conversations"}}</label>
<div>
<label><input type="radio" name="muteFocusedConversations" value="1" checked="{{checked 'muteFocusedConversations' true}}"/> {{_ "True"}}</label>
<label><input type="radio" name="muteFocusedConversations" value="0" checked="{{checked 'muteFocusedConversations' false}}"/> {{_ "False"}}</label>
</div>
</div>
<div class="input-line double-col">
<label>{{_ "Notifications_Sound_Volume"}}</label>
<div>
Expand Down
6 changes: 5 additions & 1 deletion packages/rocketchat-ui-account/client/accountPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Template.accountPreferences.helpers({
newRoomNotification() {
return RocketChat.getUserPreference(Meteor.user(), 'newRoomNotification');
},
muteFocusedConversations() {
return RocketChat.getUserPreference(Meteor.user(), 'muteFocusedConversations');
},
languages() {
const languages = TAPi18n.getLanguages();

Expand Down Expand Up @@ -129,6 +132,7 @@ Template.accountPreferences.onCreated(function() {

data.newRoomNotification = $('select[name=newRoomNotification]').val();
data.newMessageNotification = $('select[name=newMessageNotification]').val();
data.muteFocusedConversations = $('#muteFocusedConversations').find('input:checked').val();
data.useEmojis = $('input[name=useEmojis]:checked').val();
data.convertAsciiEmoji = $('input[name=convertAsciiEmoji]:checked').val();
data.saveMobileBandwidth = $('input[name=saveMobileBandwidth]:checked').val();
Expand Down Expand Up @@ -239,7 +243,7 @@ Template.accountPreferences.events({
}
if (audio) {
const $audio = $(`audio#${ audio }`);
return $audio && $audio[0] && $audio.play();
return $audio && $audio[0] && $audio[0].play();
}
}
});
4 changes: 4 additions & 0 deletions server/methods/saveUserPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Meteor.methods({
preferences.newMessageNotification = settings.newMessageNotification;
}

if (settings.muteFocusedConversations) {
preferences.muteFocusedConversations = settings.muteFocusedConversations === '1' ? true : false;
}

if (settings.useEmojis) {
preferences.useEmojis = settings.useEmojis === '1' ? true : false;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/pageobjects/administration.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ class Administration extends Page {
get accountsNewMessageNotification() { return browser.element('[name="Accounts_Default_User_Preferences_newMessageNotification"]'); }
get accountsNewMessageNotificationReset() { return browser.element('.reset-setting[data-setting="Accounts_Default_User_Preferences_newMessageNotification"]'); }

get accountsMuteFocusedConversationsTrue() { return browser.element('label:nth-of-type(1) [name="Accounts_Default_User_Preferences_muteFocusedConversations"]'); }
get accountsMuteFocusedConversationsFalse() { return browser.element('label:nth-of-type(2) [name="Accounts_Default_User_Preferences_muteFocusedConversations"]'); }
get accountsMuteFocusedConversationsReset() { return browser.element('.reset-setting[data-setting="Accounts_Default_User_Preferences_muteFocusedConversations"]'); }

get accountsNotificationsSoundVolume() { return browser.element('[name="Accounts_Default_User_Preferences_notificationsSoundVolume"]'); }
get accountsNotificationsSoundVolumeReset() { return browser.element('.reset-setting[data-setting="Accounts_Default_User_Preferences_notificationsSoundVolume"]'); }

Expand Down

0 comments on commit 6a292a7

Please sign in to comment.