diff --git a/src/categories.js b/src/categories.js index a1b3dd30a7..a88c79a1d2 100644 --- a/src/categories.js +++ b/src/categories.js @@ -182,14 +182,16 @@ var RDB = require('./redis.js'), topicData.teaser_username = topicInfo.teaserInfo.username; topicData.teaser_userpicture = topicInfo.teaserInfo.picture; topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp); - + if (isTopicVisible(topicData, topicInfo)) retrieved_topics.push(topicData); else --topicCountToLoad; - if(retrieved_topics.length === topicCountToLoad) + if(retrieved_topics.length === topicCountToLoad) { + console.log('derp'); callback(retrieved_topics); + } }); }); } diff --git a/src/topics.js b/src/topics.js index f4a88349ca..760c12e609 100644 --- a/src/topics.js +++ b/src/topics.js @@ -293,14 +293,19 @@ marked.setOptions({ while(numPosts--) { if(posts[numPosts].deleted !== '1') { callback(posts[numPosts].pid); - break; + return; } - } + } + if(posts.length > 0) + callback(posts[0].pid); + else + callback(null); }); } Topics.getTeaser = function(tid, callback) { Topics.get_latest_undeleted_pid(tid, function(pid) { + console.log(pid); if (pid !== null) { posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(postData) { @@ -320,6 +325,13 @@ marked.setOptions({ }); }); }); + } else { + callback({ + "text": "", + "username": "", + "picture": "", + "timestamp" : "" + }); } }); }