changed emailer.send so that it processes a callback, if provided. Also added new option to receive emails every time a topic you subscribe to is posted to.

This commit is contained in:
Julian Lam
2015-01-23 21:27:42 -05:00
parent 4b3aa26abd
commit bc9ede7b6c
6 changed files with 66 additions and 7 deletions

View File

@@ -19,10 +19,10 @@ var fs = require('fs'),
return Emailer;
};
Emailer.send = function(template, uid, params) {
Emailer.send = function(template, uid, params, callback) {
if (!app) {
winston.warn('[emailer] App not ready!');
return;
return callback();
}
async.parallel({
@@ -36,7 +36,8 @@ var fs = require('fs'),
settings: async.apply(User.getSettings, uid)
}, function(err, results) {
if (err) {
return winston.error('[emailer] Error sending digest : ' + err.stack);
winston.error('[emailer] Error sending digest : ' + err.stack);
return callback(err);
}
async.map([results.html, results.plaintext, params.subject], function(raw, next) {
translator.translate(raw, results.settings.language || meta.config.defaultLang || 'en_GB', function(translated) {
@@ -44,9 +45,11 @@ var fs = require('fs'),
});
}, function(err, translated) {
if (err) {
return winston.error(err.message);
winston.error(err.message);
return callback(err);
} else if (!results.email) {
return winston.warn('uid : ' + uid + ' has no email, not sending.');
winston.warn('uid : ' + uid + ' has no email, not sending.');
return callback();
}
if (Plugins.hasListeners('action:email.send')) {
@@ -57,10 +60,12 @@ var fs = require('fs'),
html: translated[0],
plaintext: translated[1],
template: template,
uid: uid
uid: uid,
pid: params.pid
});
} else {
winston.warn('[emailer] No active email plugin found!');
callback();
}
});
});