|
|
|
|
@ -16,16 +16,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
/* |
|
|
|
|
Increment unread couter if direct messages |
|
|
|
|
*/ |
|
|
|
|
var indexOf = [].indexOf || function(item) { |
|
|
|
|
for (var i = 0, l = this.length; i < l; i++) { |
|
|
|
|
if (i in this && this[i] === item) { |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return -1; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var settings, desktopMentionIds, i, j, len, len1, highlights, mentionIds, highlightsIds, usersWithHighlights, mobileMentionIds, ref, ref1, toAll, toHere, userIdsToNotify, userIdsToPushNotify, userOfMention, userOfMentionId, usersOfDesktopMentions, usersOfMentionId, usersOfMentionItem, usersOfMobileMentions; |
|
|
|
|
const settings = {}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Checks if a given user can be notified |
|
|
|
|
@ -67,8 +58,6 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
return has; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
settings = {}; |
|
|
|
|
|
|
|
|
|
settings.alwaysNotifyDesktopUsers = []; |
|
|
|
|
settings.dontNotifyDesktopUsers = []; |
|
|
|
|
settings.alwaysNotifyMobileUsers = []; |
|
|
|
|
@ -90,11 +79,11 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
settings.desktopNotificationDurations[subscription.u._id] = subscription.desktopNotificationDuration; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
userIdsToNotify = []; |
|
|
|
|
userIdsToPushNotify = []; |
|
|
|
|
usersWithHighlights = []; |
|
|
|
|
let userIdsToNotify = []; |
|
|
|
|
let userIdsToPushNotify = []; |
|
|
|
|
const usersWithHighlights = []; |
|
|
|
|
|
|
|
|
|
highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch(); |
|
|
|
|
const highlights = RocketChat.models.Users.findUsersByUsernamesWithHighlights(room.usernames, { fields: { '_id': 1, 'settings.preferences.highlights': 1 }}).fetch(); |
|
|
|
|
|
|
|
|
|
highlights.forEach(function(user) { |
|
|
|
|
if (messageContainsHighlight(message, user.settings.preferences.highlights)) { |
|
|
|
|
@ -120,9 +109,9 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
push_room = ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((room.t == null) || room.t === 'd') { |
|
|
|
|
userOfMentionId = message.rid.replace(message.u._id, ''); |
|
|
|
|
userOfMention = RocketChat.models.Users.findOne({ |
|
|
|
|
if (room.t == null || room.t === 'd') { |
|
|
|
|
const userOfMentionId = message.rid.replace(message.u._id, ''); |
|
|
|
|
const userOfMention = RocketChat.models.Users.findOne({ |
|
|
|
|
_id: userOfMentionId |
|
|
|
|
}, { |
|
|
|
|
fields: { |
|
|
|
|
@ -174,19 +163,19 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
mentionIds = []; |
|
|
|
|
if ((ref = message.mentions) != null) { |
|
|
|
|
ref.forEach(function(mention) { |
|
|
|
|
const mentionIds = []; |
|
|
|
|
if (message.mentions != null) { |
|
|
|
|
message.mentions.forEach(function(mention) { |
|
|
|
|
return mentionIds.push(mention._id); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
toAll = mentionIds.indexOf('all') > -1; |
|
|
|
|
toHere = mentionIds.indexOf('here') > -1; |
|
|
|
|
const toAll = mentionIds.indexOf('all') > -1; |
|
|
|
|
const toHere = mentionIds.indexOf('here') > -1; |
|
|
|
|
if (mentionIds.length > 0 || settings.alwaysNotifyDesktopUsers.length > 0) { |
|
|
|
|
desktopMentionIds = _.union(mentionIds, settings.alwaysNotifyDesktopUsers); |
|
|
|
|
let desktopMentionIds = _.union(mentionIds, settings.alwaysNotifyDesktopUsers); |
|
|
|
|
desktopMentionIds = _.difference(desktopMentionIds, settings.dontNotifyDesktopUsers); |
|
|
|
|
|
|
|
|
|
usersOfDesktopMentions = RocketChat.models.Users.find({ |
|
|
|
|
let usersOfDesktopMentions = RocketChat.models.Users.find({ |
|
|
|
|
_id: { |
|
|
|
|
$in: desktopMentionIds |
|
|
|
|
} |
|
|
|
|
@ -205,8 +194,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
for (i = 0, len = usersOfDesktopMentions.length; i < len; i++) { |
|
|
|
|
usersOfMentionItem = usersOfDesktopMentions[i]; |
|
|
|
|
for (const usersOfMentionItem of usersOfDesktopMentions) { |
|
|
|
|
if (room.usernames.indexOf(usersOfMentionItem.username) === -1) { |
|
|
|
|
callJoin(usersOfMentionItem); |
|
|
|
|
} |
|
|
|
|
@ -223,10 +211,10 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mentionIds.length > 0 || settings.alwaysNotifyMobileUsers.length > 0) { |
|
|
|
|
mobileMentionIds = _.union(mentionIds, settings.alwaysNotifyMobileUsers); |
|
|
|
|
let mobileMentionIds = _.union(mentionIds, settings.alwaysNotifyMobileUsers); |
|
|
|
|
mobileMentionIds = _.difference(mobileMentionIds, settings.dontNotifyMobileUsers); |
|
|
|
|
|
|
|
|
|
usersOfMobileMentions = RocketChat.models.Users.find({ |
|
|
|
|
let usersOfMobileMentions = RocketChat.models.Users.find({ |
|
|
|
|
_id: { |
|
|
|
|
$in: mobileMentionIds |
|
|
|
|
} |
|
|
|
|
@ -249,7 +237,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
}), '_id'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((toAll || toHere) && ((ref1 = room.usernames) != null ? ref1.length : void 0) > 0) { |
|
|
|
|
if ((toAll || toHere) && room.usernames && room.usernames.length > 0) { |
|
|
|
|
RocketChat.models.Users.find({ |
|
|
|
|
username: { |
|
|
|
|
$in: room.usernames |
|
|
|
|
@ -265,18 +253,17 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
statusConnection: 1 |
|
|
|
|
} |
|
|
|
|
}).forEach(function(user) { |
|
|
|
|
var ref2, ref3, ref4; |
|
|
|
|
if (((ref2 = user.status) === 'online' || ref2 === 'away' || ref2 === 'busy') && (ref3 = user._id, indexOf.call(settings.dontNotifyDesktopUsers, ref3) < 0)) { |
|
|
|
|
if (['online', 'away', 'busy'].includes(user.status) && (settings.dontNotifyDesktopUsers || []).includes(user._id) === false) { |
|
|
|
|
userIdsToNotify.push(user._id); |
|
|
|
|
} |
|
|
|
|
if (toAll && user.statusConnection !== 'online' && (ref4 = user._id, indexOf.call(settings.dontNotifyMobileUsers, ref4) < 0)) { |
|
|
|
|
if (toAll && user.statusConnection !== 'online' && (settings.dontNotifyMobileUsers || []).includes(user._id) === false) { |
|
|
|
|
return userIdsToPushNotify.push(user._id); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (usersWithHighlights.length > 0) { |
|
|
|
|
highlightsIds = _.pluck(usersWithHighlights, '_id'); |
|
|
|
|
const highlightsIds = _.pluck(usersWithHighlights, '_id'); |
|
|
|
|
userIdsToNotify = userIdsToNotify.concat(highlightsIds); |
|
|
|
|
userIdsToPushNotify = userIdsToPushNotify.concat(highlightsIds); |
|
|
|
|
} |
|
|
|
|
@ -285,8 +272,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) { |
|
|
|
|
userIdsToPushNotify = _.without(_.compact(_.unique(userIdsToPushNotify)), message.u._id); |
|
|
|
|
|
|
|
|
|
if (userIdsToNotify.length > 0) { |
|
|
|
|
for (j = 0, len1 = userIdsToNotify.length; j < len1; j++) { |
|
|
|
|
usersOfMentionId = userIdsToNotify[j]; |
|
|
|
|
for (const usersOfMentionId of userIdsToNotify) { |
|
|
|
|
let title = '@' + user.username; |
|
|
|
|
if (room.name) { |
|
|
|
|
title += ' @ #' + room.name; |
|
|
|
|
|