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.

v1.18.x
Julian Lam 10 years ago
parent 4b3aa26abd
commit bc9ede7b6c

@ -23,6 +23,9 @@
"notif.chat.cta": "Click here to continue the conversation", "notif.chat.cta": "Click here to continue the conversation",
"notif.chat.unsub.info": "This chat notification was sent to you due to your subscription settings.", "notif.chat.unsub.info": "This chat notification was sent to you due to your subscription settings.",
"notif.post.cta": "Click here to read the full topic",
"notif.post.unsub.info": "This post notification was sent to you due to your subscription settings.",
"test.text1": "This is a test email to verify that the emailer is set up correctly for your NodeBB.", "test.text1": "This is a test email to verify that the emailer is set up correctly for your NodeBB.",
"unsub.cta": "Click here to alter those settings", "unsub.cta": "Click here to alter those settings",

@ -64,6 +64,7 @@
"digest_weekly": "Weekly", "digest_weekly": "Weekly",
"digest_monthly": "Monthly", "digest_monthly": "Monthly",
"send_chat_notifications": "Send an email if a new chat message arrives and I am not online", "send_chat_notifications": "Send an email if a new chat message arrives and I am not online",
"send_post_notifications": "Send an email when replies are made to topics I am subscribed to",
"has_no_follower": "This user doesn't have any followers :(", "has_no_follower": "This user doesn't have any followers :(",
"follows_no_one": "This user isn't following anyone :(", "follows_no_one": "This user isn't following anyone :(",

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

@ -9,7 +9,9 @@ var async = require('async'),
user = require('../user'), user = require('../user'),
posts = require('../posts'), posts = require('../posts'),
postTools = require('../postTools'), postTools = require('../postTools'),
notifications = require('../notifications'); notifications = require('../notifications'),
meta = require('../meta'),
emailer = require('../emailer');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -125,6 +127,24 @@ module.exports = function(Topics) {
notifications.push(notification, followers); notifications.push(notification, followers);
} }
}); });
async.eachLimit(followers, 3, function(toUid, next) {
async.parallel({
userData: async.apply(user.getUserFields, toUid, ['username']),
userSettings: async.apply(user.getSettings, toUid)
}, function(err, data) {
emailer.send('notif_post', toUid, {
pid: postData.pid,
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title,
intro: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]',
postBody: postData.content,
site_title: meta.config.title || 'NodeBB',
username: data.userData.username,
url: nconf.get('url') + '/topics/' + postData.topic.tid,
base_url: nconf.get('url')
}, next);
});
});
}); });
}; };
}; };

@ -0,0 +1,16 @@
<p>[[email:greeting_with_name, {username}]],</p>
<p>{intro}:</p>
<blockquote>{postBody}</blockquote>
<a href="{url}">[[email:notif.post.cta]]</a>
<p>
[[email:closing]]<br />
<strong>{site_title}</strong>
</p>
<hr />
<p>
[[email:notif.post.unsub.info]] <a href="{base_url}/user/{username}/settings">[[email:unsub.cta]]</a>.
</p>

@ -0,0 +1,14 @@
[[email:greeting_with_name, {username}]],
{intro}:
{postBody}
[[email:notif.post.cta]]: {url}
[[email:closing]]
{site_title}
===
[[email:notif.post.unsub.info]] <a href="{base_url}/user/{username}/settings">[[email:unsub.cta]]</a>.
Loading…
Cancel
Save