|
|
|
@ -9,7 +9,13 @@ module.exports = function (Topics) {
|
|
|
|
|
count = parseInt(count, 10) || 20;
|
|
|
|
|
|
|
|
|
|
if (term === 'alltime') {
|
|
|
|
|
return getAllTimePopular(uid, count, callback);
|
|
|
|
|
return getAllTimePopular(uid, count, function (err, topics) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sortTiedTopicsByViews(topics, callback);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
@ -19,6 +25,9 @@ module.exports = function (Topics) {
|
|
|
|
|
function (tids, next) {
|
|
|
|
|
getTopics(tids, uid, count, next);
|
|
|
|
|
},
|
|
|
|
|
function (topics, next) {
|
|
|
|
|
sortTiedTopicsByViews(topics, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -48,4 +57,12 @@ module.exports = function (Topics) {
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sortTiedTopicsByViews(topics, next) {
|
|
|
|
|
topics.sort(function (a, b) {
|
|
|
|
|
return parseInt(a.postcount) !== parseInt(b.postcount) ? 0 : parseInt(b.viewcount, 10) - parseInt(a.viewcount, 10);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
next(null, topics);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|