mirror of
https://github.com/vale981/Vulcan
synced 2025-03-08 19:11:38 -05:00
fixing new comments validation
This commit is contained in:
parent
07a95b3b5c
commit
a99a0f89e6
4 changed files with 18 additions and 11 deletions
|
@ -137,7 +137,7 @@ Template.comment_item.helpers({
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
ago: function(){
|
ago: function(){
|
||||||
return moment(this.submitted).fromNow();
|
return moment(this.createdAt).fromNow();
|
||||||
},
|
},
|
||||||
upvoted: function(){
|
upvoted: function(){
|
||||||
return Meteor.user() && _.include(this.upvoters, Meteor.user()._id);
|
return Meteor.user() && _.include(this.upvoters, Meteor.user()._id);
|
||||||
|
|
|
@ -5,12 +5,12 @@ Template.comment_list.created = function(){
|
||||||
Template.comment_list.helpers({
|
Template.comment_list.helpers({
|
||||||
has_comments: function(){
|
has_comments: function(){
|
||||||
var post = this;
|
var post = this;
|
||||||
var comments = Comments.find({post: post._id, parent: null}, {sort: {score: -1, submitted: -1}});
|
var comments = Comments.find({postId: post._id, parent: null}, {sort: {score: -1, submitted: -1}});
|
||||||
return comments.count() > 0;
|
return comments.count() > 0;
|
||||||
},
|
},
|
||||||
child_comments: function(){
|
child_comments: function(){
|
||||||
var post = this;
|
var post = this;
|
||||||
var comments = Comments.find({post: post._id, parent: null}, {sort: {score: -1, submitted: -1}});
|
var comments = Comments.find({postId: post._id, parent: null}, {sort: {score: -1, submitted: -1}});
|
||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,8 @@ Comments = new Meteor.Collection("comments", {
|
||||||
schema: new SimpleSchema({
|
schema: new SimpleSchema({
|
||||||
_id: {
|
_id: {
|
||||||
type: String,
|
type: String,
|
||||||
regEx: SimpleSchema.RegEx.Id
|
regEx: SimpleSchema.RegEx.Id,
|
||||||
|
optional: true
|
||||||
},
|
},
|
||||||
createdAt: {
|
createdAt: {
|
||||||
type: Date,
|
type: Date,
|
||||||
|
@ -13,10 +14,12 @@ Comments = new Meteor.Collection("comments", {
|
||||||
},
|
},
|
||||||
baseScore: {
|
baseScore: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
decimal: true,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
score: {
|
score: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
decimal: true,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
upvotes: {
|
upvotes: {
|
||||||
|
@ -101,11 +104,15 @@ Meteor.methods({
|
||||||
throw new Meteor.Error(704,i18n.t('Your comment is empty.'));
|
throw new Meteor.Error(704,i18n.t('Your comment is empty.'));
|
||||||
|
|
||||||
var comment = {
|
var comment = {
|
||||||
post: postId,
|
postId: postId,
|
||||||
body: cleanText,
|
body: cleanText,
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
submitted: new Date().getTime(),
|
createdAt: new Date(),
|
||||||
author: getDisplayName(user)
|
upvotes: 0,
|
||||||
|
downvotes: 0,
|
||||||
|
baseScore: 0,
|
||||||
|
score: 0,
|
||||||
|
author: getDisplayName(user)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(parentCommentId)
|
if(parentCommentId)
|
||||||
|
|
|
@ -43,7 +43,7 @@ Meteor.publish('postUsers', function(postId) {
|
||||||
users = [];
|
users = [];
|
||||||
|
|
||||||
if(post) {
|
if(post) {
|
||||||
var comments = Comments.find({post: post._id}).fetch();
|
var comments = Comments.find({postId: post._id}).fetch();
|
||||||
// get IDs from all commenters on the post, plus post author's ID
|
// get IDs from all commenters on the post, plus post author's ID
|
||||||
users = _.pluck(comments, "userId");
|
users = _.pluck(comments, "userId");
|
||||||
users.push(post.userId);
|
users.push(post.userId);
|
||||||
|
@ -146,7 +146,7 @@ Meteor.publish('postsList', function(terms) {
|
||||||
|
|
||||||
Meteor.publish('postComments', function(postId) {
|
Meteor.publish('postComments', function(postId) {
|
||||||
if(canViewById(this.userId)){
|
if(canViewById(this.userId)){
|
||||||
return Comments.find({post: postId});
|
return Comments.find({postId: postId});
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue