Skip to content

Node.js based forum software built for the modern web

recent posts done (needs polish/cleanup), and fixed bug where new topic button was not showing up in categories

psychobunny4b67f8573e49
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;