Vulcan/packages/telescope-comments/lib/server/publications.js

90 lines
2.3 KiB
JavaScript
Raw Normal View History

2015-08-13 11:32:41 +09:00
Comments._ensureIndex({postId: 1});
Comments._ensureIndex({parentCommentId: 1});
// Publish a list of comments
2016-02-16 16:12:13 +09:00
Meteor.publish('comments.list', function(terms) {
2016-01-02 18:40:49 +01:00
this.unblock();
if (this.userId) { // add currentUserId to terms if a user is logged in
terms.currentUserId = this.userId;
}
if(Users.can.viewById(this.userId)){
var parameters = Comments.parameters.get(terms);
var comments = Comments.find(parameters.find, parameters.options);
// 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}})
];
}
});
2016-02-16 16:12:13 +09:00
// // Publish a single comment
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// Meteor.publish('singleCommentAndChildren', function(commentId) {
2016-02-16 16:12:13 +09:00
// check(commentId, String);
2016-02-16 16:12:13 +09:00
// this.unblock();
2016-01-02 18:40:49 +01:00
2016-02-16 16:12:13 +09:00
// if(Users.can.viewById(this.userId)){
// // publish both current comment and child comments
// var commentIds = [commentId];
// var childCommentIds = _.pluck(Comments.find({parentCommentId: commentId}, {fields: {_id: 1}}).fetch(), '_id');
// commentIds = commentIds.concat(childCommentIds);
// return Comments.find({_id: {$in: commentIds}}, {sort: {score: -1, postedAt: -1}});
// }
// return [];
// });
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// // Publish the post related to the current comment
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// Meteor.publish('commentPost', function(commentId) {
2016-02-16 16:12:13 +09:00
// check(commentId, String);
2016-02-16 16:12:13 +09:00
// this.unblock();
2016-01-02 18:40:49 +01:00
2016-02-16 16:12:13 +09:00
// if(Users.can.viewById(this.userId)){
// var comment = Comments.findOne(commentId);
// return Posts.find({_id: comment && comment.postId});
// }
// return [];
// });
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// // Publish author of the current comment, and author of the post related to the current comment
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// Meteor.publish('commentUsers', function(commentId) {
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// check(commentId, String);
2016-01-02 18:40:49 +01:00
2016-02-16 16:12:13 +09:00
// this.unblock();
2016-01-02 18:40:49 +01:00
2016-02-16 16:12:13 +09:00
// var userIds = [];
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// if(Users.can.viewById(this.userId)){
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// var comment = Comments.findOne(commentId);
2015-05-21 15:51:19 +09:00
2016-02-16 16:12:13 +09:00
// if (!!comment) {
// userIds.push(comment.userId);
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// var post = Posts.findOne(comment.postId);
// if (!!post) {
// userIds.push(post.userId);
// }
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// return Meteor.users.find({_id: {$in: userIds}}, {fields: Users.pubsub.publicProperties});
2015-05-21 15:51:19 +09:00
2016-02-16 16:12:13 +09:00
// }
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// }
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// return [];
2015-04-22 07:50:26 +09:00
2016-02-16 16:12:13 +09:00
// });