closes #4094, also add missing next to notifyFollowers

v1.18.x
barisusakli 9 years ago
parent 535dd82902
commit 04aea9ec22

@ -1,18 +1,17 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
nconf = require('nconf'), var nconf = require('nconf');
S = require('string'), var S = require('string');
winston = require('winston'), var winston = require('winston');
db = require('../database'), var db = require('../database');
user = require('../user'), var user = require('../user');
posts = require('../posts'), var notifications = require('../notifications');
notifications = require('../notifications'), var privileges = require('../privileges');
privileges = require('../privileges'), var meta = require('../meta');
meta = require('../meta'), var emailer = require('../emailer');
emailer = require('../emailer');
module.exports = function(Topics) { module.exports = function(Topics) {
@ -152,12 +151,20 @@ module.exports = function(Topics) {
}); });
}, },
function (next) { function (next) {
if (parseInt(meta.config.disableEmailSubscriptions, 10) === 1) {
return next();
}
async.eachLimit(followers, 3, function(toUid, next) { async.eachLimit(followers, 3, function(toUid, next) {
async.parallel({ async.parallel({
userData: async.apply(user.getUserFields, toUid, ['username', 'userslug']), userData: async.apply(user.getUserFields, toUid, ['username', 'userslug']),
userSettings: async.apply(user.getSettings, toUid) userSettings: async.apply(user.getSettings, toUid)
}, function(err, data) { }, function(err, data) {
if (data.userSettings.hasOwnProperty('sendPostNotifications') && data.userSettings.sendPostNotifications) { if (err) {
return next(err);
}
if (data.userSettings.sendPostNotifications) {
emailer.send('notif_post', toUid, { emailer.send('notif_post', toUid, {
pid: postData.pid, pid: postData.pid,
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title, subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title,
@ -171,6 +178,7 @@ module.exports = function(Topics) {
}, next); }, next);
} else { } else {
winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.'); winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.');
next();
} }
}); });
}); });

@ -81,13 +81,13 @@ module.exports = function(User) {
}); });
} }
function getSetting(settings, key, base) { function getSetting(settings, key, defaultValue) {
if (settings[key] || settings[key] === 0) { if (settings[key] || settings[key] === 0) {
return settings[key]; return settings[key];
} else if (meta.config[key] || meta.config[key] === 0) { } else if (meta.config[key] || meta.config[key] === 0) {
return meta.config[key]; return meta.config[key];
} }
return base; return defaultValue;
} }
User.saveSettings = function(uid, data, callback) { User.saveSettings = function(uid, data, callback) {

Loading…
Cancel
Save