mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 18:11:40 -05:00
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
// 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;
|
|
});
|
|
|
|
Meteor.publish('userDownvotedPosts', function(terms) {
|
|
var parameters = getPostsParameters(terms);
|
|
var posts = Posts.find(parameters.find, parameters.options);
|
|
return posts;
|
|
});
|
|
|
|
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}})
|
|
]
|
|
});
|