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] Allow sounds when conversation is focused #9312

Merged
merged 7 commits into from
Feb 15, 2018
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
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on why embeds only fire notifications when the room is focused, instead of unfocused. I'm 99% sure this is an existing bug, but I've left it as is for now. (L40-41 above)

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 @@ -1296,6 +1296,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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here was the audio preview bug. It was calling "play" on an array instead of the first HTML5 audio object.

}
}
});
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