mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Changed comments to CommentsCount; Now tracking _ids of commenters on each Post document
This commit is contained in:
parent
0a0ad6a501
commit
063242b78d
6 changed files with 40 additions and 6 deletions
|
@ -4,6 +4,8 @@
|
||||||
* Changed `navItems` to `primaryNav` and added `secondaryNav`.
|
* Changed `navItems` to `primaryNav` and added `secondaryNav`.
|
||||||
* Added new `themeSettings` object for storing theme-level settings.
|
* Added new `themeSettings` object for storing theme-level settings.
|
||||||
* Notifications is now a nav menu item.
|
* Notifications is now a nav menu item.
|
||||||
|
* Renamed `comments` to `commentsCount` on `Post` model.
|
||||||
|
* Now tracking list of commenters `_id`s on `Post` model.
|
||||||
|
|
||||||
## v0.9.2.5 “AccountScope”
|
## v0.9.2.5 “AccountScope”
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template name="postCommentsLink">
|
<template name="postCommentsLink">
|
||||||
<div class="post-meta-item">
|
<div class="post-meta-item">
|
||||||
<a class="comments-link" href="/posts/{{_id}}">
|
<a class="comments-link" href="/posts/{{_id}}">
|
||||||
<span class="count">{{comments}}</span>
|
<span class="count">{{commentsCount}}</span>
|
||||||
<span class="action">{{i18n 'Comments'}}</span>
|
<span class="action">{{i18n 'Comments'}}</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template name="postDiscuss">
|
<template name="postDiscuss">
|
||||||
<a class="discuss-link go-to-comments" href="/posts/{{_id}}">
|
<a class="discuss-link go-to-comments" href="/posts/{{_id}}">
|
||||||
<i class="icon-comment"></i>
|
<i class="icon-comment"></i>
|
||||||
<span class="count">{{comments}}</span>
|
<span class="count">{{commentsCount}}</span>
|
||||||
<span class="action">{{i18n 'Discuss'}}</span>
|
<span class="action">{{i18n 'Discuss'}}</span>
|
||||||
</a>
|
</a>
|
||||||
</template>
|
</template>
|
|
@ -128,7 +128,11 @@ Meteor.methods({
|
||||||
// extend comment with newly created _id
|
// extend comment with newly created _id
|
||||||
comment = _.extend(comment, {_id: newCommentId});
|
comment = _.extend(comment, {_id: newCommentId});
|
||||||
|
|
||||||
Posts.update(postId, {$inc: {comments: 1}, $set: {lastCommentedAt: now}});
|
Posts.update(postId, {
|
||||||
|
$inc: {commentsCount: 1},
|
||||||
|
$set: {lastCommentedAt: now},
|
||||||
|
$addToSet: {commenters: user._id}
|
||||||
|
});
|
||||||
|
|
||||||
Meteor.call('upvoteComment', comment);
|
Meteor.call('upvoteComment', comment);
|
||||||
|
|
||||||
|
@ -167,8 +171,11 @@ Meteor.methods({
|
||||||
removeComment: function(commentId){
|
removeComment: function(commentId){
|
||||||
var comment=Comments.findOne(commentId);
|
var comment=Comments.findOne(commentId);
|
||||||
if(canEdit(Meteor.user(), comment)){
|
if(canEdit(Meteor.user(), comment)){
|
||||||
// decrement post comment count
|
// decrement post comment count and remove user ID from post
|
||||||
Posts.update(comment.postId, {$inc: {comments: -1}});
|
Posts.update(comment.postId, {
|
||||||
|
$inc: {commentsCount: -1},
|
||||||
|
$pull: {commenters: comment.userId}
|
||||||
|
});
|
||||||
|
|
||||||
// decrement user comment count
|
// decrement user comment count
|
||||||
Meteor.users.update({_id: comment.userId}, {$inc: {commentCount: -1}});
|
Meteor.users.update({_id: comment.userId}, {$inc: {commentCount: -1}});
|
||||||
|
|
|
@ -24,10 +24,14 @@ postSchemaObject = {
|
||||||
type: String,
|
type: String,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
comments: {
|
commentsCount: {
|
||||||
type: Number,
|
type: Number,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
|
commenters: {
|
||||||
|
type: [String],
|
||||||
|
optional: true
|
||||||
|
},
|
||||||
lastCommentedAt: {
|
lastCommentedAt: {
|
||||||
type: Date,
|
type: Date,
|
||||||
optional: true
|
optional: true
|
||||||
|
|
|
@ -280,5 +280,26 @@ var migrationsList = {
|
||||||
console.log("---------------------");
|
console.log("---------------------");
|
||||||
});
|
});
|
||||||
return i;
|
return i;
|
||||||
|
},
|
||||||
|
commentsToCommentsCount: function () {
|
||||||
|
var i = 0;
|
||||||
|
Posts.find({commentsCount: {$exists : false}}).forEach(function (post) {
|
||||||
|
i++;
|
||||||
|
console.log("Post: "+post._id);
|
||||||
|
Posts.update(post._id, { $rename: { 'comments': 'commentsCount'}}, {multi: true, validate: false});
|
||||||
|
console.log("---------------------");
|
||||||
|
});
|
||||||
|
return i;
|
||||||
|
},
|
||||||
|
addCommentersToPosts: function () {
|
||||||
|
var i = 0;
|
||||||
|
Comments.find().forEach(function (comment) {
|
||||||
|
i++;
|
||||||
|
console.log("Comment: "+comment._id);
|
||||||
|
console.log("Post: "+comment.postId);
|
||||||
|
Posts.update(comment.postId, { $addToSet: { 'commenters': comment.userId}}, {multi: true, validate: false});
|
||||||
|
console.log("---------------------");
|
||||||
|
});
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue