Skip to content

Instantly share code, notes, and snippets.

@freshlogic
Created June 24, 2015 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freshlogic/358072623d0ead85e5c8 to your computer and use it in GitHub Desktop.
Save freshlogic/358072623d0ead85e5c8 to your computer and use it in GitHub Desktop.
Sidebar
exports.fetchUserTopics = function(date, callback) {
var startDate = moment(date).tz('America/New_York').startOf('day');
pettyCache.fetch('meh-user-topics-' + startDate.format('YYYMMDD'), function(callback) {
async.auto({
dateCreated: function(callback) {
sdk.forum.topics.list({ limit: 100, site: 'meh.com', sort: '-createdAt' }, {}, callback);
},
votesToday: function(callback) {
var endDate = moment(startDate).add(1, 'day');
sdk.forum.topics.list({ lastVoteAfter: startDate.valueOf(), lastVoteBefore: endDate.valueOf(), limit: 100, site: 'meh.com', sort: '-votesToday.for' }, {}, callback);
}
}, function(err, results) {
if (err) {
return callback(err);
}
var topics = results.votesToday;
results.dateCreated.forEach(function(t) {
if (!topics.some(function(topic) { return topic.id == t.id; })) {
topics.push(t);
}
});
var categoryBlacklist = ['deals', 'polls', 'videos'];
// Remove any topics with content categories
topics = topics.filter(function(t) { return categoryBlacklist.indexOf(t.category) === -1; });
// Only take 7
topics = topics.slice(0, 7);
callback(null, topics);
});
}, callback);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment