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] Option to mute group mentions (@all and @here) #10502

Merged
merged 5 commits into from
Apr 21, 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
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,7 @@
"multi": "multi",
"multi_line": "multi line",
"Mute_all_notifications": "Mute all notifications",
"Mute_Group_Mentions" : "Mute @all and @here mentions",
"mute-user": "Mute User",
"mute-user_description": "Permission to mute other users in the same channel",
"Mute_Focused_Conversations": "Mute Focused Conversations",
Expand Down Expand Up @@ -1654,6 +1655,7 @@
"Reason_To_Join": "Reason to Join",
"RealName_Change_Disabled": "Your Rocket.Chat administrator has disabled the changing of names",
"Receive_alerts": "Receive alerts",
"Receive_Group_Mentions" : "Receive @all and @here mentions",
"Record": "Record",
"Redirect_URI": "Redirect URI",
"Refresh_keys": "Refresh keys",
Expand Down
8 changes: 6 additions & 2 deletions packages/rocketchat-lib/server/lib/sendEmailOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,21 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
query = RocketChat.models.Subscriptions.findByRoomIdAndUserIdsOrAllMessages(room._id, userIds);
}

query.forEach((sub) => {
query.forEach(sub => {
if (sub.disableNotifications) {
return delete usersToSendEmail[sub.u._id];
}

const emailNotifications = sub.emailNotifications;
const { emailNotifications, muteGroupMentions } = sub;

if (emailNotifications === 'nothing') {
return delete usersToSendEmail[sub.u._id];
}

if (isMentionAll && muteGroupMentions) {
return delete usersToSendEmail[sub.u._id];
}

const mentionedUser = isMentionAll || message.mentions.find(mention => mention._id === sub.u._id);

if (emailNotifications === 'default' || emailNotifications == null) {
Expand Down
29 changes: 19 additions & 10 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
desktopNotificationDurations: {},
alwaysNotifyAudioUsers: [],
dontNotifyAudioUsers: [],
audioNotificationValues: {}
audioNotificationValues: {},
dontNotifyUsersOnGroupMentions: []
};

/**
Expand Down Expand Up @@ -248,6 +249,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {

settings.audioNotificationValues[subscription.u._id] = subscription.audioNotificationValue;
settings.desktopNotificationDurations[subscription.u._id] = subscription.desktopNotificationDuration;

if (subscription.muteGroupMentions) {
settings.dontNotifyUsersOnGroupMentions.push(subscription.u._id);
}
});
let userIdsForAudio = [];
let userIdsToNotify = [];
Expand Down Expand Up @@ -419,17 +424,21 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
status: 1,
statusConnection: 1
}
}).forEach(function(user) {
if (['online', 'away', 'busy'].includes(user.status) && !(settings.dontNotifyDesktopUsers || []).includes(user._id)) {
userIdsToNotify.push(user._id);
userIdsForAudio.push(user._id);
}).forEach(function({ status, _id, username, statusConnection }) { // user
if (Array.isArray(settings.dontNotifyUsersOnGroupMentions) && settings.dontNotifyUsersOnGroupMentions.includes(_id)) {
return;
}

if (['online', 'away', 'busy'].includes(status) && !(settings.dontNotifyDesktopUsers || []).includes(_id)) {
userIdsToNotify.push(_id);
userIdsForAudio.push(_id);
}
if (toAll && user.statusConnection !== 'online' && !(settings.dontNotifyMobileUsers || []).includes(user._id)) {
pushUsernames[user._id] = user.username;
return userIdsToPushNotify.push(user._id);
if (toAll && statusConnection !== 'online' && !(settings.dontNotifyMobileUsers || []).includes(_id)) {
pushUsernames[_id] = username;
return userIdsToPushNotify.push(_id);
}
if (toAll && user.statusConnection !== 'online') {
userIdsForAudio.push(user._id);
if (toAll && statusConnection !== 'online') {
userIdsForAudio.push(_id);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
</div>
</div>
</div>
<div class="rc-user-info__row rc-user-info__row--separator">
<div class="rc-switch-double">
<div class="rc-switch-double__label {{#if muteGroupMentions}}disabled{{/if}}">
{{_ "Receive_Group_Mentions"}}
</div>
<div class="rc-switch rc-switch--blue">
<label class="rc-switch__label">
<input type="checkbox" class="rc-switch__input js-input-check" id="muteGroupMentions" name="muteGroupMentions" value="1" checked="{{$eq muteGroupMentions true}}">
<span class="rc-switch__button">
<span class="rc-switch__button-inside"></span>
</span>
</label>
</div>
<div class="rc-switch-double__label {{#unless muteGroupMentions}}disabled{{/unless}}">
{{_ "Mute_Group_Mentions"}}
</div>
</div>
</div>
<div class="rc-user-info__row rc-user-info__row--separator">
<div class="rc-switch-double">
<div class="rc-switch-double__label {{#if showUnreadStatus}}disabled{{/if}}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Template.pushNotificationsFlexTab.helpers({
showUnreadStatus() {
return !Template.instance().form.hideUnreadStatus.get();
},
muteGroupMentions() {
return Template.instance().form.muteGroupMentions.get();
},
hideUnreadStatus() {
return Template.instance().form.hideUnreadStatus.get();
},
Expand Down Expand Up @@ -109,7 +112,8 @@ Template.pushNotificationsFlexTab.onCreated(function() {
mobilePushNotifications: 1,
emailNotifications: 1,
desktopNotificationDuration: 1,
audioNotificationValue: 1
audioNotificationValue: 1,
muteGroupMentions: 1
}
}) || {};

Expand All @@ -121,7 +125,8 @@ Template.pushNotificationsFlexTab.onCreated(function() {
mobilePushNotifications = 'default',
emailNotifications = 'default',
desktopNotificationDuration = 0,
audioNotificationValue = null
audioNotificationValue = null,
muteGroupMentions = false
} = sub;

this.original = {
Expand All @@ -132,7 +137,8 @@ Template.pushNotificationsFlexTab.onCreated(function() {
mobilePushNotifications: new ReactiveVar(mobilePushNotifications),
emailNotifications: new ReactiveVar(emailNotifications),
desktopNotificationDuration: new ReactiveVar(desktopNotificationDuration),
audioNotificationValue: new ReactiveVar(audioNotificationValue)
audioNotificationValue: new ReactiveVar(audioNotificationValue),
muteGroupMentions: new ReactiveVar(muteGroupMentions)
};

this.form = {
Expand All @@ -143,7 +149,8 @@ Template.pushNotificationsFlexTab.onCreated(function() {
mobilePushNotifications: new ReactiveVar(mobilePushNotifications),
emailNotifications: new ReactiveVar(emailNotifications),
desktopNotificationDuration: new ReactiveVar(desktopNotificationDuration),
audioNotificationValue: new ReactiveVar(audioNotificationValue)
audioNotificationValue: new ReactiveVar(audioNotificationValue),
muteGroupMentions: new ReactiveVar(muteGroupMentions)
};

this.saveSetting = async() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Meteor.methods({
'hideUnreadStatus': {
updateMethod: (subscription, value) => RocketChat.models.Subscriptions.updateHideUnreadStatusById(subscription._id, value === '1')
},
'muteGroupMentions': {
updateMethod: (subscription, value) => RocketChat.models.Subscriptions.updateMuteGroupMentions(subscription._id, value === '1')
},
'desktopNotificationDuration': {
updateMethod: (subscription, value) => RocketChat.models.Subscriptions.updateDesktopNotificationDurationById(subscription._id, value)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ RocketChat.models.Subscriptions.updateHideUnreadStatusById = function(_id, hideU
return this.update(query, update);
};

RocketChat.models.Subscriptions.updateMuteGroupMentions = function(_id, muteGroupMentions) {
const query = {
_id
};

const update = {
$set: {
muteGroupMentions
}
};

return this.update(query, update);
};

RocketChat.models.Subscriptions.findAlwaysNotifyAudioUsersByRoomId = function(roomId) {
const query = {
rid: roomId,
Expand Down Expand Up @@ -188,11 +202,12 @@ RocketChat.models.Subscriptions.findNotificationPreferencesByRoom = function(roo
{desktopNotifications: {$exists: true}},
{desktopNotificationDuration: {$exists: true}},
{mobilePushNotifications: {$exists: true}},
{disableNotifications: {$exists: true}}
{disableNotifications: {$exists: true}},
{muteGroupMentions: {$exists: true}}
];
}

return this.find(query, { fields: { 'u._id': 1, audioNotifications: 1, audioNotificationValue: 1, desktopNotificationDuration: 1, desktopNotifications: 1, mobilePushNotifications: 1, disableNotifications: 1 } });
return this.find(query, { fields: { 'u._id': 1, audioNotifications: 1, audioNotificationValue: 1, desktopNotificationDuration: 1, desktopNotifications: 1, mobilePushNotifications: 1, disableNotifications: 1, muteGroupMentions: 1 } });
};

RocketChat.models.Subscriptions.findWithSendEmailByRoomId = function(roomId) {
Expand Down
1 change: 1 addition & 0 deletions server/publications/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const fields = {
autoTranslateLanguage: 1,
disableNotifications: 1,
hideUnreadStatus: 1,
muteGroupMentions: 1,
ignored: 1
};

Expand Down