From c785f0636710dccb7c5546063ce77306499a7e83 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 23 May 2013 16:53:19 -0400 Subject: [PATCH] added 404 tpl, fix for 404 on topics, continuing refactor - categories --- public/templates/404.tpl | 4 + src/categories.js | 277 +++++++++++++++++++++------------------ src/topics.js | 5 + src/webserver.js | 2 +- 4 files changed, 159 insertions(+), 129 deletions(-) create mode 100644 public/templates/404.tpl diff --git a/public/templates/404.tpl b/public/templates/404.tpl new file mode 100644 index 0000000000..f3a998992e --- /dev/null +++ b/public/templates/404.tpl @@ -0,0 +1,4 @@ +
+ Not found +

You seem to have stumbled upon a page that does not exist. Return to the home page

+
\ No newline at end of file diff --git a/src/categories.js b/src/categories.js index c2c6d06d4d..fe80f93e8d 100644 --- a/src/categories.js +++ b/src/categories.js @@ -60,104 +60,162 @@ var RDB = require('./redis.js'), Categories.get = function(callback, category_id, current_user) { - var range_var = (category_id) ? 'categories:' + category_id + ':tid' : 'topics:tid'; - - RDB.smembers(range_var, function(err, tids) { - var title = [], - uid = [], - timestamp = [], - slug = [], - postcount = [], - locked = [], - deleted = [], - pinned = []; - - for (var i=0, ii=tids.length; i 0) { - multi - .mget(title) - .mget(uid) - .mget(timestamp) - .mget(slug) - .mget(postcount) - .mget(locked) - .mget(deleted) - .mget(pinned) - } + .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_topic_button' : 'hidden', + 'category_id': category_id, + 'active_users': active_users, + 'topics' : [] + }; + + if (tids.length === 0) { + getModerators(function(err, moderators) { + categoryData.moderator_block_class = moderators.length > 0 ? '' : 'none'; + categoryData.moderators = moderators; + + callback(categoryData); + }); + } + + 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); + }); + } + + 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); + }); + + + }); + }); + } + + + 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 0) { - for (var i=0, ii=title.length; i 0 ? '' : 'none', - 'moderators': moderators - }); - } - - user.get_usernames_by_uids(uid, function(userNames) { - usernames = userNames; - generate_topic(); - }); - - topics.hasReadTopics(tids, current_user, function(hasRead) { - has_read = hasRead; - generate_topic(); - }); - - Categories.getModerators(category_id, function(mods) { - moderators = mods; - generate_topic(); - }); - - topics.get_teasers(tids, function(teasers) { - teaser_info = teasers; - generate_topic(); - }); - - Categories.privileges(category_id, current_user, function(user_privs) { - privileges = user_privs; + callback(retrieved_topics); }); }); - }); } Categories.getAllCategories = function(callback, current_user) { diff --git a/src/topics.js b/src/topics.js index 2cb0382105..c2c44fef3b 100644 --- a/src/topics.js +++ b/src/topics.js @@ -58,6 +58,11 @@ marked.setOptions({ voteData = results[1].voteData, privileges = results[2]; + if (!postData) { + callback(false); + return; + } + for (var i=0, ii= postData.pid.length; i