Skip to content

Commit

Permalink
Merge pull request #7641 from stalley/mobile-notify-always
Browse files Browse the repository at this point in the history
[NEW] Adds admin option to globally set mobile devices to always be notified regardless of presence status.
  • Loading branch information
rodrigok committed Dec 7, 2017
2 parents e2b99ea + 3b6ca5e commit 0cdcf89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,8 @@
"Notification_Duration": "Notification Duration",
"Notification_Mobile_Default_For": "Push Mobile Notifications For",
"Notifications": "Notifications",
"Notifications_Always_Notify_Mobile" : "Always notify mobile",
"Notifications_Always_Notify_Mobile_Description" : "Choose to always notify mobile device regardless of presence status.",
"Notifications_Max_Room_Members": "Max Room Members Before Disabling All Message Notifications",
"Notifications_Max_Room_Members_Description": "Max number of members in room when notifications for all messages gets disabled. Users can still change per room setting to receive all notifications on an individual basis. (0 to disable)",
"Notifications_Muted_Description": "If you choose to mute everything, you won't see the room highlight in the list when there are new messages, except for mentions. Muting notifications will override notifications settings.",
Expand Down Expand Up @@ -2099,4 +2101,4 @@
"your_message_optional": "your message (optional)",
"Your_password_is_wrong": "Your password is wrong!",
"Your_push_was_sent_to_s_devices": "Your push was sent to %s devices"
}
}
18 changes: 12 additions & 6 deletions packages/rocketchat-lib/server/lib/sendNotificationsOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
let userIdsToNotify = [];
let userIdsToPushNotify = [];
const mentions = [];
const alwaysNotifyMobileBoolean = RocketChat.settings.get('Notifications_Always_Notify_Mobile');

const usersWithHighlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch()
.filter(user => messageContainsHighlight(message, user.settings.preferences.highlights));
Expand Down Expand Up @@ -288,7 +289,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
}

if (canBeNotified(userOfMentionId, 'mobile')) {
if (Push.enabled === true && userOfMention.statusConnection !== 'online') {
if (Push.enabled === true && (userOfMention.statusConnection !== 'online' || alwaysNotifyMobileBoolean === true)) {
RocketChat.PushNotification.send({
roomId: message.rid,
username: push_username,
Expand All @@ -315,6 +316,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
const mentionIds = (message.mentions || []).map(({_id}) => _id);
const toAll = mentionIds.includes('all');
const toHere = mentionIds.includes('here');

if (mentionIds.length + settings.alwaysNotifyDesktopUsers.length > 0) {
let desktopMentionIds = _.union(mentionIds, settings.alwaysNotifyDesktopUsers);
desktopMentionIds = _.difference(desktopMentionIds, settings.dontNotifyDesktopUsers);
Expand Down Expand Up @@ -344,21 +346,25 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room, userId) {
let mobileMentionIds = _.union(mentionIds, settings.alwaysNotifyMobileUsers);
mobileMentionIds = _.difference(mobileMentionIds, settings.dontNotifyMobileUsers);

let usersOfMobileMentions = RocketChat.models.Users.find({
const usersOfMobileMentionsQuery = {
_id: {
$in: mobileMentionIds
},
statusConnection: {
$ne:'online'
}
}, {
};

if (alwaysNotifyMobileBoolean !== true) {
usersOfMobileMentionsQuery.statusConnection = { $ne: 'online' };
}

let usersOfMobileMentions = RocketChat.models.Users.find(usersOfMobileMentionsQuery, {
fields: {
_id: 1,
username: 1,
statusConnection: 1,
active: 1
}
}).fetch();

mentions.push(...usersOfMobileMentions);
if (room.t !== 'c') {
usersOfMobileMentions = _.reject(usersOfMobileMentions, usersOfMentionItem => !room.usernames.includes(usersOfMentionItem.username));
Expand Down
6 changes: 6 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ RocketChat.settings.addGroup('General', function() {
public: true,
i18nDescription: 'Notifications_Max_Room_Members_Description'
});

this.add('Notifications_Always_Notify_Mobile', false, {
type: 'boolean',
public: true,
i18nDescription: 'Notifications_Always_Notify_Mobile_Description'
});
});
this.section('REST API', function() {
return this.add('API_User_Limit', 500, {
Expand Down

0 comments on commit 0cdcf89

Please sign in to comment.