From 5a1c2b9ddf777cce97a3d2637529c56bcfd8cb93 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 25 Jan 2015 09:41:51 -0500 Subject: [PATCH] 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... --- src/topics/follow.js | 25 +++++++++++++++---------- src/user/settings.js | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) 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;