Last active
August 29, 2015 14:14
-
-
Save barisusakli/4428158ffc19b5d4dfa4 to your computer and use it in GitHub Desktop.
add main post content to all topic lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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