|
|
@ -11,6 +11,7 @@ var path = require('path'); |
|
|
|
var nodemailer = require('nodemailer'); |
|
|
|
|
|
|
|
var Utils = require('./common/utils'); |
|
|
|
var Defaults = require('./common/defaults'); |
|
|
|
var Storage = require('./storage'); |
|
|
|
var MessageBroker = require('./messagebroker'); |
|
|
|
var Lock = require('./lock'); |
|
|
@ -173,33 +174,44 @@ EmailService.prototype._applyTemplate = function(template, data, cb) { |
|
|
|
EmailService.prototype._getRecipientsList = function(notification, emailType, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
self.storage.fetchPreferences(notification.walletId, null, function(err, preferences) { |
|
|
|
self.storage.fetchWallet(notification.walletId, function(err, wallet) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (_.isEmpty(preferences)) return cb(null, []); |
|
|
|
|
|
|
|
var usedEmails = {}; |
|
|
|
var recipients = _.compact(_.map(preferences, function(p) { |
|
|
|
if (!p.email || usedEmails[p.email]) return; |
|
|
|
|
|
|
|
usedEmails[p.email] = true; |
|
|
|
if (notification.creatorId == p.copayerId && !emailType.notifyDoer) return; |
|
|
|
if (notification.creatorId != p.copayerId && !emailType.notifyOthers) return; |
|
|
|
if (!_.contains(self.availableLanguages, p.language)) { |
|
|
|
if (p.language) { |
|
|
|
log.warn('Language for email "' + p.language + '" not available.'); |
|
|
|
|
|
|
|
self.storage.fetchPreferences(notification.walletId, null, function(err, preferences) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (_.isEmpty(preferences)) return cb(null, []); |
|
|
|
|
|
|
|
var usedEmails = {}; |
|
|
|
var recipients = _.compact(_.map(preferences, function(p) { |
|
|
|
if (!p.email || usedEmails[p.email]) return; |
|
|
|
|
|
|
|
usedEmails[p.email] = true; |
|
|
|
if (notification.creatorId == p.copayerId && !emailType.notifyDoer) return; |
|
|
|
if (notification.creatorId != p.copayerId && !emailType.notifyOthers) return; |
|
|
|
if (!_.contains(self.availableLanguages, p.language)) { |
|
|
|
if (p.language) { |
|
|
|
log.warn('Language for email "' + p.language + '" not available.'); |
|
|
|
} |
|
|
|
p.language = self.defaultLanguage; |
|
|
|
} |
|
|
|
p.language = self.defaultLanguage; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
copayerId: p.copayerId, |
|
|
|
emailAddress: p.email, |
|
|
|
language: p.language, |
|
|
|
unit: p.unit || self.defaultUnit, |
|
|
|
}; |
|
|
|
})); |
|
|
|
var unit; |
|
|
|
if (wallet.coin != Defaults.COIN) { |
|
|
|
unit = wallet.coin; |
|
|
|
} else { |
|
|
|
unit = p.unit || self.defaultUnit; |
|
|
|
} |
|
|
|
|
|
|
|
return { |
|
|
|
copayerId: p.copayerId, |
|
|
|
emailAddress: p.email, |
|
|
|
language: p.language, |
|
|
|
unit: unit, |
|
|
|
}; |
|
|
|
})); |
|
|
|
|
|
|
|
return cb(null, recipients); |
|
|
|
return cb(null, recipients); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
@ -209,7 +221,8 @@ EmailService.prototype._getDataForTemplate = function(notification, recipient, c |
|
|
|
// TODO: Declare these in BWU
|
|
|
|
var UNIT_LABELS = { |
|
|
|
btc: 'BTC', |
|
|
|
bit: 'bits' |
|
|
|
bit: 'bits', |
|
|
|
bch: 'BCH', |
|
|
|
}; |
|
|
|
|
|
|
|
var data = _.cloneDeep(notification.data); |
|
|
|