From c785f0636710dccb7c5546063ce77306499a7e83 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 23 May 2013 16:53:19 -0400 Subject: [PATCH 1/5] 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 Date: Thu, 23 May 2013 21:06:56 -0400 Subject: [PATCH 2/5] Updated README.md --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 40485cedae..e28a0681c3 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,25 @@ # NodeBB **NodeBB** is a robust nodejs driven forum built on a redis database. It is powered by web sockets, and is compatible down to IE8. +![NodeBB Screenshot](http://i.imgur.com/mxRmLAg.png) + +![NodeBB Login Page (with Social Logins)](http://i.imgur.com/q5tUUHW.png) + +## Requirements + +NodeBB requires a version of Node.js at least 0.8 or greater, and a Redis version 2.6 or greater. + ## Installation -NodeBB is powered by Node.js with a Redis database. They must be installed prior in order for NodeBB to work. `build-essential` exposes the build environment for `bcrypt` compilation. +First, we install our base software stack. `build-essential` is required as it exposes the build environment for `bcrypt` compilation, we won't be compiling anything manually. - # apt-get install nodejs redis-server npm build-essential + # apt-get install git nodejs redis-server npm build-essential + $ cd /path/to/nodebb/install/location + $ git clone git://github.com/designcreateplay/NodeBB.git nodebb Next, obtain all of the dependencies required by NodeBB: + $ cd nodebb $ npm install Now we ensure that the configuration files are properly set up. NodeBB runs on port 4567 by default. The client side config can be set up thusly: From 4b67f8573e49e5914f22036f42dd07d86fbd8203 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 23 May 2013 17:38:49 -0400 Subject: [PATCH 3/5] recent posts done (needs polish/cleanup), and fixed bug where new topic button was not showing up in categories --- src/categories.js | 28 +++++++++++++++++++++++----- src/topics.js | 3 +++ src/webserver.js | 7 +------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/categories.js b/src/categories.js index fe80f93e8d..a21e548640 100644 --- a/src/categories.js +++ b/src/categories.js @@ -79,7 +79,7 @@ var RDB = require('./redis.js'), var categoryData = { 'category_name' : category_name, - 'show_topic_button' : 'hidden', + 'show_topic_button' : 'show', 'category_id': category_id, 'active_users': active_users, 'topics' : [] @@ -118,6 +118,28 @@ var RDB = require('./redis.js'), }); } + // 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_topic_button' : 'hidden', + 'category_id': false, + 'topics' : [] + }; + + if (!tids.length) { + callback(latestTopics); + return; + } + + Categories.getTopicsByTids(tids, current_user, function(topicData) { + latestTopics.topics = topicData; + callback(latestTopics); + }); + }); + } + Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) { var title = [], @@ -182,10 +204,6 @@ var RDB = require('./redis.js'), // temporary. I don't think this call should belong here function getPrivileges(next) { - if (category_id == null) { - next(null, {view_deleted: false}); - } - Categories.privileges(category_id, current_user, function(user_privs) { next(null, user_privs); }); diff --git a/src/topics.js b/src/topics.js index c2c44fef3b..b46135ebfe 100644 --- a/src/topics.js +++ b/src/topics.js @@ -340,6 +340,9 @@ marked.setOptions({ // let everyone know that there is an unread topic in this category RDB.del('cid:' + category_id + ':read_by_uid'); + RDB.zadd('topics:recent', (new Date()).getTime(), tid); + //RDB.zadd('topics:active', tid); + // in future it may be possible to add topics to several categories, so leaving the door open here. RDB.sadd('categories:' + category_id + ':tid', tid); RDB.set('tid:' + tid + ':cid', category_id); diff --git a/src/webserver.js b/src/webserver.js index f1c734f112..d372e29413 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -183,17 +183,12 @@ var express = require('express'), }, req.params.id, (req.user) ? req.user.uid : 0); break; case 'latest' : - categories.get(function(data) { - if(!data) { - res.send(false); - return; - } + categories.getLatestTopics((req.user) ? req.user.uid : 0, 0, 9, function(data) { res.send(JSON.stringify(data)); }); break; case 'popular' : categories.get(function(data) { - console.log(data); if(!data) { res.send(false); return; From 43614a51976801f4144a644b5e7121653e344eb1 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 24 May 2013 07:52:15 -0400 Subject: [PATCH 4/5] fixed breaking issue on empty category --- src/categories.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/categories.js b/src/categories.js index a21e548640..f7e624a943 100644 --- a/src/categories.js +++ b/src/categories.js @@ -85,15 +85,6 @@ var RDB = require('./redis.js'), '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); @@ -106,12 +97,21 @@ var RDB = require('./redis.js'), }); } - 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); - }); + if (tids.length === 0) { + getModerators(function(err, moderators) { + categoryData.moderator_block_class = moderators.length > 0 ? '' : 'none'; + categoryData.moderators = moderators; + + 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); + }); + } }); From deaf8105cc1be50ba0385a7283c70d2d85580525 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 24 May 2013 08:34:13 -0400 Subject: [PATCH 5/5] renamed get category to get categories --- src/categories.js | 4 ++-- src/threadTools.js | 2 +- src/topics.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/categories.js b/src/categories.js index f7e624a943..3985a8ae2e 100644 --- a/src/categories.js +++ b/src/categories.js @@ -255,7 +255,7 @@ var RDB = require('./redis.js'), Categories.getAllCategories = function(callback, current_user) { RDB.lrange('categories:cid', 0, -1, function(err, cids) { RDB.handle(err); - Categories.get_category(cids, callback, current_user); + Categories.getCategories(cids, callback, current_user); }); } @@ -290,7 +290,7 @@ var RDB = require('./redis.js'), - Categories.get_category = function(cids, callback, current_user) { + Categories.getCategories = function(cids, callback, current_user) { var name = [], description = [], icon = [], diff --git a/src/threadTools.js b/src/threadTools.js index 06850a2b05..6886750dd0 100644 --- a/src/threadTools.js +++ b/src/threadTools.js @@ -141,7 +141,7 @@ var RDB = require('./redis.js'), RDB.smove('categories:' + oldCid + ':tid', 'categories:' + cid + ':tid', tid, function(err, result) { if (!err && result === 1) { RDB.set('tid:' + tid + ':cid', cid); - categories.get_category([cid], function(data) { + categories.getCategories([cid], function(data) { RDB.set('tid:' + tid + ':category_name', data.categories[0].name); RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug); }); diff --git a/src/topics.js b/src/topics.js index b46135ebfe..43dc651053 100644 --- a/src/topics.js +++ b/src/topics.js @@ -346,7 +346,7 @@ marked.setOptions({ // in future it may be possible to add topics to several categories, so leaving the door open here. RDB.sadd('categories:' + category_id + ':tid', tid); RDB.set('tid:' + tid + ':cid', category_id); - categories.get_category([category_id], function(data) { + categories.getCategories([category_id], function(data) { RDB.set('tid:' + tid + ':category_name', data.categories[0].name); RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug); });