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,
|
2013-11-14 10:49:37 +09:00
|
|
|
inviteCount: false,
|
2013-10-21 18:56:22 +08:00
|
|
|
'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() {
|
2014-02-18 14:46:53 +09:00
|
|
|
var user = Meteor.users.find({_id: this.userId});
|
2013-10-25 10:04:34 +09:00
|
|
|
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);
|
2014-05-06 20:15:48 -07:00
|
|
|
var findBySlug = Meteor.users.find({slug: userIdOrSlug}, options);
|
2013-10-24 14:24:03 +09:00
|
|
|
// 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-11-15 11:50:57 +09:00
|
|
|
return [];
|
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
|
2013-11-11 21:35:38 +02:00
|
|
|
var post = Posts.findOne(postId),
|
|
|
|
users = [];
|
|
|
|
|
|
|
|
if(post) {
|
2014-06-22 10:34:39 +09:00
|
|
|
var comments = Comments.find({postId: post._id}).fetch();
|
2013-11-11 21:35:38 +02:00
|
|
|
// get IDs from all commenters on the post, plus post author's ID
|
|
|
|
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-11-15 11:50:57 +09:00
|
|
|
return [];
|
2013-10-26 10:37:32 +09:00
|
|
|
});
|
|
|
|
|
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);
|
2013-11-11 21:35:38 +02:00
|
|
|
return Meteor.users.find({_id: comment && comment.userId}, {fields: privacyOptions});
|
2013-10-24 14:24:03 +09:00
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
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
|
|
|
|
|
2013-11-17 08:01:56 +09:00
|
|
|
Meteor.publish('postsListUsers', function(terms) {
|
2013-10-26 10:50:49 +09:00
|
|
|
if(canViewById(this.userId)){
|
2013-11-17 08:01:56 +09:00
|
|
|
var parameters = getParameters(terms),
|
|
|
|
posts = Posts.find(parameters.find, parameters.options),
|
|
|
|
userIds = _.pluck(posts.fetch(), 'userId');
|
2013-11-06 09:29:10 +09:00
|
|
|
return Meteor.users.find({_id: {$in: userIds}}, {fields: privacyOptions, multi: true});
|
2013-10-26 10:50:49 +09:00
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
2013-10-26 10:50:49 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// Publish all users
|
|
|
|
|
2013-11-17 08:01:56 +09:00
|
|
|
Meteor.publish('allUsers', function(filterBy, sortBy, limit) {
|
2013-10-24 14:24:03 +09:00
|
|
|
if(canViewById(this.userId)){
|
2013-11-17 08:01:56 +09:00
|
|
|
var parameters = getUsersParameters(filterBy, sortBy, limit);
|
2013-11-04 22:05:19 +09:00
|
|
|
if (!isAdminById(this.userId)) // if user is not admin, filter out sensitive info
|
2013-11-17 08:01:56 +09:00
|
|
|
parameters.options = _.extend(parameters.options, {fields: privacyOptions});
|
|
|
|
return Meteor.users.find(parameters.find, parameters.options);
|
2012-09-18 16:23:33 +09:00
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
2012-09-06 15:28:58 +09:00
|
|
|
});
|
2012-09-19 09:03:25 +09:00
|
|
|
|
2013-11-08 11:38:57 +09:00
|
|
|
// publish all users for admins to make autocomplete work
|
|
|
|
// TODO: find a better way
|
|
|
|
|
|
|
|
Meteor.publish('allUsersAdmin', function() {
|
2014-07-03 10:28:27 +09:00
|
|
|
var selector = getSetting('requirePostInvite') ? {isInvited: true} : {};
|
2013-11-11 16:25:47 -05:00
|
|
|
if (isAdminById(this.userId)) {
|
2014-07-03 10:28:27 +09:00
|
|
|
return Meteor.users.find(selector);
|
2013-11-11 16:25:47 -05:00
|
|
|
} else {
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
2013-11-11 16:25:47 -05:00
|
|
|
}
|
2013-11-08 11:38:57 +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);
|
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
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);
|
2014-07-05 16:21:28 +09:00
|
|
|
return Posts.find({_id: comment && comment.postId});
|
2013-10-26 10:47:13 +09:00
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
2013-10-26 10:47:13 +09:00
|
|
|
});
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// Publish a list of posts
|
|
|
|
|
2013-11-17 08:01:56 +09:00
|
|
|
Meteor.publish('postsList', function(terms) {
|
2013-10-24 20:30:05 +09:00
|
|
|
if(canViewById(this.userId)){
|
2013-11-17 08:01:56 +09:00
|
|
|
var parameters = getParameters(terms),
|
|
|
|
posts = Posts.find(parameters.find, parameters.options);
|
2013-10-24 22:22:49 +09:00
|
|
|
// console.log('//-------- Subscription Parameters:');
|
2013-11-17 08:01:56 +09:00
|
|
|
// console.log(parameters.find);
|
|
|
|
// console.log(parameters.options);
|
2013-10-24 22:22:49 +09:00
|
|
|
// console.log('Found '+posts.fetch().length+ ' posts:');
|
|
|
|
// posts.rewind();
|
2014-05-16 09:19:35 +09:00
|
|
|
// console.log(_.pluck(posts.fetch(), 'title'));
|
2013-10-24 20:30:05 +09:00
|
|
|
return posts;
|
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
2013-10-24 20:30:05 +09: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)){
|
2014-06-22 10:34:39 +09:00
|
|
|
return Comments.find({postId: postId});
|
2013-10-24 14:24:03 +09:00
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
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-11-15 11:50:57 +09:00
|
|
|
return [];
|
2013-10-23 08:14:06 +08:00
|
|
|
});
|
|
|
|
|
2013-10-26 10:50:49 +09:00
|
|
|
// -------------------------------------------- Other -------------------------------------------- //
|
|
|
|
|
2013-11-17 10:28:08 +09:00
|
|
|
Meteor.publish('settings', function() {
|
|
|
|
var options = {};
|
|
|
|
if(!isAdminById(this.userId)){
|
|
|
|
options = _.extend(options, {
|
|
|
|
fields: {
|
|
|
|
mailChimpAPIKey: false,
|
|
|
|
mailChimpListId: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Settings.find({}, options);
|
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});
|
|
|
|
}
|
2013-11-15 11:50:57 +09:00
|
|
|
return [];
|
2012-10-05 10:23:38 +09:00
|
|
|
});
|
|
|
|
|