mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Fix bad karma
This commit is contained in:
parent
b6e49111aa
commit
23fccbd082
1 changed files with 41 additions and 18 deletions
59
lib/vote.js
59
lib/vote.js
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue