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() {
return [
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() {

View file

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

View file

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

View file

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

View file

@ -1,4 +1,5 @@
Template.comment_reply.post = function(){
var comment = this;
return comment && Posts.findOne(comment.post);
};
Template.comment_reply.helpers({
post: function () {
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) {
if(canViewById(this.userId)){
options = options || {};