|
|
@ -66,6 +66,7 @@ EmailService.prototype.start = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
self.defaultLanguage = opts.defaultLanguage || 'en'; |
|
|
|
self.defaultUnit = opts.defaultUnit || 'btc'; |
|
|
|
self.templatePath = path.normalize((opts.templatePath || (__dirname + '/templates')) + '/'); |
|
|
|
|
|
|
|
async.parallel([ |
|
|
@ -163,7 +164,7 @@ EmailService.prototype._getRecipientsList = function(notification, emailType, cb |
|
|
|
copayerId: p.copayerId, |
|
|
|
emailAddress: p.email, |
|
|
|
language: p.language, |
|
|
|
unit: p.unit || 'btc', |
|
|
|
unit: p.unit || self.defaultUnit, |
|
|
|
}; |
|
|
|
})); |
|
|
|
|
|
|
@ -171,13 +172,13 @@ EmailService.prototype._getRecipientsList = function(notification, emailType, cb |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
EmailService.prototype._getDataForTemplate = function(notification, cb) { |
|
|
|
EmailService.prototype._getDataForTemplate = function(notification, recipient, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var data = _.cloneDeep(notification.data); |
|
|
|
data.subjectPrefix = _.trim(self.subjectPrefix) + ' '; |
|
|
|
if (data.amount) { |
|
|
|
data.amount = WalletUtils.formatAmount(+data.amount, 'bit') + ' bits'; |
|
|
|
data.amount = WalletUtils.formatAmount(+data.amount, recipient.unit) + ' ' + recipient.unit; |
|
|
|
} |
|
|
|
self.storage.fetchWallet(notification.walletId, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
@ -228,30 +229,31 @@ EmailService.prototype._send = function(email, cb) { |
|
|
|
EmailService.prototype._readAndApplyTemplates = function(notification, emailType, recipientsList, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
async.waterfall([ |
|
|
|
async.map(recipientsList, function(recipient, next) { |
|
|
|
async.waterfall([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|
self._getDataForTemplate(notification, next); |
|
|
|
}, |
|
|
|
function(data, next) { |
|
|
|
var languages = _.uniq(_.pluck(recipientsList, 'language')); |
|
|
|
async.map(languages, function(lang, next) { |
|
|
|
async.waterfall([ |
|
|
|
function(next) { |
|
|
|
async.parallel([ |
|
|
|
|
|
|
|
function(next) { |
|
|
|
self._readTemplate(emailType.filename, lang, next); |
|
|
|
self._readTemplate(emailType.filename, recipient.language, next); |
|
|
|
}, |
|
|
|
function(template, next) { |
|
|
|
self._applyTemplate(template, data, next); |
|
|
|
function(next) { |
|
|
|
self._getDataForTemplate(notification, recipient, next); |
|
|
|
}, |
|
|
|
], function(err, res) { |
|
|
|
next(err, [lang, res]); |
|
|
|
}); |
|
|
|
}, function(err, res) { |
|
|
|
return next(err, _.zipObject(res)); |
|
|
|
}); |
|
|
|
}, |
|
|
|
], cb); |
|
|
|
], next); |
|
|
|
}, |
|
|
|
function(result, next) { |
|
|
|
var template = result[0]; |
|
|
|
var data = result[1]; |
|
|
|
self._applyTemplate(template, data, next); |
|
|
|
}, |
|
|
|
], function(err, res) { |
|
|
|
next(err, [recipient.language, res]); |
|
|
|
}); |
|
|
|
}, function(err, res) { |
|
|
|
return cb(err, _.zipObject(res)); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
EmailService.prototype.sendEmail = function(notification, cb) { |
|
|
|