Skip to content

Node.js based forum software built for the modern web

closes #4094, also add missing next to notifyFollowers

barisusakli04aea9ec2235
diff --git a/src/topics/follow.js b/src/topics/follow.js
index 250f571dc4..671a540496 100644
--- a/src/topics/follow.js
+++ b/src/topics/follow.js
@@ -1,18 +1,17 @@
'use strict';
-var async = require('async'),
- nconf = require('nconf'),
- S = require('string'),
- winston = require('winston'),
-
- db = require('../database'),
- user = require('../user'),
- posts = require('../posts'),
- notifications = require('../notifications'),
- privileges = require('../privileges'),
- meta = require('../meta'),
- emailer = require('../emailer');
+var async = require('async');
+var nconf = require('nconf');
+var S = require('string');
+var winston = require('winston');
+
+var db = require('../database');
+var user = require('../user');
+var notifications = require('../notifications');
+var privileges = require('../privileges');
+var meta = require('../meta');
+var emailer = require('../emailer');
module.exports = function(Topics) {
@@ -104,10 +103,10 @@ module.exports = function(Topics) {
var followers, title;
async.waterfall([
- function(next) {
+ function (next) {
Topics.getFollowers(postData.topic.tid, next);
},
- function(followers, next) {
+ function (followers, next) {
if (!Array.isArray(followers) || !followers.length) {
return callback();
}
@@ -121,7 +120,7 @@ module.exports = function(Topics) {
privileges.topics.filterUids('read', postData.topic.tid, followers, next);
},
- function(_followers, next) {
+ function (_followers, next) {
followers = _followers;
if (!followers.length) {
return callback();
@@ -151,13 +150,21 @@ module.exports = function(Topics) {
next();
});
},
- function(next) {
+ function (next) {
+
+ if (parseInt(meta.config.disableEmailSubscriptions, 10) === 1) {
+ return next();
+ }
+
async.eachLimit(followers, 3, function(toUid, next) {
async.parallel({
userData: async.apply(user.getUserFields, toUid, ['username', 'userslug']),
userSettings: async.apply(user.getSettings, toUid)
}, 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, {
pid: postData.pid,
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title,
@@ -171,6 +178,7 @@ module.exports = function(Topics) {
}, next);
} else {
winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.');
+ next();
}
});
});
diff --git a/src/user/settings.js b/src/user/settings.js
index a2d83e89eb..7adc79829e 100644
--- a/src/user/settings.js
+++ b/src/user/settings.js
@@ -81,13 +81,13 @@ module.exports = function(User) {
});
}
- function getSetting(settings, key, base) {
+ function getSetting(settings, key, defaultValue) {
if (settings[key] || settings[key] === 0) {
return settings[key];
} else if (meta.config[key] || meta.config[key] === 0) {
return meta.config[key];
}
- return base;
+ return defaultValue;
}
User.saveSettings = function(uid, data, callback) {
@@ -122,7 +122,7 @@ module.exports = function(User) {
if (data.bootswatchSkin) {
settings.bootswatchSkin = data.bootswatchSkin;
}
-
+
async.waterfall([
function(next) {
db.setObject('user:' + uid + ':settings', settings, next);