refactored chat notification system to wait a bit before sending notif/email, closes #2098

This commit is contained in:
Julian Lam
2014-09-16 13:27:26 -04:00
parent 451c5b40fd
commit b85ff61de6
5 changed files with 61 additions and 23 deletions

View File

@@ -197,7 +197,7 @@ SocketModules.chats.send = function(socket, data, callback) {
return callback(err);
}
sendChatNotification(socket.uid, touid, message);
Messaging.notifyUser(socket.uid, touid, message);
// Recipient
SocketModules.chats.pushUnreadCount(touid);
@@ -217,23 +217,6 @@ SocketModules.chats.send = function(socket, data, callback) {
});
};
function sendChatNotification(fromuid, touid, messageObj) {
// todo #1798 -- this should check if the user is in room `chat_{uidA}_{uidB}` instead, see `Sockets.uidInRoom(uid, room);`
if (!module.parent.exports.isUserOnline(touid)) {
notifications.create({
bodyShort: '[[notifications:new_message_from, ' + messageObj.fromUser.username + ']]',
bodyLong: messageObj.content,
path: nconf.get('relative_path') + '/chats/' + utils.slugify(messageObj.fromUser.username),
nid: 'chat_' + fromuid + '_' + touid,
from: fromuid
}, function(err, notification) {
if (!err && notification) {
notifications.push(notification, [touid]);
}
});
}
}
SocketModules.chats.pushUnreadCount = function(uid) {
Messaging.getUnreadCount(uid, function(err, unreadCount) {
if (err) {