Not take into account the 'pending' section when finding users to send a mail to

This commit is contained in:
quenenni 2013-04-03 00:41:11 +02:00
parent 787b9157be
commit a98c59fed5

View file

@ -43,22 +43,25 @@ exports.notifyBegin = function(padId){
db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email
if(recipients){ if(recipients){
async.forEach(Object.keys(recipients), function(recipient, cb){ async.forEach(Object.keys(recipients), function(recipient, cb){
// Is this recipient already on the pad? //avoid the 'pending' section
exports.isUserEditingPad(padId, recipients[recipient].authorId, function(err,userIsOnPad){ // is the user already on the pad? if (recipient != 'pending') {
var onStart = typeof(recipients[recipient].onStart) == "undefined" || recipients[recipient].onStart?true:false; // In case onStart wasn't defined we set it to true // Is this recipient already on the pad?
if(!userIsOnPad && onStart){ exports.isUserEditingPad(padId, recipients[recipient].authorId, function(err,userIsOnPad){ // is the user already on the pad?
console.debug("Emailing "+recipient +" about a new begin update"); var onStart = typeof(recipients[recipient].onStart) == "undefined" || recipients[recipient].onStart?true:false; // In case onStart wasn't defined we set it to true
server.send({ if(!userIsOnPad && onStart){
text: "Your pad at "+urlToPads+padId +" is being edited, we're just emailing you let you know :)", console.debug("Emailing "+recipient +" about a new begin update");
from: fromName+ "<"+fromEmail+">", server.send({
to: recipient, text: "Your pad at "+urlToPads+padId +" is being edited, we're just emailing you let you know :)",
subject: "Someone started editing "+padId from: fromName+ "<"+fromEmail+">",
}, function(err, message) { console.log(err || message); }); to: recipient,
} subject: "Someone started editing "+padId
else{ }, function(err, message) { console.log(err || message); });
console.debug("Didn't send an email because user is already on the pad"); }
} else{
}); console.debug("Didn't send an email because user is already on the pad");
}
});
}
cb(); // finish each user cb(); // finish each user
}, },
function(err){ function(err){
@ -75,23 +78,26 @@ exports.notifyEnd = function(padId){
db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email
if(recipients){ if(recipients){
async.forEach(Object.keys(recipients), function(recipient, cb){ async.forEach(Object.keys(recipients), function(recipient, cb){
// Is this recipient already on the pad? //avoid the 'pending' section
exports.isUserEditingPad(padId, recipients[recipient].authorId, function(err,userIsOnPad){ // is the user already on the$ if (recipient != 'pending') {
var onEnd = typeof(recipients[recipient].onEnd) == "undefined" || recipients[recipient].onEnd?true:false; // In case onEnd wasn't defined we set it to false // Is this recipient already on the pad?
exports.isUserEditingPad(padId, recipients[recipient].authorId, function(err,userIsOnPad){ // is the user already on the$
var onEnd = typeof(recipients[recipient].onEnd) == "undefined" || recipients[recipient].onEnd?true:false; // In case onEnd wasn't defined we set it to false
if(!userIsOnPad && onEnd){ if(!userIsOnPad && onEnd){
console.debug("Emailing "+recipient +" about a pad finished being updated"); console.debug("Emailing "+recipient +" about a pad finished being updated");
server.send({ server.send({
text: "Your pad at "+urlToPads+padId +" has finished being edited, we're just emailing you let you know :) \n\n The changes look like this: \n" + changesToPad, text: "Your pad at "+urlToPads+padId +" has finished being edited, we're just emailing you let you know :) \n\n The changes look like this: \n" + changesToPad,
from: fromName+ "<"+fromEmail+">", from: fromName+ "<"+fromEmail+">",
to: recipient, to: recipient,
subject: "Someone finished editing "+padId subject: "Someone finished editing "+padId
}, function(err, message) { console.log(err || message); }); }, function(err, message) { console.log(err || message); });
} }
else{ else{
console.debug("Didn't send an email because user is already on the pad"); console.debug("Didn't send an email because user is already on the pad");
} }
}); });
}
cb(); // finish each user cb(); // finish each user
}, },
function(err){ function(err){