2014-09-04 16:39:35 +09:00
|
|
|
// Publish a single post
|
|
|
|
|
|
|
|
Meteor.publish('singlePost', function(id) {
|
2015-04-20 13:57:37 +09:00
|
|
|
if (Users.can.viewById(this.userId)){
|
2014-09-04 16:39:35 +09:00
|
|
|
return Posts.find(id);
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
2015-03-26 13:15:16 +09:00
|
|
|
// Publish author of the current post, authors of its comments, and upvoters of the post
|
2014-09-04 16:39:35 +09:00
|
|
|
|
|
|
|
Meteor.publish('postUsers', function(postId) {
|
2015-04-20 13:57:37 +09:00
|
|
|
if (Users.can.viewById(this.userId)){
|
2014-09-04 16:39:35 +09:00
|
|
|
// publish post author and post commenters
|
|
|
|
var post = Posts.findOne(postId),
|
2015-03-26 13:15:16 +09:00
|
|
|
users = [post.userId]; // publish post author's ID
|
2014-09-04 16:39:35 +09:00
|
|
|
|
2015-01-07 08:22:46 +01:00
|
|
|
if (post) {
|
2015-03-26 13:15:16 +09:00
|
|
|
|
|
|
|
// get IDs from all commenters on the post
|
2014-09-04 16:39:35 +09:00
|
|
|
var comments = Comments.find({postId: post._id}).fetch();
|
2015-03-26 13:15:16 +09:00
|
|
|
if (comments.length) {
|
|
|
|
users = users.concat(_.pluck(comments, "userId"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// publish upvoters
|
|
|
|
if (post.upvoters && post.upvoters.length) {
|
|
|
|
users = users.concat(post.upvoters);
|
|
|
|
}
|
|
|
|
|
|
|
|
// publish downvoters
|
|
|
|
if (post.downvoters && post.downvoters.length) {
|
|
|
|
users = users.concat(post.downvoters);
|
|
|
|
}
|
|
|
|
|
2014-09-04 16:39:35 +09:00
|
|
|
}
|
|
|
|
|
2015-03-26 13:15:16 +09:00
|
|
|
// remove any duplicate IDs
|
|
|
|
users = _.unique(users);
|
2015-04-20 13:57:37 +09:00
|
|
|
|
|
|
|
return Meteor.users.find({_id: {$in: users}}, {fields: Users.pubsub.privacyOptions});
|
2014-09-04 16:39:35 +09:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
});
|
|
|
|
|
|
|
|
// Publish comments for a specific post
|
|
|
|
|
|
|
|
Meteor.publish('postComments', function(postId) {
|
2015-04-20 13:57:37 +09:00
|
|
|
if (Users.can.viewById(this.userId)){
|
2015-03-27 15:37:11 -07:00
|
|
|
return Comments.find({postId: postId}, {sort: {score: -1, postedAt: -1}});
|
2014-09-04 16:39:35 +09:00
|
|
|
}
|
|
|
|
return [];
|
2015-04-20 13:57:37 +09:00
|
|
|
});
|