updating topics.getTeaser and get_last_undeleted_pid to return err first, and handled methods that called it

v1.18.x
Julian Lam 12 years ago
parent 5819b43595
commit 31f8be8a0a

@ -132,8 +132,8 @@ var RDB = require('./redis.js'),
}
function getTeaserInfo(next) {
topics.getTeaser(topicData.tid, function(teaser) {
next(null, teaser);
topics.getTeaser(topicData.tid, function(err, teaser) {
next(null, teaser || {});
});
}
@ -178,10 +178,10 @@ var RDB = require('./redis.js'),
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_userpicture = topicInfo.teaserInfo.picture;
topicData.teaser_timestamp = utils.relativeTime(topicInfo.teaserInfo.timestamp);
topicData.teaser_text = topicInfo.teaserInfo.text || '',
topicData.teaser_username = topicInfo.teaserInfo.username || '';
topicData.teaser_userpicture = topicInfo.teaserInfo.picture || '';
topicData.teaser_timestamp = topicInfo.teaserInfo.timestamp ? utils.relativeTime(topicInfo.teaserInfo.timestamp) : '';
if (isTopicVisible(topicData, topicInfo))
retrieved_topics.push(topicData);

@ -243,10 +243,12 @@ var RDB = require('./redis.js'),
function(next) {
topics.getTopicField(tid, 'title', function(title) {
topics.getTeaser(tid, function(teaser) {
topics.getTeaser(tid, function(err, teaser) {
if (!err) {
notifications.create(teaser.username + ' has posted a reply to: "' + title + '"', null, '/topic/' + tid, 'topic:' + tid, function(nid) {
next(null, nid);
});
next(null, nid);
});
} else next(err);
});
});
@ -259,9 +261,8 @@ var RDB = require('./redis.js'),
});
}
], function(err, results) {
if (!err) {
notifications.push(results[0], results[1]);
}
if (!err) notifications.push(results[0], results[1]);
// Otherwise, do nothing
});
}

@ -153,7 +153,8 @@ marked.setOptions({
}
function getTeaser(next) {
Topics.getTeaser(tid, function(teaser) {
Topics.getTeaser(tid, function(err, teaser) {
if (err) teaser = {};
next(null, teaser);
});
}
@ -169,9 +170,9 @@ marked.setOptions({
topicData.relativeTime = utils.relativeTime(topicData.timestamp);
topicData.badgeclass = hasRead ? '' : 'badge-important';
topicData.teaser_text = teaser.text;
topicData.teaser_username = teaser.username;
topicData.teaser_timestamp = utils.relativeTime(teaser.timestamp);
topicData.teaser_text = teaser.text || '';
topicData.teaser_username = teaser.username || '';
topicData.teaser_timestamp = teaser.timestamp ? utils.relativeTime(teaser.timestamp) : '';
callback(topicData);
});
@ -262,23 +263,18 @@ marked.setOptions({
}
Topics.getTeasers = function(tids, callback) {
var requests = [];
var teasers = [];
if (Array.isArray(tids)) {
for(x=0,numTids=tids.length;x<numTids;x++) {
(function(tid) {
requests.push(function(next) {
Topics.getTeaser(tid, function(teaser_info) {
next(null, teaser_info);
});
});
})(tids[x]);
}
async.parallel(requests, function(err, teasers) {
async.each(tids, function(tid, next) {
Topics.getTeaser(tid, function(err, teaser_info) {
if (err) teaser_info = {};
teasers.push(teaser_info);
next();
});
}, function() {
callback(teasers);
});
} else {
callback([]);
}
} else callback(teasers);
}
@ -288,26 +284,23 @@ marked.setOptions({
var numPosts = posts.length;
if(!numPosts)
callback(null);
return callback(new Error('no-undeleted-pids-found'));
while(numPosts--) {
if(posts[numPosts].deleted !== '1') {
callback(posts[numPosts].pid);
callback(null, posts[numPosts].pid);
return;
}
}
if(posts.length > 0)
callback(posts[0].pid);
else
callback(null);
// If we got here, nothing was found...
callback(new Error('no-undeleted-pids-found'));
});
}
Topics.getTeaser = function(tid, callback) {
Topics.get_latest_undeleted_pid(tid, function(pid) {
console.log(pid);
if (pid !== null) {
Topics.get_latest_undeleted_pid(tid, function(err, pid) {
if (!err) {
posts.getPostFields(pid, ['content', 'uid', 'timestamp'], function(postData) {
user.getUserFields(postData.uid, ['username', 'picture'], function(userData) {
@ -317,7 +310,7 @@ marked.setOptions({
if(postData.content)
stripped = utils.strip_tags(marked(postData.content));
callback({
callback(null, {
"text": stripped,
"username": userData.username,
"picture": userData.picture,
@ -325,14 +318,7 @@ marked.setOptions({
});
});
});
} else {
callback({
"text": "",
"username": "",
"picture": "",
"timestamp" : ""
});
}
} else callback(new Error('no-teaser-found'));
});
}

Loading…
Cancel
Save