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] Adds admin option to globally set mobile devices to always be notified regardless of presence status. #7641

Merged
merged 6 commits into from
Dec 7, 2017
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
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