From 04aea9ec223564a244b152a37d1aa7514e7a6d58 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 23 Jan 2016 11:19:49 +0200 Subject: [PATCH] closes #4094, also add missing next to notifyFollowers --- src/topics/follow.js | 42 +++++++++++++++++++++++++----------------- src/user/settings.js | 6 +++--- 2 files changed, 28 insertions(+), 20 deletions(-) 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);