Skip to content

Node.js based forum software built for the modern web

booleanifying sendPostNotification user setting when requested, and now only sending the post notification if the user has flipped that option on in user settings... kind of an important thing to forget...

Julian Lam5a1c2b9ddf77
diff --git a/src/topics/follow.js b/src/topics/follow.js
index c1ba78e384..7d88c9752e 100644
--- a/src/topics/follow.js
+++ b/src/topics/follow.js
@@ -4,6 +4,7 @@
var async = require('async'),
nconf = require('nconf'),
S = require('string'),
+ winston = require('winston'),
db = require('../database'),
user = require('../user'),
@@ -133,16 +134,20 @@ module.exports = function(Topics) {
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);
+ if (data.userSettings.hasOwnProperty('sendPostNotifications') && data.userSettings.sendPostNotifications) {
+ 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);
+ } else {
+ winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.');
+ }
});
});
});
diff --git a/src/user/settings.js b/src/user/settings.js
index 9ac714ea6e..9f3e1166eb 100644
--- a/src/user/settings.js
+++ b/src/user/settings.js
@@ -69,6 +69,7 @@ module.exports = function(User) {
settings.followTopicsOnCreate = (settings.followTopicsOnCreate === null || settings.followTopicsOnCreate === undefined) ? true : parseInt(settings.followTopicsOnCreate, 10) === 1;
settings.followTopicsOnReply = parseInt(settings.followTopicsOnReply, 10) === 1;
settings.sendChatNotifications = parseInt(settings.sendChatNotifications, 10) === 1;
+ settings.sendPostNotifications = parseInt(settings.sendPostNotifications, 10) === 1;
settings.restrictChat = parseInt(settings.restrictChat, 10) === 1;
settings.topicSearchEnabled = parseInt(settings.topicSearchEnabled, 10) === 1;