2014-12-08 17:25:11 +09:00
|
|
|
// accept either an ID or a slug
|
|
|
|
Meteor.publish('singleUser', function(idOrSlug) {
|
|
|
|
var findById = Meteor.users.findOne(idOrSlug);
|
|
|
|
var findBySlug = Meteor.users.findOne({slug: idOrSlug});
|
|
|
|
var user = typeof findById !== 'undefined' ? findById : findBySlug;
|
|
|
|
var options = isAdminById(this.userId) ? {} : {fields: privacyOptions};
|
|
|
|
return Meteor.users.find({_id: user._id}, options);
|
|
|
|
});
|
|
|
|
|
|
|
|
Meteor.publish('userPosts', function(terms) {
|
|
|
|
var parameters = getPostsParameters(terms);
|
|
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
|
|
|
return posts;
|
|
|
|
});
|
|
|
|
|
|
|
|
Meteor.publish('userUpvotedPosts', function(terms) {
|
|
|
|
var parameters = getPostsParameters(terms);
|
|
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
|
|
|
return posts;
|
|
|
|
});
|
2014-09-03 09:56:38 +09:00
|
|
|
|
2014-12-08 17:25:11 +09:00
|
|
|
Meteor.publish('userDownvotedPosts', function(terms) {
|
|
|
|
var parameters = getPostsParameters(terms);
|
|
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
|
|
|
return posts;
|
2014-12-08 14:53:26 +09:00
|
|
|
});
|
|
|
|
|
2014-12-08 15:26:06 +09:00
|
|
|
Meteor.publish('userComments', function(userId, limit) {
|
|
|
|
var comments = Comments.find({userId: userId}, {limit: limit});
|
|
|
|
// if there are comments, find out which posts were commented on
|
|
|
|
var commentedPostIds = comments.count() ? _.pluck(comments.fetch(), 'postId') : [];
|
|
|
|
return [
|
|
|
|
comments,
|
|
|
|
Posts.find({_id: {$in: commentedPostIds}})
|
|
|
|
]
|
|
|
|
});
|