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...

This commit is contained in:
Julian Lam
2015-01-25 09:41:51 -05:00
parent 288d507eb6
commit 5a1c2b9ddf
2 changed files with 16 additions and 10 deletions

View File

@@ -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.');
}
});
});
});

View File

@@ -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;