publish the post related to a single comment

This commit is contained in:
Sacha Greif 2013-10-26 10:47:13 +09:00
parent 65e59767d1
commit 0c47f6e250
6 changed files with 27 additions and 15 deletions

View file

@ -298,7 +298,8 @@ CommentPageController = RouteController.extend({
waitOn: function() { waitOn: function() {
return [ return [
Meteor.subscribe('singleComment', this.params._id), Meteor.subscribe('singleComment', this.params._id),
Meteor.subscribe('commentUser', this.params._id) Meteor.subscribe('commentUser', this.params._id),
Meteor.subscribe('commentPost', this.params._id)
] ]
}, },
data: function() { data: function() {

View file

@ -1,14 +1,16 @@
<template name="comment_page"> <template name="comment_page">
{{#if canView}} {{#if canView}}
<div class="post grid comment-page"> <div class="post grid comment-page">
{{#with post}}
{{>post_item}}
{{/with}}
{{#if comment}}
{{#with comment}} {{#with comment}}
<ul class="selected-comment"> <ul class="selected-comment">
{{> comment_item}} {{> comment_item}}
</ul> </ul>
{{/with}} {{/with}}
{{/if}}
</div> </div>
{{/if}} {{/if}}

View file

@ -1,4 +1,5 @@
Template.comment_page.post = function(){ Template.comment_page.helpers({
var selectedComment = Comments.findOne(Session.get('selectedCommentId')); post: function () {
return selectedComment && Posts.findOne(selectedComment.post); return Posts.findOne(this.comment.post);
}; }
});

View file

@ -1,21 +1,19 @@
<template name="comment_reply"> <template name="comment_reply">
{{#if canComment "replace"}} {{#if canComment "replace"}}
<div class="post grid comment-page"> <div class="post grid comment-page">
{{#if post}}
{{#with post}} {{#with post}}
{{> post_item}} {{> post_item}}
{{/with}} {{/with}}
{{/if}}
{{#if comment}}
{{#with comment}} {{#with comment}}
<ul class="selected-comment"> <ul class="selected-comment">
{{> comment_item}} {{> comment_item}}
</ul> </ul>
{{/with}} {{/with}}
{{/if}}
{{> comment_form}} {{> comment_form}}
</div> </div>
{{/if}} {{/if}}
</template> </template>

View file

@ -1,4 +1,5 @@
Template.comment_reply.post = function(){ Template.comment_reply.helpers({
var comment = this; post: function () {
return comment && Posts.findOne(comment.post); return Posts.findOne(this.comment.post);
}; }
});

View file

@ -83,6 +83,15 @@ Meteor.publish('singlePost', function(id) {
} }
}); });
// The post related to the current comment
Meteor.publish('commentPost', function(commentId) {
if(canViewById(this.userId)){
var comment = Comments.findOne(commentId);
return Posts.find(comment.post);
}
});
Meteor.publish('postsList', function(find, options) { Meteor.publish('postsList', function(find, options) {
if(canViewById(this.userId)){ if(canViewById(this.userId)){
options = options || {}; options = options || {};