|
|
@ -20,7 +20,10 @@ var RDB = require('./redis.js'),
|
|
|
|
|
|
|
|
|
|
|
|
Topics.getTopicData = function(tid, callback) {
|
|
|
|
Topics.getTopicData = function(tid, callback) {
|
|
|
|
RDB.hgetall('topic:' + tid, function(err, data) {
|
|
|
|
RDB.hgetall('topic:' + tid, function(err, data) {
|
|
|
|
if (err === null) {
|
|
|
|
if(err) {
|
|
|
|
|
|
|
|
return callback(err, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(data) {
|
|
|
|
if(data) {
|
|
|
|
data.title = validator.sanitize(data.title).escape();
|
|
|
|
data.title = validator.sanitize(data.title).escape();
|
|
|
|
if(data.timestamp) {
|
|
|
|
if(data.timestamp) {
|
|
|
@ -28,20 +31,25 @@ var RDB = require('./redis.js'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
callback(data);
|
|
|
|
callback(null, data);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.log(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Topics.getTopicDataWithUser = function(tid, callback) {
|
|
|
|
Topics.getTopicDataWithUser = function(tid, callback) {
|
|
|
|
Topics.getTopicData(tid, function(topic) {
|
|
|
|
Topics.getTopicData(tid, function(err, topic) {
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
|
|
|
|
return callback(err, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
user.getUserFields(topic.uid, ['username', 'userslug', 'picture'] , function(err, userData) {
|
|
|
|
user.getUserFields(topic.uid, ['username', 'userslug', 'picture'] , function(err, userData) {
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
|
|
|
|
return callback(err, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
topic.username = userData.username;
|
|
|
|
topic.username = userData.username;
|
|
|
|
topic.userslug = userData.userslug
|
|
|
|
topic.userslug = userData.userslug
|
|
|
|
topic.picture = userData.picture;
|
|
|
|
topic.picture = userData.picture;
|
|
|
|
callback(topic);
|
|
|
|
callback(null, topic);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -331,7 +339,7 @@ var RDB = require('./redis.js'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loadTopic(tid, callback) {
|
|
|
|
function loadTopic(tid, callback) {
|
|
|
|
Topics.getTopicData(tid, function(topicData) {
|
|
|
|
Topics.getTopicData(tid, function(err, topicData) {
|
|
|
|
if (!topicData) {
|
|
|
|
if (!topicData) {
|
|
|
|
return callback(null);
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -381,9 +389,7 @@ var RDB = require('./redis.js'),
|
|
|
|
Topics.increaseViewCount(tid);
|
|
|
|
Topics.increaseViewCount(tid);
|
|
|
|
|
|
|
|
|
|
|
|
function getTopicData(next) {
|
|
|
|
function getTopicData(next) {
|
|
|
|
Topics.getTopicData(tid, function(topicData) {
|
|
|
|
Topics.getTopicData(tid, next);
|
|
|
|
next(null, topicData);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getTopicPosts(next) {
|
|
|
|
function getTopicPosts(next) {
|
|
|
@ -442,9 +448,7 @@ var RDB = require('./redis.js'),
|
|
|
|
Topics.getTopicForCategoryView = function(tid, uid, callback) {
|
|
|
|
Topics.getTopicForCategoryView = function(tid, uid, callback) {
|
|
|
|
|
|
|
|
|
|
|
|
function getTopicData(next) {
|
|
|
|
function getTopicData(next) {
|
|
|
|
Topics.getTopicDataWithUser(tid, function(topic) {
|
|
|
|
Topics.getTopicDataWithUser(tid, next);
|
|
|
|
next(null, topic);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getReadStatus(next) {
|
|
|
|
function getReadStatus(next) {
|
|
|
@ -517,7 +521,7 @@ var RDB = require('./redis.js'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
async.each(tids, function(tid, next) {
|
|
|
|
async.each(tids, function(tid, next) {
|
|
|
|
Topics.getTopicDataWithUser(tid, function(topicData) {
|
|
|
|
Topics.getTopicDataWithUser(tid, function(err, topicData) {
|
|
|
|
topics.push(topicData);
|
|
|
|
topics.push(topicData);
|
|
|
|
next();
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
});
|
|
|
|