2014-09-03 09:56:38 +09:00
|
|
|
// Publish a list of posts
|
|
|
|
|
|
|
|
Meteor.publish('postsList', function(terms) {
|
|
|
|
if(canViewById(this.userId)){
|
2014-09-29 15:42:35 +08:00
|
|
|
var parameters = getPostsParameters(terms),
|
2014-09-03 09:56:38 +09:00
|
|
|
posts = Posts.find(parameters.find, parameters.options);
|
2014-09-08 17:39:59 +09:00
|
|
|
|
2014-09-03 09:56:38 +09:00
|
|
|
// console.log('//-------- Subscription Parameters:');
|
|
|
|
// console.log(parameters.find);
|
|
|
|
// console.log(parameters.options);
|
|
|
|
// console.log('Found '+posts.fetch().length+ ' posts:');
|
|
|
|
// posts.rewind();
|
|
|
|
// console.log(_.pluck(posts.fetch(), 'title'));
|
|
|
|
return posts;
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
// Publish all the users that have posted the currently displayed list of posts
|
2014-12-14 15:15:34 +09:00
|
|
|
// plus the commenters for each post
|
2014-09-03 09:56:38 +09:00
|
|
|
|
|
|
|
Meteor.publish('postsListUsers', function(terms) {
|
|
|
|
if(canViewById(this.userId)){
|
2014-09-29 15:42:35 +08:00
|
|
|
var parameters = getPostsParameters(terms),
|
2014-09-03 09:56:38 +09:00
|
|
|
posts = Posts.find(parameters.find, parameters.options),
|
2014-12-14 15:15:34 +09:00
|
|
|
postsIds = _.pluck(posts.fetch(), '_id'),
|
2014-12-17 11:25:40 +09:00
|
|
|
userIds = _.pluck(posts.fetch(), 'userId');
|
2014-12-14 15:15:34 +09:00
|
|
|
|
2014-12-17 11:42:08 +09:00
|
|
|
// for each post, add first four commenter's userIds to userIds array
|
2014-12-17 11:25:40 +09:00
|
|
|
posts.forEach(function (post) {
|
2014-12-17 11:42:08 +09:00
|
|
|
userIds = userIds.concat(_.first(post.commenters,4));
|
2014-12-17 11:25:40 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
userIds = _.unique(userIds);
|
2014-12-17 11:42:08 +09:00
|
|
|
|
2014-12-14 15:15:34 +09:00
|
|
|
return Meteor.users.find({_id: {$in: userIds}}, {fields: avatarOptions, multi: true});
|
2014-09-03 09:56:38 +09:00
|
|
|
}
|
|
|
|
return [];
|
2014-09-29 15:42:35 +08:00
|
|
|
});
|