Fix bad karma

This commit is contained in:
Julien Chaumond 2012-09-28 15:07:25 +02:00
parent b6e49111aa
commit 23fccbd082

View file

@ -9,9 +9,8 @@
Meteor.users.update({_id: userId}, {$inc: {karma: karma}});
};
var giveKarmaForPost = function(postId, karma){
var votedPost=Posts.findOne(postId);
modifyKarma(votedPost.user_id, karma);
var giveKarmaForItem = function(votedItem, karma){
modifyKarma(votedItem.user_id, karma);
};
var upvote = function(collection, id) {
@ -19,15 +18,21 @@
return false;
var votePower=getVotePower(this.userId());
// Is my userId already in up/downvoters?
var ack = (collection.findOne({_id: id, upvoters: {$ne: this.userId()}}) !== undefined);
// only modify the document if my userId isn't already in upvoters
collection.update({_id: id, upvoters: {$ne: this.userId()}},
{$push: {upvoters: this.userId()},
$inc: {votes: 1, baseScore: votePower}});
// user's posts and comments do not impact his own karma:
if (id != this.userId) {
giveKarmaForPost(id, votePower);
if (ack) {
var votedItem = collection.findOne(id);
// user's posts and comments do not impact his own karma:
if (votedItem.user_id != this.userId()) {
giveKarmaForItem(votedItem, votePower);
}
}
if (!this.isSimulation)
@ -42,14 +47,20 @@
var votePower=getVotePower(this.userId());
// Is my userId already in up/downvoters?
var ack = (collection.findOne({_id: id, downvoters: {$ne: this.userId()}}) !== undefined);
// only modify the document if my userId isn't already in downvoters
collection.update({_id: id, downvoters: {$ne: this.userId()}},
{$push: {downvoters: this.userId()},
$inc: {votes: -1, baseScore: -votePower}});
// user's posts and comments do not impact his own karma:
if (id != this.userId) {
giveKarmaForPost(id, -votePower);
if (ack) {
var votedItem = collection.findOne(id);
// user's posts and comments do not impact his own karma:
if (votedItem.user_id != this.userId()) {
giveKarmaForItem(votedItem, -votePower);
}
}
if (!this.isSimulation)
@ -63,15 +74,21 @@
return false;
var votePower=getVotePower(this.userId());
// Is my userId already in up/downvoters?
var ack = (collection.findOne({_id: id, upvoters: {$ne: this.userId()}}) !== undefined);
// only modify the document if i am a recorded voter
collection.update({_id: id, upvoters: this.userId()},
{$pull: {upvoters: this.userId()},
$inc: {votes: -1, baseScore: -votePower}});
// user's posts and comments do not impact his own karma:
if (id != this.userId) {
giveKarmaForPost(id, -votePower);
if (ack) {
var votedItem = collection.findOne(id);
// user's posts and comments do not impact his own karma:
if (votedItem.user_id != this.userId()) {
giveKarmaForItem(votedItem, -votePower);
}
}
if (!this.isSimulation)
@ -85,15 +102,21 @@
return false;
var votePower=getVotePower(this.userId());
// Is my userId already in up/downvoters?
var ack = (collection.findOne({_id: id, downvoters: {$ne: this.userId()}}) !== undefined);
// only modify the document if i am a recorded voter
collection.update({_id: id, downvoters: this.userId()},
{$pull: {downvoters: this.userId()},
$inc: {votes: 1, baseScore: votePower}});
// user's posts and comments do not impact his own karma:
if (id != this.userId) {
giveKarmaForPost(id, votePower);
if (ack) {
var votedItem = collection.findOne(id);
// user's posts and comments do not impact his own karma:
if (votedItem.user_id != this.userId()) {
giveKarmaForItem(votedItem, votePower);
}
}
if (!this.isSimulation)