mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Fix downvoting, cancelling upvoting & cancelling downvoting
Additionally removed the `(function() {})();` encapsulation since Meteor already adds this in since they started scoping files
This commit is contained in:
parent
0bed5aa609
commit
b38c6cda3f
1 changed files with 7 additions and 9 deletions
16
lib/vote.js
16
lib/vote.js
|
@ -1,4 +1,4 @@
|
|||
(function() {
|
||||
|
||||
// returns how much "power" a user's votes have
|
||||
var getVotePower = function(user){
|
||||
// return (user && user.isAdmin) ? 5 : 1;
|
||||
|
@ -30,7 +30,7 @@
|
|||
cancelDownvote(collection, item, user)
|
||||
|
||||
// Votes & Score
|
||||
var result = collection.update({_id: item._id},{
|
||||
var result = collection.update({_id: item && item._id},{
|
||||
$addToSet: {upvoters: user._id},
|
||||
$pull: {downvoters: user._id},
|
||||
$inc: {votes: 1, baseScore: votePower},
|
||||
|
@ -71,7 +71,7 @@
|
|||
cancelUpvote(collection, item, user)
|
||||
|
||||
// Votes & Score
|
||||
collection.update({_id: id},{
|
||||
collection.update({_id: item && item._id},{
|
||||
$addToSet: {downvoters: user._id},
|
||||
$pull: {upvoters: user._id},
|
||||
$inc: {votes: -1, baseScore: -votePower},
|
||||
|
@ -98,7 +98,7 @@
|
|||
return false;
|
||||
|
||||
// Votes & Score
|
||||
collection.update({_id: id},{
|
||||
collection.update({_id: item && item._id},{
|
||||
$pull: {upvoters: user._id},
|
||||
$inc: {votes: -1, baseScore: -votePower},
|
||||
$set: {inactive: false}
|
||||
|
@ -106,7 +106,7 @@
|
|||
|
||||
// extend item with baseScore to help calculate newScore
|
||||
item = _.extend(item, {baseScore: (item.baseScore + votePower)});
|
||||
updateScore(collection, id, true);
|
||||
updateScore(item && item._id, collection, true);
|
||||
|
||||
// if the item is being upvoted by its own author, don't give karma
|
||||
if (item.userId != user._id)
|
||||
|
@ -124,7 +124,7 @@
|
|||
return false;
|
||||
|
||||
// Votes & Score
|
||||
collection.update({_id: id},{
|
||||
collection.update({_id: item && item._id},{
|
||||
$pull: {downvoters: user._id},
|
||||
$inc: {votes: 1, baseScore: votePower},
|
||||
$set: {inactive: false}
|
||||
|
@ -132,7 +132,7 @@
|
|||
|
||||
// extend item with baseScore to help calculate newScore
|
||||
item = _.extend(item, {baseScore: (item.baseScore + votePower)});
|
||||
updateScore(collection, id, true);
|
||||
updateScore(item && item._id, collection, true);
|
||||
|
||||
// if the item is being upvoted by its own author, don't give karma
|
||||
if (item.userId != user._id)
|
||||
|
@ -174,5 +174,3 @@
|
|||
return cancelDownvote.call(this, Comments, comment);
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
Loading…
Add table
Reference in a new issue