|
|
@ -424,12 +424,12 @@ var async = require('async'),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function getTopics(set, uid, tids, callback) {
|
|
|
|
function getTopics(set, uid, tids, callback) {
|
|
|
|
var latestTopics = {
|
|
|
|
var returnTopics = {
|
|
|
|
'topics': []
|
|
|
|
'topics': []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (!tids || !tids.length) {
|
|
|
|
if (!tids || !tids.length) {
|
|
|
|
return callback(null, latestTopics);
|
|
|
|
return callback(null, returnTopics);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async.filter(tids, function(tid, next) {
|
|
|
|
async.filter(tids, function(tid, next) {
|
|
|
@ -443,7 +443,7 @@ var async = require('async'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!topicData || !topicData.length) {
|
|
|
|
if(!topicData || !topicData.length) {
|
|
|
|
return callback(null, latestTopics);
|
|
|
|
return callback(null, returnTopics);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.sortedSetRevRank(set, topicData[topicData.length - 1].tid, function(err, rank) {
|
|
|
|
db.sortedSetRevRank(set, topicData[topicData.length - 1].tid, function(err, rank) {
|
|
|
@ -451,9 +451,9 @@ var async = require('async'),
|
|
|
|
return calllback(err);
|
|
|
|
return calllback(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
latestTopics.nextStart = parseInt(rank, 10) + 1;
|
|
|
|
returnTopics.nextStart = parseInt(rank, 10) + 1;
|
|
|
|
latestTopics.topics = topicData;
|
|
|
|
returnTopics.topics = topicData;
|
|
|
|
callback(null, latestTopics);
|
|
|
|
callback(null, returnTopics);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -905,49 +905,11 @@ var async = require('async'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Topics.getAllTopics = function(limit, after, callback) {
|
|
|
|
Topics.getAllTopics = function(start, end, callback) {
|
|
|
|
db.getSetMembers('topics:tid', function(err, tids) {
|
|
|
|
db.getSortedSetRevRange('topics:recent', start, end, function(err, tids) {
|
|
|
|
if(err) {
|
|
|
|
async.map(tids, function(tid, next) {
|
|
|
|
return callback(err, null);
|
|
|
|
Topics.getTopicDataWithUser(tid, next);
|
|
|
|
}
|
|
|
|
}, callback);
|
|
|
|
|
|
|
|
|
|
|
|
var topics = [],
|
|
|
|
|
|
|
|
numTids, x;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sort into ascending order
|
|
|
|
|
|
|
|
tids.sort(function(a, b) {
|
|
|
|
|
|
|
|
return a - b;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Eliminate everything after the "after" tid
|
|
|
|
|
|
|
|
if (after) {
|
|
|
|
|
|
|
|
for (x = 0, numTids = tids.length; x < numTids; x++) {
|
|
|
|
|
|
|
|
if (tids[x] >= after) {
|
|
|
|
|
|
|
|
tids = tids.slice(0, x);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (limit) {
|
|
|
|
|
|
|
|
if (limit > 0 && limit < tids.length) {
|
|
|
|
|
|
|
|
tids = tids.slice(tids.length - limit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sort into descending order
|
|
|
|
|
|
|
|
tids.sort(function(a, b) {
|
|
|
|
|
|
|
|
return b - a;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.each(tids, function(tid, next) {
|
|
|
|
|
|
|
|
Topics.getTopicDataWithUser(tid, function(err, topicData) {
|
|
|
|
|
|
|
|
topics.push(topicData);
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, function(err) {
|
|
|
|
|
|
|
|
callback(err, topics);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|