From 4b5836c5b2f88ae06f37536c7304a0c830b1d212 Mon Sep 17 00:00:00 2001 From: Hudell Date: Wed, 18 Apr 2018 17:40:54 -0300 Subject: [PATCH 1/3] Added option to mute generic mentions per channel --- packages/rocketchat-i18n/i18n/en.i18n.json | 2 ++ .../server/lib/sendEmailOnMessage.js | 6 ++++++ .../server/lib/sendNotificationsOnMessage.js | 11 ++++++++++- .../views/pushNotificationsFlexTab.html | 18 ++++++++++++++++++ .../client/views/pushNotificationsFlexTab.js | 15 +++++++++++---- .../methods/saveNotificationSettings.js | 3 +++ .../server/models/Subscriptions.js | 19 +++++++++++++++++-- server/publications/subscription.js | 3 ++- 8 files changed, 69 insertions(+), 8 deletions(-) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 2a545530cbbe..16c1dbd245be 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1351,6 +1351,7 @@ "multi": "multi", "multi_line": "multi line", "Mute_all_notifications": "Mute all notifications", + "Mute_Generic_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", @@ -1585,6 +1586,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_Generic_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..dea9974fd94b 100644 --- a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js @@ -129,6 +129,12 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { return delete usersToSendEmail[sub.u._id]; } + if (isMentionAll) { + if (sub.muteGenericMentions) { + 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 16c425a8a6dd..f6f1e1999822 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: {}, + dontNotifyUsersOnGenericMentions: [] }; /** @@ -245,6 +246,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.muteGenericMentions) { + settings.dontNotifyUsersOnGenericMentions.push(subscription.u._id); + } }); let userIdsForAudio = []; let userIdsToNotify = []; @@ -417,6 +422,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { statusConnection: 1 } }).forEach(function(user) { + if ((settings.dontNotifyUsersOnGenericMentions || []).includes(user._id)) { + return; + } + if (['online', 'away', 'busy'].includes(user.status) && !(settings.dontNotifyDesktopUsers || []).includes(user._id)) { userIdsToNotify.push(user._id); userIdsForAudio.push(user._id); diff --git a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html index 59cff0f76060..6046b5d21279 100644 --- a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html +++ b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html @@ -24,6 +24,24 @@ +
+
+
+ {{_ "Receive_Generic_Mentions"}} +
+
+ +
+
+ {{_ "Mute_Generic_Mentions"}} +
+
+
diff --git a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.js b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.js index 70f65e81ef12..b084f2772207 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(); }, + muteGenericMentions() { + return Template.instance().form.muteGenericMentions.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, + muteGenericMentions: 1 } }) || {}; @@ -121,7 +125,8 @@ Template.pushNotificationsFlexTab.onCreated(function() { mobilePushNotifications = 'default', emailNotifications = 'default', desktopNotificationDuration = 0, - audioNotificationValue = null + audioNotificationValue = null, + muteGenericMentions = 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), + muteGenericMentions: new ReactiveVar(muteGenericMentions) }; 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), + muteGenericMentions: new ReactiveVar(muteGenericMentions) }; 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..2a3fe5f8612a 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') }, + 'muteGenericMentions': { + updateMethod: (subscription, value) => RocketChat.models.Subscriptions.updateMuteGenericMentions(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..17be054005b8 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.updateMuteGenericMentions = function(_id, muteGenericMentions) { + const query = { + _id + }; + + const update = { + $set: { + muteGenericMentions + } + }; + + 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}}, + {muteGenericMentions: {$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, muteGenericMentions: 1 } }); }; RocketChat.models.Subscriptions.findWithSendEmailByRoomId = function(roomId) { diff --git a/server/publications/subscription.js b/server/publications/subscription.js index 2b00302f00fa..ee95d9145613 100644 --- a/server/publications/subscription.js +++ b/server/publications/subscription.js @@ -28,7 +28,8 @@ const fields = { autoTranslate: 1, autoTranslateLanguage: 1, disableNotifications: 1, - hideUnreadStatus: 1 + hideUnreadStatus: 1, + muteGenericMentions: 1 }; Meteor.methods({ From 3ceb35e29255145deec1fe18e48043b5bf4d9cca Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 20 Apr 2018 20:54:10 -0300 Subject: [PATCH 2/3] fix review --- .../server/lib/sendEmailOnMessage.js | 10 ++++------ .../server/lib/sendNotificationsOnMessage.js | 20 +++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js index dea9974fd94b..12567aa52a5b 100644 --- a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js @@ -118,21 +118,19 @@ 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 } = sub; if (emailNotifications === 'nothing') { return delete usersToSendEmail[sub.u._id]; } - if (isMentionAll) { - if (sub.muteGenericMentions) { - return delete usersToSendEmail[sub.u._id]; - } + if (isMentionAll && sub.muteGenericMentions) { + return delete usersToSendEmail[sub.u._id]; } const mentionedUser = isMentionAll || message.mentions.find(mention => mention._id === sub.u._id); diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index f6f1e1999822..37b20ac9e452 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -421,21 +421,21 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { status: 1, statusConnection: 1 } - }).forEach(function(user) { - if ((settings.dontNotifyUsersOnGenericMentions || []).includes(user._id)) { + }).forEach(function({ status, _id, username, statusConnection }) { // user + if (Array.isArray(settings.dontNotifyUsersOnGenericMentions) && settings.dontNotifyUsersOnGenericMentions.includes(_id)) { return; } - if (['online', 'away', 'busy'].includes(user.status) && !(settings.dontNotifyDesktopUsers || []).includes(user._id)) { - userIdsToNotify.push(user._id); - userIdsForAudio.push(user._id); + 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); } }); } From 7aa61f095631623c82a0625f58b489f093f02e9e Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 20 Apr 2018 21:19:07 -0300 Subject: [PATCH 3/3] changed generic to group --- packages/rocketchat-i18n/i18n/en.i18n.json | 4 ++-- .../rocketchat-lib/server/lib/sendEmailOnMessage.js | 2 +- .../server/lib/sendNotificationsOnMessage.js | 8 ++++---- .../client/views/pushNotificationsFlexTab.html | 10 +++++----- .../client/views/pushNotificationsFlexTab.js | 12 ++++++------ .../server/methods/saveNotificationSettings.js | 4 ++-- .../server/models/Subscriptions.js | 8 ++++---- server/publications/subscription.js | 2 +- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 16c1dbd245be..3648a038ad0b 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1351,7 +1351,7 @@ "multi": "multi", "multi_line": "multi line", "Mute_all_notifications": "Mute all notifications", - "Mute_Generic_Mentions" : "Mute @all and @here mentions", + "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", @@ -1586,7 +1586,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_Generic_Mentions" : "Receive @all and @here mentions", + "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 12567aa52a5b..bea9e6ac670a 100644 --- a/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendEmailOnMessage.js @@ -129,7 +129,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { return delete usersToSendEmail[sub.u._id]; } - if (isMentionAll && sub.muteGenericMentions) { + if (isMentionAll && sub.muteGroupMentions) { return delete usersToSendEmail[sub.u._id]; } diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 37b20ac9e452..03e4eb1f7ba9 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -182,7 +182,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { alwaysNotifyAudioUsers: [], dontNotifyAudioUsers: [], audioNotificationValues: {}, - dontNotifyUsersOnGenericMentions: [] + dontNotifyUsersOnGroupMentions: [] }; /** @@ -247,8 +247,8 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { settings.audioNotificationValues[subscription.u._id] = subscription.audioNotificationValue; settings.desktopNotificationDurations[subscription.u._id] = subscription.desktopNotificationDuration; - if (subscription.muteGenericMentions) { - settings.dontNotifyUsersOnGenericMentions.push(subscription.u._id); + if (subscription.muteGroupMentions) { + settings.dontNotifyUsersOnGroupMentions.push(subscription.u._id); } }); let userIdsForAudio = []; @@ -422,7 +422,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) { statusConnection: 1 } }).forEach(function({ status, _id, username, statusConnection }) { // user - if (Array.isArray(settings.dontNotifyUsersOnGenericMentions) && settings.dontNotifyUsersOnGenericMentions.includes(_id)) { + if (Array.isArray(settings.dontNotifyUsersOnGroupMentions) && settings.dontNotifyUsersOnGroupMentions.includes(_id)) { return; } diff --git a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html index 6046b5d21279..962ab0c2ef81 100644 --- a/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html +++ b/packages/rocketchat-push-notifications/client/views/pushNotificationsFlexTab.html @@ -26,19 +26,19 @@