Skip to content

Instantly share code, notes, and snippets.

@barisusakli
Last active August 29, 2015 14:14
Show Gist options
  • Save barisusakli/4428158ffc19b5d4dfa4 to your computer and use it in GitHub Desktop.
Save barisusakli/4428158ffc19b5d4dfa4 to your computer and use it in GitHub Desktop.
add main post content to all topic lists
//use filter:topics.get in plugin.json
//{ "hook": "filter:topics.get", "method": "addMainPostContent"}
module.addMainPostContent = function(data, callback) {
var topics = data.topics;
var keys = topics.map(function(topic) {
return topic && 'topic:' + topic.tid;
});
db.getObjectsFields(keys, ['mainPid'], function(err, mainPids) {
if (err) {
return callback(err);
}
mainPids = mainPids.map(function(topic) {
return topic && topic.mainPid;
});
posts.getPostSummaryByPids(mainPids, data.uid, {stripTags: true}, function(err, posts) {
if (err) {
return callback(err);
}
for (var i=0; i<topics.length; ++i) {
if (topics[i]) {
topics[i].mainPost = posts[i];
}
}
callback(null, data);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment