fixing new comments validation

This commit is contained in:
Sacha Greif 2014-06-22 10:34:39 +09:00
parent 07a95b3b5c
commit a99a0f89e6
4 changed files with 18 additions and 11 deletions

View file

@ -137,7 +137,7 @@ Template.comment_item.helpers({
return true;
},
ago: function(){
return moment(this.submitted).fromNow();
return moment(this.createdAt).fromNow();
},
upvoted: function(){
return Meteor.user() && _.include(this.upvoters, Meteor.user()._id);

View file

@ -5,12 +5,12 @@ Template.comment_list.created = function(){
Template.comment_list.helpers({
has_comments: function(){
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;
},
child_comments: function(){
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;
}
});

View file

@ -2,7 +2,8 @@ Comments = new Meteor.Collection("comments", {
schema: new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id
regEx: SimpleSchema.RegEx.Id,
optional: true
},
createdAt: {
type: Date,
@ -13,10 +14,12 @@ Comments = new Meteor.Collection("comments", {
},
baseScore: {
type: Number,
decimal: true,
optional: true
},
score: {
type: Number,
decimal: true,
optional: true
},
upvotes: {
@ -101,11 +104,15 @@ Meteor.methods({
throw new Meteor.Error(704,i18n.t('Your comment is empty.'));
var comment = {
post: postId,
body: cleanText,
userId: user._id,
submitted: new Date().getTime(),
author: getDisplayName(user)
postId: postId,
body: cleanText,
userId: user._id,
createdAt: new Date(),
upvotes: 0,
downvotes: 0,
baseScore: 0,
score: 0,
author: getDisplayName(user)
};
if(parentCommentId)

View file

@ -43,7 +43,7 @@ Meteor.publish('postUsers', function(postId) {
users = [];
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
users = _.pluck(comments, "userId");
users.push(post.userId);
@ -146,7 +146,7 @@ Meteor.publish('postsList', function(terms) {
Meteor.publish('postComments', function(postId) {
if(canViewById(this.userId)){
return Comments.find({post: postId});
return Comments.find({postId: postId});
}
return [];
});