Node.js based forum software built for the modern web
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.
Julian Lambc9ede7b6cd8
diff --git a/public/language/en_GB/email.json b/public/language/en_GB/email.jsonindex 75813bcb58..efee400748 100644--- a/public/language/en_GB/email.json+++ b/public/language/en_GB/email.json@@ -23,6 +23,9 @@"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.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.","unsub.cta": "Click here to alter those settings",diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.jsonindex 9ee1bbfefc..9c32b2d26e 100644--- a/public/language/en_GB/user.json+++ b/public/language/en_GB/user.json@@ -64,6 +64,7 @@"digest_weekly": "Weekly","digest_monthly": "Monthly","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 :(","follows_no_one": "This user isn't following anyone :(",diff --git a/src/emailer.js b/src/emailer.jsindex 3472ec0d2c..6eaf913e4c 100644--- a/src/emailer.js+++ b/src/emailer.js@@ -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();}});});diff --git a/src/topics/follow.js b/src/topics/follow.jsindex 00785ffd77..c1ba78e384 100644--- a/src/topics/follow.js+++ b/src/topics/follow.js@@ -9,7 +9,9 @@ var async = require('async'),user = require('../user'),posts = require('../posts'),postTools = require('../postTools'),- notifications = require('../notifications');+ notifications = require('../notifications'),+ meta = require('../meta'),+ emailer = require('../emailer');module.exports = function(Topics) {@@ -125,6 +127,24 @@ module.exports = function(Topics) {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);+ });+ });});};};\ No newline at end of filediff --git a/src/views/emails/notif_post.tpl b/src/views/emails/notif_post.tplnew file mode 100644index 0000000000..1f91d044be--- /dev/null+++ b/src/views/emails/notif_post.tpl@@ -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>\ No newline at end of filediff --git a/src/views/emails/notif_post_plaintext.tpl b/src/views/emails/notif_post_plaintext.tplnew file mode 100644index 0000000000..0920b2f79e--- /dev/null+++ b/src/views/emails/notif_post_plaintext.tpl@@ -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>.\ No newline at end of file