controllers.home

v1.18.x
psychobunny 11 years ago
parent c084529597
commit 96d6b96ce4

@ -1,11 +1,14 @@
var topics = require('./topics'), var topicsController = require('./topics'),
categories = require('./categories'); categoriesController = require('./categories'),
async = require('async'),
categories = require('../categories'),
categoryTools = require('../categoryTools');
Controllers = { Controllers = {
topics: topics, topics: topicsController,
categories: categories categories: categoriesController
}; };
@ -33,20 +36,32 @@ Controllers.home = function(req, res, next) {
next(null); next(null);
}, },
"categories": function (next) { "categories": function (next) {
var uid = (req.user) ? req.user.uid : 0;
categories.getAllCategories(uid, function (err, data) {
data.categories = data.categories.filter(function (category) {
return !category.disabled;
});
function canSee(category, next) { function canSee(category, next) {
CategoryTools.privileges(category.cid, ((req.user) ? req.user.uid || 0 : 0), function(err, privileges) { categoryTools.privileges(category.cid, ((req.user) ? req.user.uid || 0 : 0), function(err, privileges) {
next(!err && privileges.read); next(!err && privileges.read);
}); });
} }
categories.getAllCategories(0, function (err, returnData) { function getRecentReplies(category, callback) {
returnData.categories = returnData.categories.filter(function (category) { categories.getRecentReplies(category.cid, uid, parseInt(category.numRecentReplies, 10), function (err, posts) {
return !category.disabled; category.posts = posts;
category.post_count = posts.length > 2 ? 2 : posts.length; // this was a hack to make metro work back in the day, post_count should just = length
callback(null);
}); });
}
async.filter(data.categories, canSee, function(visibleCategories) {
data.categories = visibleCategories;
async.filter(returnData.categories, canSee, function(visibleCategories) { async.each(data.categories, getRecentReplies, function (err) {
returnData.categories = visibleCategories; next(err, data.categories);
next(null, returnData); });
}); });
}); });
} }
@ -60,4 +75,5 @@ Controllers.home = function(req, res, next) {
}; };
module.exports = Controllers; module.exports = Controllers;
Loading…
Cancel
Save