Node.js based forum software built for the modern web
closes #6465
Barış Soner Uşaklı6659a520e034
diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.jsindex 5166222706..5f5bb57aa7 100644--- a/src/controllers/accounts/settings.js+++ b/src/controllers/accounts/settings.js@@ -9,6 +9,7 @@ var meta = require('../../meta');var plugins = require('../../plugins');var privileges = require('../../privileges');var categories = require('../../categories');+var notifications = require('../../notifications');var db = require('../../database');var helpers = require('../helpers');var accountHelpers = require('./helpers');@@ -180,15 +181,6 @@ settingsController.get = function (req, res, callback) {};function getNotificationSettings(userData, callback) {- var types = [- 'notificationType_upvote',- 'notificationType_new-topic',- 'notificationType_new-reply',- 'notificationType_follow',- 'notificationType_new-chat',- 'notificationType_group-invite',- ];-var privilegedTypes = [];async.waterfall([@@ -206,8 +198,7 @@ function getNotificationSettings(userData, callback) {privilegedTypes.push('notificationType_new-user-flag');}plugins.fireHook('filter:user.notificationTypes', {- userData: userData,- types: types,+ types: notifications.baseTypes.slice(),privilegedTypes: privilegedTypes,}, next);},diff --git a/src/controllers/admin/settings.js b/src/controllers/admin/settings.jsindex 678a9e4e8c..d711e7cdcc 100644--- a/src/controllers/admin/settings.js+++ b/src/controllers/admin/settings.js@@ -4,7 +4,7 @@ var async = require('async');var meta = require('../../meta');var emailer = require('../../emailer');-var plugins = require('../../plugins');+var notifications = require('../../notifications');var settingsController = module.exports;@@ -45,32 +45,12 @@ function renderEmail(req, res, next) {}function renderUser(req, res, next) {- var types = [- 'notificationType_upvote',- 'notificationType_new-topic',- 'notificationType_new-reply',- 'notificationType_follow',- 'notificationType_new-chat',- 'notificationType_group-invite',- ];-- var privilegedTypes = [- 'notificationType_new-register',- 'notificationType_post-queue',- 'notificationType_new-post-flag',- 'notificationType_new-user-flag',- ];-async.waterfall([function (next) {- plugins.fireHook('filter:user.notificationTypes', {- userData: {},- types: types,- privilegedTypes: privilegedTypes,- }, next);+ notifications.getAllNotificationTypes(next);},- function (results) {- var notificationSettings = results.types.concat(results.privilegedTypes).map(function (type) {+ function (notificationTypes) {+ var notificationSettings = notificationTypes.map(function (type) {return {name: type,label: '[[notifications:' + type + ']]',diff --git a/src/notifications.js b/src/notifications.jsindex 8a91c44509..a9ef31f734 100644--- a/src/notifications.js+++ b/src/notifications.js@@ -17,6 +17,36 @@ var emailer = require('./emailer');var Notifications = module.exports;+Notifications.baseTypes = [+ 'notificationType_upvote',+ 'notificationType_new-topic',+ 'notificationType_new-reply',+ 'notificationType_follow',+ 'notificationType_new-chat',+ 'notificationType_group-invite',+];++Notifications.privilegedTypes = [+ 'notificationType_new-register',+ 'notificationType_post-queue',+ 'notificationType_new-post-flag',+ 'notificationType_new-user-flag',+];++Notifications.getAllNotificationTypes = function (callback) {+ async.waterfall([+ function (next) {+ plugins.fireHook('filter:user.notificationTypes', {+ types: Notifications.baseTypes.slice(),+ privilegedTypes: Notifications.privilegedTypes.slice(),+ }, next);+ },+ function (results, next) {+ next(null, results.types.concat(results.privilegedTypes));+ },+ ], callback);+};+Notifications.startJobs = function () {winston.verbose('[notifications.init] Registering jobs.');new cron('*/30 * * * *', Notifications.prune, null, true);diff --git a/src/user/settings.js b/src/user/settings.jsindex c654d2dd99..202c440d14 100644--- a/src/user/settings.js+++ b/src/user/settings.js@@ -6,6 +6,7 @@ var async = require('async');var meta = require('../meta');var db = require('../database');var plugins = require('../plugins');+var notifications = require('../notifications');module.exports = function (User) {User.getSettings = function (uid, callback) {@@ -81,12 +82,14 @@ module.exports = function (User) {settings.delayImageLoading = parseInt(getSetting(settings, 'delayImageLoading', 1), 10) === 1;settings.bootswatchSkin = settings.bootswatchSkin || meta.config.bootswatchSkin || 'default';settings.scrollToMyPost = parseInt(getSetting(settings, 'scrollToMyPost', 1), 10) === 1;- settings.notificationType_upvote = getSetting(settings, 'notificationType_upvote', 'notification');- settings['notificationType_new-topic'] = getSetting(settings, 'notificationType_new-topic', 'notification');- settings['notificationType_new-reply'] = getSetting(settings, 'notificationType_new-reply', 'notification');- settings.notificationType_follow = getSetting(settings, 'notificationType_follow', 'notification');- settings['notificationType_new-chat'] = getSetting(settings, 'notificationType_new-chat', 'notification');- settings['notificationType_group-invite'] = getSetting(settings, 'notificationType_group-invite', 'notification');++ notifications.getAllNotificationTypes(next);+ },+ function (notificationTypes, next) {+ notificationTypes.forEach(function (notificationType) {+ settings[notificationType] = getSetting(settings, notificationType, 'notification');+ });+next(null, settings);},], callback);@@ -139,26 +142,20 @@ module.exports = function (User) {upvoteNotifFreq: data.upvoteNotifFreq,};- var notificationTypes = [- 'notificationType_upvote', 'notificationType_new-topic', 'notificationType_new-reply',- 'notificationType_follow', 'notificationType_new-chat', 'notificationType_group-invite',- 'notificationType_new-register', 'notificationType_post-queue', 'notificationType_new-post-flag',- 'notificationType_new-user-flag',- ];-- notificationTypes.forEach(function (notificationType) {- if (data[notificationType]) {- settings[notificationType] = data[notificationType];- }- });--if (data.bootswatchSkin) {settings.bootswatchSkin = data.bootswatchSkin;}async.waterfall([function (next) {+ notifications.getAllNotificationTypes(next);+ },+ function (notificationTypes, next) {+ notificationTypes.forEach(function (notificationType) {+ if (data[notificationType]) {+ settings[notificationType] = data[notificationType];+ }+ });plugins.fireHook('filter:user.saveSettings', { settings: settings, data: data }, next);},function (result, next) {