Skip to content

Node.js based forum software built for the modern web

more work

Baris Usakli9dbaf9fef953
diff --git a/src/categories.js b/src/categories.js
index e4ba8ad55e..f938d2a0ae 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -115,111 +115,91 @@ var RDB = require('./redis.js'),
// not the permanent location for this function
Categories.getTopicsByTids = function(tids, current_user, callback, category_id /*temporary*/) {
- var title = [],
- uid = [],
- timestamp = [],
- lastposttime = [],
- slug = [],
- postcount = [],
- locked = [],
- deleted = [],
- pinned = [];
-
- for (var i=0, ii=tids.length; i<ii; i++) {
- title.push('tid:' + tids[i] + ':title');
- uid.push('tid:' + tids[i] + ':uid');
- timestamp.push('tid:' + tids[i] + ':timestamp');
- lastposttime.push('tid:' + tids[i] + ':lastposttime');
- slug.push('tid:' + tids[i] + ':slug');
- postcount.push('tid:' + tids[i] + ':postcount');
- locked.push('tid:' + tids[i] + ':locked');
- deleted.push('tid:' + tids[i] + ':deleted');
- pinned.push('tid:' + tids[i] + ':pinned');
+ var retrieved_topics = [];
+
+ function getTopicInfoMoar(topicData, callback) {
+
+ function getUserNames(next) {
+ user.getUserField(topicData.uid, 'username', function(username) {
+ next(null, username);
+ });
+ }
+
+ function hasReadTopics(next) {
+ topics.hasReadTopics([topicData.tid], current_user, function(hasRead) {
+ next(null, hasRead);
+ });
+ }
+
+ function getTeaserInfo(next) {
+ topics.get_teasers([topicData.tid], function(teasers) {
+ next(null, teasers);
+ });
+ }
+
+ // temporary. I don't think this call should belong here
+ function getPrivileges(next) {
+ Categories.privileges(category_id, current_user, function(user_privs) {
+ next(null, user_privs);
+ });
+ }
+
+ async.parallel([getUserNames, hasReadTopics, getTeaserInfo, getPrivileges], function(err, results) {
+ var username = results[0],
+ hasReadTopic = results[1],
+ teaserInfo = results[2],
+ privileges = results[3];
+
+ callback({
+ username: username,
+ hasReadTopic: 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)
+ });*/
+ //}
+
+
+
+ });
}
- RDB.multi()
- .mget(title)
- .mget(uid)
- .mget(timestamp)
- .mget(lastposttime)
- .mget(slug)
- .mget(postcount)
- .mget(locked)
- .mget(deleted)
- .mget(pinned)
- .exec(function(err, replies) {
- var retrieved_topics = [];
+ for(var i=0; i<tids.length; ++i) {
- title = replies[0];
- uid = replies[1];
- timestamp = replies[2];
- lastposttime = replies[3];
- slug = replies[4];
- postcount = replies[5];
- locked = replies[6];
- deleted = replies[7];
- pinned = replies[8];
-
- function getUserNames(next) {
- user.get_usernames_by_uids(uid, function(userNames) {
- next(null, userNames);
- });
- }
+ topics.getTopicData(tids[i], function(topicData) {
- function hasReadTopics(next) {
- topics.hasReadTopics(tids, current_user, function(hasRead) {
- next(null, hasRead);
- });
- }
+ getTopicInfoMoar(topicData, function(topicInfo) {
+ console.log(topicInfo);
- function getTeaserInfo(next) {
- topics.get_teasers(tids, function(teasers) {
- next(null, teasers);
- });
- }
+ topicData['pin-icon'] = topicData.pinned === '1' ? 'icon-pushpin' : 'none';
+ topicData['lock-icon'] = topicData.locked === '1' ? 'icon-lock' : 'none';
+ topicData['deleted-class'] = topicData.deleted === '1' ? 'deleted' : '';
- // temporary. I don't think this call should belong here
- function getPrivileges(next) {
- Categories.privileges(category_id, current_user, function(user_privs) {
- next(null, user_privs);
- });
- }
+ topicData.relativeTime = utils.relativeTime(topicData.timestamp);
- async.parallel([getUserNames, hasReadTopics, getTeaserInfo, getPrivileges], function(err, results) {
- var usernames = results[0],
- hasReadTopics = results[1],
- teaserInfo = results[2],
- privileges = results[3];
-
- for (var i=0, ii=tids.length; i<ii; i++) {
- if (!deleted[i] || (deleted[i] && privileges.view_deleted) || uid[i] === current_user) {
- retrieved_topics.push({
- 'tid' : tids[i],
- 'title' : title[i],
- 'uid' : uid[i],
- 'username': usernames[i],
- 'timestamp' : timestamp[i],
- 'lastposttime' : lastposttime[i],
- 'relativeTime': utils.relativeTime(timestamp[i]),
- 'slug' : slug[i],
- 'post_count' : postcount[i],
- 'lock-icon': locked[i] === '1' ? 'icon-lock' : 'none',
- 'deleted': deleted[i],
- 'deleted-class': deleted[i] ? 'deleted' : '',
- 'pinned': parseInt(pinned[i] || 0), // For sorting purposes
- 'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'none',
- '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)
- });
- }
- }
+ topicData.username = topicInfo.username;
+ topicData.badgeclass = (topicInfo.hasread && current_user != 0) ? '' : 'badge-important';
+ topicData.teaser_text = topicInfo.teaserInfo.text,
+ topicData.teaser_username = topicInfo.teaserInfo.username;
+ topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp);
+
+ retrieved_topics.push(topicData);
- callback(retrieved_topics);
+ if(retrieved_topics.length === tids.length)
+ callback(retrieved_topics);
});
});
+ }
+
}
Categories.getAllCategories = function(callback, current_user) {
diff --git a/src/posts.js b/src/posts.js
index ed850fc74f..832f10346a 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -103,6 +103,21 @@ marked.setOptions({
});
}
+ Posts.getPostFields = function(pid, fields, callback) {
+ RDB.hmget('post:' + pid, fields, function(err, data) {
+ if(err === null) {
+ var returnData = {};
+
+ for(var i=0, ii=fields.length; i<ii; ++i) {
+ returnData[fields[i]] = data[i];
+ }
+
+ callback(returnData);
+ }
+ else
+ console.log(err);
+ });
+ }
Posts.get_cid_by_pid = function(pid, callback) {
Posts.getPostField(pid, 'tid', function(tid) {
diff --git a/src/topics.js b/src/topics.js
index f32c2331aa..9175868169 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -303,11 +303,9 @@ marked.setOptions({
Topics.get_teaser = function(tid, callback) {
Topics.get_latest_undeleted_pid(tid, function(pid) {
if (pid !== null) {
- RDB.mget([
- 'pid:' + pid + ':content',
- 'pid:' + pid + ':uid',
- 'pid:' + pid + ':timestamp'
- ], function(err, content) {
+
+ posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(content) {
+
user.getUserField(content[1], 'username', function(username) {
var stripped = content[0],
timestamp = content[2];
diff --git a/src/user.js b/src/user.js
index b237b338d4..7a4ffb125c 100644
--- a/src/user.js
+++ b/src/user.js
@@ -11,7 +11,7 @@ var utils = require('./../public/src/utils.js'),
(function(User) {
User.getUserField = function(uid, field, callback) {
- RDB.hget('user:'+uid, field, function(err, data) {
+ RDB.hget('user:' + uid, field, function(err, data) {
if(err === null)
callback(data);
else
@@ -20,7 +20,7 @@ var utils = require('./../public/src/utils.js'),
}
User.getUserFields = function(uid, fields, callback) {
- RDB.hmget('user:'+uid, fields, function(err, data) {
+ RDB.hmget('user:' + uid, fields, function(err, data) {
if(err === null) {
var returnData = {};
diff --git a/src/webserver.js b/src/webserver.js
index 7b7bd52e24..e17cc40929 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -312,8 +312,13 @@ var express = require('express'),
/*posts.getPostsByUid(1, 0, 10, function(data) {
res.send(data);
});*/
- topics.getTopicById(1, 1, function(data) {
+
+ /*topics.getTopicById(1, 1, function(data) {
res.send(data);
+ });*/
+
+ categories.getCategoryById(12, 0, function(returnData) {
+ res.send(returnData);
});