2013-10-24 11:15:07 +09:00
|
|
|
var privacyOptions = { // false means private
|
2013-10-21 18:56:22 +08:00
|
|
|
secret_id: false,
|
|
|
|
isAdmin: false,
|
|
|
|
emails: false,
|
|
|
|
notifications: false,
|
|
|
|
'profile.email': false,
|
|
|
|
'services.twitter.accessToken': false,
|
|
|
|
'services.twitter.accessTokenSecret': false,
|
|
|
|
'services.twitter.id': false,
|
|
|
|
'services.password': false,
|
|
|
|
'services.resume': false
|
|
|
|
};
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// -------------------------------------------- Users -------------------------------------------- //
|
|
|
|
|
|
|
|
// Publish the current user
|
2013-07-04 12:51:26 +09:00
|
|
|
|
2012-10-18 14:24:36 +09:00
|
|
|
Meteor.publish('currentUser', function() {
|
2013-10-25 10:04:34 +09:00
|
|
|
var user = Meteor.users.find(this.userId);
|
|
|
|
return user;
|
2012-10-18 14:24:36 +09:00
|
|
|
});
|
2013-10-09 22:16:47 +09:00
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish a single user
|
|
|
|
|
2013-10-24 11:04:27 +09:00
|
|
|
Meteor.publish('singleUser', function(userIdOrSlug) {
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
var options = isAdminById(this.userId) ? {limit: 1} : {limit: 1, fields: privacyOptions};
|
|
|
|
var findById = Meteor.users.find(userIdOrSlug, options);
|
|
|
|
var findBySlug = Meteor.users.find({slug: userIdOrSlug}, options)
|
|
|
|
// if we find something when treating the argument as an ID, return that; else assume it's a slug
|
|
|
|
return findById.count() ? findById : findBySlug;
|
|
|
|
}
|
2013-10-09 22:16:47 +09:00
|
|
|
});
|
2013-10-21 18:56:22 +08:00
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish authors of the current post and its comments
|
2013-10-26 10:37:32 +09:00
|
|
|
|
2013-10-22 09:03:18 +08:00
|
|
|
Meteor.publish('postUsers', function(postId) {
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
// publish post author and post commenters
|
|
|
|
var post = Posts.findOne(postId);
|
|
|
|
var comments = Comments.find({post: post._id}).fetch();
|
|
|
|
// get IDs from all commenters on the post, plus post author's ID
|
|
|
|
var users = _.pluck(comments, "userId");
|
|
|
|
users.push(post.userId);
|
|
|
|
users = _.unique(users);
|
2013-10-26 10:37:32 +09:00
|
|
|
return Meteor.users.find({_id: {$in: users}}, {fields: privacyOptions});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish author of the current comment
|
2013-10-26 10:37:32 +09:00
|
|
|
|
|
|
|
Meteor.publish('commentUser', function(commentId) {
|
|
|
|
if(canViewById(this.userId)){
|
|
|
|
var comment = Comments.findOne(commentId);
|
|
|
|
return Meteor.users.find({_id: comment.userId}, {fields: privacyOptions});
|
2013-10-24 14:24:03 +09:00
|
|
|
}
|
2013-10-21 23:07:36 +08:00
|
|
|
});
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish all the users that have posted the currently displayed list of posts
|
|
|
|
|
|
|
|
Meteor.publish('postsListUsers', function(find, options) {
|
|
|
|
if(canViewById(this.userId)){
|
|
|
|
var posts = Posts.find(find, options);
|
|
|
|
var userIds = _.pluck(posts.fetch(), 'userId');
|
|
|
|
return Meteor.users.find({_id: {$in: userIds}}, {multi: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Publish all users
|
|
|
|
|
2013-10-25 09:54:40 +09:00
|
|
|
Meteor.publish('allUsers', function(limit) {
|
|
|
|
console.log(limit)
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
if (isAdminById(this.userId)) {
|
|
|
|
// if user is admin, publish all fields
|
2013-10-25 09:54:40 +09:00
|
|
|
return Meteor.users.find({}, {sort:{createdAt: -1}, limit: limit});
|
2013-10-24 14:24:03 +09:00
|
|
|
}else{
|
|
|
|
// else, filter out sensitive info
|
2013-10-25 09:54:40 +09:00
|
|
|
return Meteor.users.find({}, {sort:{createdAt: -1}, limit: limit, fields: userFieldsPrivacy});
|
2013-10-24 14:24:03 +09:00
|
|
|
}
|
2012-09-18 16:23:33 +09:00
|
|
|
}
|
2012-09-06 15:28:58 +09:00
|
|
|
});
|
2012-09-19 09:03:25 +09:00
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// -------------------------------------------- Posts -------------------------------------------- //
|
2013-10-25 11:23:16 +09:00
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish a single post
|
2012-08-22 23:24:33 -04:00
|
|
|
|
2013-04-06 14:27:01 +09:00
|
|
|
Meteor.publish('singlePost', function(id) {
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
return Posts.find(id);
|
|
|
|
}
|
2012-12-13 18:12:08 +11:00
|
|
|
});
|
2012-12-06 23:46:20 +11:00
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish the post related to the current comment
|
2013-10-26 10:47:13 +09:00
|
|
|
|
|
|
|
Meteor.publish('commentPost', function(commentId) {
|
|
|
|
if(canViewById(this.userId)){
|
|
|
|
var comment = Comments.findOne(commentId);
|
|
|
|
return Posts.find(comment.post);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish a list of posts
|
|
|
|
|
2013-10-24 20:30:05 +09:00
|
|
|
Meteor.publish('postsList', function(find, options) {
|
|
|
|
if(canViewById(this.userId)){
|
|
|
|
options = options || {};
|
|
|
|
var posts = Posts.find(find, options);
|
2013-10-24 22:22:49 +09:00
|
|
|
|
|
|
|
// console.log('//-------- Subscription Parameters:');
|
|
|
|
// console.log(find);
|
|
|
|
// console.log(options);
|
|
|
|
// console.log('Found '+posts.fetch().length+ ' posts:');
|
|
|
|
// posts.rewind();
|
|
|
|
// console.log(_.pluck(posts.fetch(), 'headline'));
|
|
|
|
// posts.rewind();
|
|
|
|
|
2013-10-24 20:30:05 +09:00
|
|
|
return posts;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-12-06 23:46:20 +11:00
|
|
|
|
2013-04-14 12:42:32 +10:00
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// -------------------------------------------- Comments -------------------------------------------- //
|
2012-08-22 23:24:33 -04:00
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish comments for a specific post
|
|
|
|
|
|
|
|
Meteor.publish('postComments', function(postId) {
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
return Comments.find({post: postId});
|
|
|
|
}
|
2012-08-22 23:24:33 -04:00
|
|
|
});
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish a single comment
|
|
|
|
|
2013-10-23 08:14:06 +08:00
|
|
|
Meteor.publish('singleComment', function(commentId) {
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
return Comments.find(commentId);
|
|
|
|
}
|
2013-10-23 08:14:06 +08:00
|
|
|
});
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// -------------------------------------------- Other -------------------------------------------- //
|
|
|
|
|
2013-10-24 14:24:03 +09:00
|
|
|
Meteor.publish('settings', function() {
|
2012-09-06 19:42:11 +09:00
|
|
|
return Settings.find();
|
2012-09-06 11:34:05 +09:00
|
|
|
});
|
|
|
|
|
2012-10-05 10:23:38 +09:00
|
|
|
Meteor.publish('notifications', function() {
|
2012-10-10 07:28:44 +09:00
|
|
|
// only publish notifications belonging to the current user
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
return Notifications.find({userId:this.userId});
|
|
|
|
}
|
2012-10-05 10:23:38 +09:00
|
|
|
});
|
|
|
|
|
2012-10-10 07:28:44 +09:00
|
|
|
Meteor.publish('categories', function() {
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
|
|
|
return Categories.find();
|
|
|
|
}
|
2012-09-06 11:34:05 +09:00
|
|
|
});
|