Fix new room sound being played too much

pull/8144/head
Diego Sampaio 8 years ago
parent e647926ad8
commit 096672ed85
No known key found for this signature in database
GPG Key ID: E060152B30502562
  1. 11
      client/notifications/notification.js
  2. 2
      packages/rocketchat-ui-sidenav/client/accountBox.js
  3. 12
      packages/rocketchat-ui-sidenav/client/chatRoomItem.js
  4. 2
      packages/rocketchat-ui-sidenav/client/sideNav.html
  5. 19
      packages/rocketchat-ui-sidenav/client/sideNav.js
  6. 9
      packages/rocketchat-ui/client/lib/notification.js

@ -55,6 +55,17 @@ Meteor.startup(function() {
KonchatNotification.newMessage(notification.payload.rid);
}
});
RocketChat.Notifications.onUser('subscriptions-changed', function(action, sub) {
// Do not play new room sound if user is busy
if (Session.equals(`user_${ Meteor.userId() }_status`, 'busy')) {
return;
}
if (!(FlowRouter.getParam('name') && FlowRouter.getParam('name') === sub.name) && !sub.ls && sub.alert === true) {
return KonchatNotification.newRoom(sub.rid);
}
});
}
});
});

@ -29,7 +29,7 @@ Template.accountBox.helpers({
},
isAnonymous() {
if (Meteor.user() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead')) {
if (Meteor.userId() == null && RocketChat.settings.get('Accounts_AllowAnonymousRead')) {
return 'disabled';
}
}

@ -1,5 +1,3 @@
/* globals KonchatNotification */
Template.chatRoomItem.helpers({
roomData() {
let name = this.name;
@ -25,10 +23,6 @@ Template.chatRoomItem.helpers({
if (!this.hideUnreadStatus && (FlowRouter.getParam('_id') !== this.rid || !document.hasFocus()) && this.alert) {
alertClass = 'sidebar-item__link--active';
}
// Sound notification
if (!(FlowRouter.getParam('name') === this.name) && !this.ls && this.alert === true) {
KonchatNotification.newRoom(this.rid);
}
const icon = RocketChat.roomTypes.getIcon(this.t);
const avatar = !icon;
@ -47,9 +41,3 @@ Template.chatRoomItem.helpers({
};
}
});
Template.chatRoomItem.onRendered = function() {
if (!(FlowRouter.getParam('name') && (FlowRouter.getParam('name') === this.name)) && !this.ls && (this.alert === true)) {
return KonchatNotification.newRoom(this.rid);
}
};

@ -5,7 +5,7 @@
{{> toolbar}}
</header>
{{#if currentUser}}
{{#if loggedInUser}}
<div class="unread-rooms background-primary-action-color color-primary-action-contrast top-unread-rooms hidden">
{{_ "More_unreads"}} <i class="icon-up-big"></i>
</div>

@ -1,14 +1,6 @@
/* globals menu*/
Template.sideNav.helpers({
hasUnread() {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences.roomsListExhibitionMode === 'unread';
},
sortByActivity() {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences.roomsListExhibitionMode === 'activity';
},
flexTemplate() {
return SideNav.getFlex().template;
},
@ -23,6 +15,10 @@ Template.sideNav.helpers({
roomType() {
return RocketChat.roomTypes.getTypes();
},
loggedInUser() {
return !!Meteor.userId();
}
});
@ -69,7 +65,12 @@ Template.sideNav.onCreated(function() {
this.mergedChannels = new ReactiveVar(false);
this.autorun(() => {
const user = Meteor.user();
const user = RocketChat.models.Users.findOne(Meteor.userId(), {
fields: {
'settings.preferences.roomsListExhibitionMode': 1,
'settings.preferences.mergeChannels': 1
}
});
let userPref = null;
if (user && user.settings && user.settings.preferences) {
userPref = user.settings.preferences.roomsListExhibitionMode === 'category' && user.settings.preferences.mergeChannels;

@ -125,13 +125,18 @@ const KonchatNotification = {
};
Tracker.autorun(function() {
const user = Meteor.user();
const user = RocketChat.models.Users.findOne(Meteor.userId(), {
fields: {
'settings.preferences.newRoomNotification': 1,
'settings.preferences.notificationsSoundVolume': 1
}
});
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() {
if (!Session.equals(`user_${ Meteor.userId() }_status`, 'busy') && newRoomNotification !== 'none') {
if (newRoomNotification !== 'none') {
const [audio] = $(`audio#${ newRoomNotification }`);
if (audio && audio.play) {
audio.volume = Number((audioVolume/100).toPrecision(2));

Loading…
Cancel
Save