diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 6d3a1ff4ea6e..27749b6a2614 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -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", @@ -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", diff --git a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js index 779b1c57b888..c4351cc46c7c 100644 --- a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js @@ -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) { diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 33532cb036a9..aee2caa865ff 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -181,7 +181,8 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { desktopNotificationDurations: {}, alwaysNotifyAudioUsers: [], dontNotifyAudioUsers: [], - audioNotificationValues: {} + audioNotificationValues: {}, + dontNotifyUsersOnGroupMentions: [] }; /** @@ -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 = []; @@ -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); } }); } diff --git a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html index 59cff0f76060..962ab0c2ef81 100644 --- a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html +++ b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html @@ -24,6 +24,24 @@ +
+
+
+ {{_ "Receive_Group_Mentions"}} +
+
+ +
+
+ {{_ "Mute_Group_Mentions"}} +
+
+
diff --git a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.js b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.js index 46a8f6a75473..d999dce8f5b9 100644 --- a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.js +++ b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.js @@ -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(); }, @@ -109,7 +112,8 @@ Template.pushNotificationsFlexTab.onCreated(function() { mobilePushNotifications: 1, emailNotifications: 1, desktopNotificationDuration: 1, - audioNotificationValue: 1 + audioNotificationValue: 1, + muteGroupMentions: 1 } }) || {}; @@ -121,7 +125,8 @@ Template.pushNotificationsFlexTab.onCreated(function() { mobilePushNotifications = 'default', emailNotifications = 'default', desktopNotificationDuration = 0, - audioNotificationValue = null + audioNotificationValue = null, + muteGroupMentions = false } = sub; this.original = { @@ -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 = { @@ -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() => { diff --git a/packages/rocketchat-push-notifications/server/methods/saveNotificationSettings.js b/packages/rocketchat-push-notifications/server/methods/saveNotificationSettings.js index 1bf4ec2ac844..c4d3cdb3dbbb 100644 --- a/packages/rocketchat-push-notifications/server/methods/saveNotificationSettings.js +++ b/packages/rocketchat-push-notifications/server/methods/saveNotificationSettings.js @@ -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) }, diff --git a/packages/rocketchat-push-notifications/server/models/Subscriptions.js b/packages/rocketchat-push-notifications/server/models/Subscriptions.js index a60402ef5509..ce988d39a332 100644 --- a/packages/rocketchat-push-notifications/server/models/Subscriptions.js +++ b/packages/rocketchat-push-notifications/server/models/Subscriptions.js @@ -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, @@ -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) { diff --git a/server/publications/subscription.js b/server/publications/subscription.js index deb363656731..88758879c124 100644 --- a/server/publications/subscription.js +++ b/server/publications/subscription.js @@ -29,6 +29,7 @@ const fields = { autoTranslateLanguage: 1, disableNotifications: 1, hideUnreadStatus: 1, + muteGroupMentions: 1, ignored: 1 };