Vulcan/server/publications/posts_list.js
Sacha Greif 50fc3eb11a Merge branch 'namespace' of https://github.com/TelescopeJS/Telescope into namespace
# Conflicts:
#	lib/users.js
#	packages/telescope-base/lib/base.js
#	packages/telescope-base/package.js
#	packages/telescope-lib
2015-04-20 13:57:37 +09:00

33 lines
1 KiB
JavaScript

// Publish a list of posts
Meteor.publish('postsList', function(terms) {
if(Users.can.viewById(this.userId)){
var parameters = Posts.getSubParams(terms),
posts = Posts.find(parameters.find, parameters.options);
return posts;
}
return [];
});
// Publish all the users that have posted the currently displayed list of posts
// plus the commenters for each post
Meteor.publish('postsListUsers', function(terms) {
if(Users.can.viewById(this.userId)){
var parameters = Posts.getSubParams(terms),
posts = Posts.find(parameters.find, parameters.options),
postsIds = _.pluck(posts.fetch(), '_id'),
userIds = _.pluck(posts.fetch(), 'userId');
// for each post, add first four commenter's userIds to userIds array
posts.forEach(function (post) {
userIds = userIds.concat(_.first(post.commenters,4));
});
userIds = _.unique(userIds);
return Meteor.users.find({_id: {$in: userIds}}, {fields: Users.pubsub.avatarOptions, multi: true});
}
return [];
});