var RDB = require('./redis.js'), posts = require('./posts.js'), utils = require('./../public/src/utils.js'), user = require('./user.js'), async = require('async'), topics = require('./topics.js'); (function(Categories) { Categories.getCategoryById = function(category_id, current_user, callback) { RDB.smembers('categories:' + category_id + ':tid', function(err, tids) { RDB.multi() .get('cid:' + category_id + ':name') .smembers('cid:' + category_id + ':active_users') .exec(function(err, replies) { category_name = replies[0]; active_usernames = replies[1]; if (category_name === null) { callback(false); } var active_users = []; for (var username in active_usernames) { active_users.push({'username': active_usernames[username]}); } var categoryData = { 'category_name' : category_name, 'show_sidebar' : 'show', 'show_topic_button': 'show', 'no_topics_message': 'hidden', 'topic_row_size': 'span9', 'category_id': category_id, 'active_users': active_users, 'topics' : [] }; function getTopics(next) { Categories.getTopicsByTids(tids, current_user, function(topics) { next(null, topics); }, category_id); } function getModerators(next) { Categories.getModerators(category_id, function(moderators) { next(null, moderators); }); } if (tids.length === 0) { getModerators(function(err, moderators) { categoryData.moderator_block_class = moderators.length > 0 ? '' : 'none'; categoryData.moderators = moderators; categoryData.show_sidebar = 'hidden'; categoryData.no_topics_message = 'show'; callback(categoryData); }); } else { async.parallel([getTopics, getModerators], function(err, results) { categoryData.topics = results[0]; categoryData.moderator_block_class = results[1].length > 0 ? '' : 'none'; categoryData.moderators = results[1]; callback(categoryData); }); } }); }); } // not the permanent location for this function Categories.getLatestTopics = function(current_user, start, end, callback) { RDB.zrange('topics:recent', 0, -1, function(err, tids) { var latestTopics = { 'category_name' : 'Recent', 'show_sidebar' : 'hidden', 'show_topic_button' : 'hidden', 'no_topics_message' : 'hidden', 'topic_row_size': 'span12', 'category_id': false, 'topics' : [] }; if (!tids.length) { callback(latestTopics); return; } Categories.getTopicsByTids(tids, current_user, function(topicData) { latestTopics.topics = topicData; callback(latestTopics); }); }); } // not the permanent location for this function Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) { var title = [], uid = [], timestamp = [], slug = [], postcount = [], locked = [], deleted = [], pinned = []; for (var i=0, ii=tids.length; i