Skip to content

Node.js based forum software built for the modern web

more work:

Baris Soner Usaklifabb55426c94
diff --git a/public/templates/admin/topics.tpl b/public/templates/admin/topics.tpl
index 68d58e2c19..e0d0a79343 100644
--- a/public/templates/admin/topics.tpl
+++ b/public/templates/admin/topics.tpl
@@ -12,7 +12,7 @@
<a target="_blank" href="../../topic/{topics.slug}">{topics.title}</a>
<ul>
<li><i class="icon-time"></i> Posted {topics.relativeTime} ago by {topics.username}</li>
- <li><i class="icon-comments"></i> {topics.post_count} post(s)</li>
+ <li><i class="icon-comments"></i> {topics.postcount} post(s)</li>
</ul>
<div class="clear"></div>
</li>
diff --git a/public/templates/category.tpl b/public/templates/category.tpl
index 50d7d3864d..2f39054da0 100644
--- a/public/templates/category.tpl
+++ b/public/templates/category.tpl
@@ -30,7 +30,7 @@
</div>
</div>
<div>
- <h3><span class="topic-title"><span class="badge {topics.badgeclass}">{topics.post_count}</span>{topics.title}</span></h3>
+ <h3><span class="topic-title"><span class="badge {topics.badgeclass}">{topics.postcount}</span>{topics.title}</span></h3>
<small>
<strong><i class="{topics.pin-icon}"></i><i class="{topics.lock-icon}"></i></strong>
Posted {topics.relativeTime} ago by
diff --git a/public/templates/noscript/category.tpl b/public/templates/noscript/category.tpl
index 3aeb8ddc87..0d44ed3376 100644
--- a/public/templates/noscript/category.tpl
+++ b/public/templates/noscript/category.tpl
@@ -6,7 +6,7 @@
<ul class="topics">
<!-- BEGIN topics -->
<li>
- <a href="../../topic/{topics.slug}">{topics.title} ({topics.post_count})</a>
+ <a href="../../topic/{topics.slug}">{topics.title} ({topics.postcount})</a>
<div class="teaser">
<img class="img-polaroid" src="../../graph/users/{topics.teaser_username}/picture" />
<p>
diff --git a/public/templates/recent.tpl b/public/templates/recent.tpl
index 6cb0beb1ec..1c8fbf8af9 100644
--- a/public/templates/recent.tpl
+++ b/public/templates/recent.tpl
@@ -33,7 +33,7 @@
</div>
</div>
<div>
- <h3><span class="topic-title"><span class="badge {topics.badgeclass}">{topics.post_count}</span>{topics.title}</span></h3>
+ <h3><span class="topic-title"><span class="badge {topics.badgeclass}">{topics.postcount}</span>{topics.title}</span></h3>
<small>
<strong><i class="{topics.pin-icon}"></i><i class="{topics.lock-icon}"></i></strong>
Posted {topics.relativeTime} ago by
diff --git a/src/categories.js b/src/categories.js
index 2032a52c99..7e2d3a50fa 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -57,7 +57,7 @@ var RDB = require('./redis.js'),
}
function getActiveUsers(next) {
- user.getMultipleUserFields(active_users, ['username','userslug'], function(users) {
+ user.getMultipleUserFields(active_users, ['username', 'userslug'], function(users) {
var activeUserData = [];
for(var uid in users) {
activeUserData.push(users[uid]);
@@ -117,7 +117,7 @@ var RDB = require('./redis.js'),
Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) {
var retrieved_topics = [];
- function getTopicInfoMoar(topicData, callback) {
+ function getTopicInfo(topicData, callback) {
function getUserName(next) {
user.getUserField(topicData.uid, 'username', function(username) {
@@ -152,33 +152,20 @@ var RDB = require('./redis.js'),
callback({
username: username,
- hasReadTopic: hasReadTopic,
+ hasread: hasReadTopic,
teaserInfo: teaserInfo,
privileges: privileges
});
- //if (!deleted[i] || (deleted[i] && privileges.view_deleted) || uid[i] === current_user) {
- /*retrieved_topics.push({
-
- 'username': usernames[i],
- 'badgeclass' : (hasReadTopics[i] && current_user !=0) ? '' : 'badge-important',
- 'teaser_text': teaserInfo[i].text,
- 'teaser_username': teaserInfo[i].username,
- 'teaser_timestamp': utils.relativeTime(teaserInfo[i].timestamp)
- });*/
- //}
-
-
-
});
}
-
+
+ var topicCountToLoad = tids.length;
for(var i=0; i<tids.length; ++i) {
topics.getTopicData(tids[i], function(topicData) {
- getTopicInfoMoar(topicData, function(topicInfo) {
- console.log(topicInfo);
+ getTopicInfo(topicData, function(topicInfo) {
topicData['pin-icon'] = topicData.pinned === '1' ? 'icon-pushpin' : 'none';
topicData['lock-icon'] = topicData.locked === '1' ? 'icon-lock' : 'none';
@@ -192,9 +179,12 @@ var RDB = require('./redis.js'),
topicData.teaser_username = topicInfo.teaserInfo.username;
topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp);
- retrieved_topics.push(topicData);
+ if (!topicData.deleted || (topicData.deleted && topicInfo.privileges.view_deleted) || topicData.uid === current_user)
+ retrieved_topics.push(topicData);
+ else
+ --topicCountToLoad;
- if(retrieved_topics.length === tids.length)
+ if(retrieved_topics.length === topicsToLoad)
callback(retrieved_topics);
});
});
diff --git a/src/feed.js b/src/feed.js
index a13a391167..bb0c927fef 100644
--- a/src/feed.js
+++ b/src/feed.js
@@ -35,17 +35,8 @@
});
}
- function getPostsData(next) {
- posts.getPostsByTid(tid, -20, -1, function(postsData) {
- next(null, postsData);
- });
- }
-
-
async.parallel([getTopicData, getPostsData], function(err, results) {
var topicData = results[0],
- postsData = results[1].postData,
- userData = results[1].userData,
location = '/topic/' + topicData.slug,
xml_url = '/topic/' + tid + '.rss';
@@ -55,18 +46,20 @@
var feed = createFeed(topicData.topic_name, '', location, xml_url, post.username, urn);
var title;
- for (var i = 0, ii = postsData.pid.length; i < ii; i++) {
- urn = 'urn:' + cid + ':' + tid + ':' + postsData.pid[i];
- title = 'Reply to ' + topicData.topic_name + ' on ' + (new Date(parseInt(postsData.timestamp[i], 10)).toUTCString());
+ var topic_posts = topicData.main_posts.concat(topicData.posts);
+
+ for (var i = 0, ii = topic_posts.length; i < ii; i++) {
+ urn = 'urn:' + cid + ':' + tid + ':' + topic_posts[i].pid;
+ title = 'Reply to ' + topicData.topic_name + ' on ' + (new Date(parseInt(topic_posts[i].timestamp, 10)).toUTCString());
feed.addNewItem(
title,
location,
- postsData.timestamp[i],
- postsData.content[i],
+ topic_posts[i].timestamp,
+ topic_posts[i].content,
{
'urn' : urn,
- 'username' : userData[postsData.uid[i]].username
+ 'username' : topic_posts[i].username
}
);
}
diff --git a/src/posts.js b/src/posts.js
index 832f10346a..d20b086dce 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -122,7 +122,7 @@ marked.setOptions({
Posts.get_cid_by_pid = function(pid, callback) {
Posts.getPostField(pid, 'tid', function(tid) {
if (tid) {
- topics.get_cid_by_tid(tid, function(cid) {
+ topics.getTopicField(tid, 'cid', function(cid) {
if (cid) {
callback(cid);
} else {
@@ -255,7 +255,8 @@ marked.setOptions({
RDB.incr('totalpostcount');
- RDB.get('tid:' + tid + ':cid', function(err, cid) {
+ //RDB.get('tid:' + tid + ':cid', function(err, cid) {
+ topics.getTopicField(tid, 'cid', function(cid) {
RDB.handle(err);
feed.updateTopic(tid, cid);
diff --git a/src/threadTools.js b/src/threadTools.js
index c387b0bd2b..ebe75bd0f5 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -11,7 +11,7 @@ var RDB = require('./redis.js'),
//todo: break early if one condition is true
function getCategoryPrivileges(next) {
- topics.get_cid_by_tid(tid, function(cid) {
+ topics.getTopicField(tid, 'cid', function(cid) {
categories.privileges(cid, uid, function(privileges) {
next(null, privileges);
});
diff --git a/src/topics.js b/src/topics.js
index 57c5120a23..788b7386c3 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -108,37 +108,14 @@ marked.setOptions({
}
Topics.get_topic = function(tid, uid, callback) {
- var topicData = {};
function get_topic_data(next) {
- RDB.mget([
- schema.topics(tid).title,
- schema.topics(tid).uid,
- schema.topics(tid).timestamp,
- schema.topics(tid).slug,
- schema.topics(tid).postcount,
- schema.topics(tid).locked,
- schema.topics(tid).pinned,
- schema.topics(tid).deleted
- ], function(err, topic) {
- if (err) {
- throw new Error(err);
- }
-
- topicData.title = topic[0];
- topicData.uid = topic[1];
- topicData.timestamp = topic[2];
- topicData.relativeTime = utils.relativeTime(topic[2]),
- topicData.slug = topic[3];
- topicData.post_count = topic[4];
- topicData.locked = topic[5];
- topicData.pinned = topic[6];
- topicData.deleted = topic[7];
-
- user.getUserField(topic[1], 'username', function(username) {
- topicData.username = username;
-
- next();
+ Topics.getTopicData(tid, function(topic) {
+
+ user.getUserField(topic.uid, 'username', function(username) {
+
+ topic.username = username;
+ next(null, topic);
});
});
}
@@ -147,30 +124,30 @@ marked.setOptions({
// posts.create calls this function - should be an option to skip this because its always true
if (uid && parseInt(uid) > 0) {
RDB.sismember(schema.topics(tid).read_by_uid, uid, function(err, read) {
- topicData.badgeclass = read ? '' : 'badge-important';
-
- next();
+ next(null, read);
});
} else {
- next();
+ next(null, null);
}
}
function get_teaser(next) {
Topics.get_teaser(tid, function(teaser) {
- topicData.teaser_text = teaser.text;
- topicData.teaser_username = teaser.username;
-
- next();
+ next(null, teaser);
});
}
- async.parallel([get_topic_data, get_read_status, get_teaser], function(err) {
+ async.parallel([get_topic_data, get_read_status, get_teaser], function(err, results) {
if (err) {
throw new Error(err);
}
+
+ var topicData = results[0];
+ topicData.relativeTime = utils.relativeTime(results[0].timestamp);
+ topicData.badgeclass = results[1] ? '' : 'badge-important';
+ topicData.teaser_text = results[2].text;
+ topicData.teaser_username = results[2].username;
- topicData.tid = tid;
callback(topicData);
});
}
@@ -213,16 +190,6 @@ marked.setOptions({
});
}
- Topics.get_cid_by_tid = function(tid, callback) {
- RDB.get(schema.topics(tid).cid, function(err, cid) {
- if (cid && parseInt(cid) > 0) {
- callback(cid);
- } else {
- callback(false);
- }
- });
- }
-
Topics.getTitleByPid = function(pid, callback) {
posts.getPostField(pid, 'tid', function(tid) {
Topics.getTopicField(tid, 'title', function(title) {
@@ -235,7 +202,7 @@ marked.setOptions({
RDB.sadd(schema.topics(tid).read_by_uid, uid);
- Topics.get_cid_by_tid(tid, function(cid) {
+ Topics.getTopicField(tid, 'cid', function(cid) {
categories.isTopicsRead(cid, uid, function(read) {
if(read) {
@@ -390,6 +357,7 @@ marked.setOptions({
// Notify any users looking at the category that a new topic has arrived
Topics.get_topic(tid, uid, function(topicData) {
+
io.sockets.in('category_' + category_id).emit('event:new_topic', topicData);
io.sockets.in('recent_posts').emit('event:new_topic', topicData);
});
diff --git a/src/webserver.js b/src/webserver.js
index e17cc40929..ef6ef1f96c 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -301,9 +301,9 @@ var express = require('express'),
res.send(data);
});*/
- /*posts.getPostsByTid(1, 1, 0, 10, function(data) {
+ posts.getPostsByTid(2, 0, -1, function(data) {
res.send(data);
- });*/
+ });
/* posts.getPostsByPids([1,2,3], function(data) {
res.send(data);
@@ -317,10 +317,10 @@ var express = require('express'),
res.send(data);
});*/
- categories.getCategoryById(12, 0, function(returnData) {
+/* categories.getCategoryById(12, 0, function(returnData) {
res.send(returnData);
});
-
+*/
});