From c761ab6bcf72a6acbf7159f81878242fc3c1b679 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Wed, 6 Jun 2018 16:15:10 -0300 Subject: [PATCH 1/2] Fix @all notifications and ignored users --- .../server/lib/sendNotificationsOnMessage.js | 8 ++++++-- .../server/models/Subscriptions.js | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index 966ec4f277e3d..b9b9fd457bfab 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -29,7 +29,7 @@ const sendNotification = ({ } // dont send notification to users who ignored the sender - if (Array.isArray(subscription.ignored) && subscription.ignored.find(sender._id)) { + if (Array.isArray(subscription.ignored) && subscription.ignored.includes(sender._id)) { return; } @@ -199,11 +199,15 @@ function sendAllNotifications(message, room) { [notificationField]: 'mentions', 'u._id': { $in: mentionIdsWithoutGroups } }); + } else if ((hasMentionToAll || hasMentionToHere) && !disableAllMessageNotifications) { + query.$or.push({ + [notificationField]: 'mentions' + }); } const serverField = kind === 'email' ? 'emailNotificationMode' : `${ kind }Notifications`; const serverPreference = RocketChat.settings.get(`Accounts_Default_User_Preferences_${ serverField }`); - if ((room.t === 'd' && serverPreference === 'mentions') || (serverPreference === 'all' && !disableAllMessageNotifications)) { + if ((room.t === 'd' && serverPreference === 'mentions') || ((serverPreference === 'all' || hasMentionToAll || hasMentionToHere) && !disableAllMessageNotifications)) { query.$or.push({ [notificationField]: { $exists: false } }); diff --git a/packages/rocketchat-push-notifications/server/models/Subscriptions.js b/packages/rocketchat-push-notifications/server/models/Subscriptions.js index 7e051dc881656..3caaf666b56c9 100644 --- a/packages/rocketchat-push-notifications/server/models/Subscriptions.js +++ b/packages/rocketchat-push-notifications/server/models/Subscriptions.js @@ -235,6 +235,7 @@ RocketChat.models.Subscriptions.findNotificationPreferencesByRoom = function(que code: 1, // fields to define if should send a notification + ignored: 1, audioNotifications: 1, audioNotificationValue: 1, desktopNotificationDuration: 1, From f78a9b00fe17de9ac065f6c2d934fd7c8c450e89 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 8 Jun 2018 16:47:36 -0300 Subject: [PATCH 2/2] Execute simple tests first --- .../rocketchat-lib/server/lib/sendNotificationsOnMessage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js index b9b9fd457bfab..1f33a449b8260 100644 --- a/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js +++ b/packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js @@ -199,7 +199,7 @@ function sendAllNotifications(message, room) { [notificationField]: 'mentions', 'u._id': { $in: mentionIdsWithoutGroups } }); - } else if ((hasMentionToAll || hasMentionToHere) && !disableAllMessageNotifications) { + } else if (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) { query.$or.push({ [notificationField]: 'mentions' }); @@ -207,7 +207,7 @@ function sendAllNotifications(message, room) { const serverField = kind === 'email' ? 'emailNotificationMode' : `${ kind }Notifications`; const serverPreference = RocketChat.settings.get(`Accounts_Default_User_Preferences_${ serverField }`); - if ((room.t === 'd' && serverPreference === 'mentions') || ((serverPreference === 'all' || hasMentionToAll || hasMentionToHere) && !disableAllMessageNotifications)) { + if ((room.t === 'd' && serverPreference !== 'nothing') || (!disableAllMessageNotifications && (serverPreference === 'all' || hasMentionToAll || hasMentionToHere))) { query.$or.push({ [notificationField]: { $exists: false } });