mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
Merge pull request #797 from Baxter900/devel
Improved vote accessability for packages
This commit is contained in:
commit
b6ccc63182
3 changed files with 82 additions and 4 deletions
63
lib/vote.js
63
lib/vote.js
|
@ -1,8 +1,10 @@
|
|||
|
||||
// returns how much "power" a user's votes have
|
||||
var getVotePower = function (user) {
|
||||
// return isAdmin(user) ? 5 : 1;
|
||||
return 1; // for now, leave everybody at 1 including admins; 5 is too unbalanced
|
||||
power = 1;
|
||||
if(typeof votePowerEq == 'function')
|
||||
power = votePowerEq(user);
|
||||
return power;
|
||||
};
|
||||
|
||||
var modifyKarma = function (userId, karma) {
|
||||
|
@ -82,6 +84,13 @@ upvoteItem = function (collection, item, user) {
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------ Callbacks ------------------------------ //
|
||||
|
||||
// run all post submit server callbacks on post object successively
|
||||
result = upvoteMethodCallbacks.reduce(function(result, currentFunction) {
|
||||
return currentFunction(collection, result, user);
|
||||
}, item);
|
||||
|
||||
// --------------------- Server-Side Async Callbacks --------------------- //
|
||||
|
||||
if (Meteor.isServer) {
|
||||
|
@ -135,6 +144,14 @@ downvoteItem = function (collection, item, user) {
|
|||
modifyKarma(item.userId, votePower);
|
||||
|
||||
|
||||
// ------------------------------ Callbacks ------------------------------ //
|
||||
|
||||
// run all post submit server callbacks on post object successively
|
||||
result = downvoteMethodCallbacks.reduce(function(result, currentFunction) {
|
||||
return currentFunction(collection, result, user);
|
||||
}, item);
|
||||
|
||||
|
||||
// --------------------- Server-Side Async Callbacks --------------------- //
|
||||
|
||||
if (Meteor.isServer) {
|
||||
|
@ -178,6 +195,27 @@ cancelUpvote = function (collection, item, user) {
|
|||
// if the item is being upvoted by its own author, don't give karma
|
||||
if (item.userId != user._id)
|
||||
modifyKarma(item.userId, votePower);
|
||||
|
||||
|
||||
|
||||
// ------------------------------ Callbacks ------------------------------ //
|
||||
|
||||
// run all post submit server callbacks on post object successively
|
||||
result = cancelUpvoteMethodCallbacks.reduce(function(result, currentFunction) {
|
||||
return currentFunction(collection, result, user);
|
||||
}, item);
|
||||
|
||||
|
||||
// --------------------- Server-Side Async Callbacks --------------------- //
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.defer(function () { // use defer to avoid holding up client
|
||||
// run all post submit server callbacks on post object successively
|
||||
result = cancelUpvoteCallbacks.reduce(function(result, currentFunction) {
|
||||
return currentFunction(collection, result, user);
|
||||
}, result);
|
||||
});
|
||||
}
|
||||
}
|
||||
// console.log(collection.findOne(item._id));
|
||||
return true;
|
||||
|
@ -210,6 +248,27 @@ cancelDownvote = function (collection, item, user) {
|
|||
// if the item is being upvoted by its own author, don't give karma
|
||||
if (item.userId != user._id)
|
||||
modifyKarma(item.userId, votePower);
|
||||
|
||||
|
||||
|
||||
// ------------------------------ Callbacks ------------------------------ //
|
||||
|
||||
// run all post submit server callbacks on post object successively
|
||||
result = cancelDownvoteMethodCallbacks.reduce(function(result, currentFunction) {
|
||||
return currentFunction(collection, result, user);
|
||||
}, item);
|
||||
|
||||
|
||||
// --------------------- Server-Side Async Callbacks --------------------- //
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.defer(function () { // use defer to avoid holding up client
|
||||
// run all post submit server callbacks on post object successively
|
||||
result = cancelDownvoteCallbacks.reduce(function(result, currentFunction) {
|
||||
return currentFunction(collection, result, user);
|
||||
}, result);
|
||||
});
|
||||
}
|
||||
}
|
||||
// console.log(collection.findOne(item._id));
|
||||
return true;
|
||||
|
|
|
@ -278,6 +278,12 @@ userProfileCompleteChecks = [];
|
|||
|
||||
upvoteCallbacks = [];
|
||||
downvoteCallbacks = [];
|
||||
cancelUpvoteCallbacks = [];
|
||||
cancelDownvoteCallbacks = [];
|
||||
upvoteMethodCallbacks = [];
|
||||
downvoteMethodCallbacks = [];
|
||||
cancelUpvoteMethodCallbacks = [];
|
||||
cancelDownvoteMethodCallbacks = [];
|
||||
|
||||
// ------------------------------------- User Profiles -------------------------------- //
|
||||
|
||||
|
@ -336,4 +342,9 @@ themeSettings = {
|
|||
// ------------------------------ Subscriptions ------------------------------ //
|
||||
|
||||
// array containing subscriptions to be preloaded
|
||||
preloadSubscriptions = [];
|
||||
preloadSubscriptions = [];
|
||||
|
||||
// ------------------------------- Vote Power -------------------------------- //
|
||||
|
||||
// The equation to determine Vote Power
|
||||
votePowerEq = null;
|
||||
|
|
|
@ -62,6 +62,12 @@ Package.onUse(function (api) {
|
|||
|
||||
'upvoteCallbacks',
|
||||
'downvoteCallbacks',
|
||||
'cancelUpvoteCallbacks',
|
||||
'cancelDownvoteCallbacks',
|
||||
'upvoteMethodCallbacks',
|
||||
'downvoteMethodCallbacks',
|
||||
'cancelUpvoteMethodCallbacks',
|
||||
'cancelDownvoteMethodCallbacks',
|
||||
|
||||
'userEditRenderedCallbacks',
|
||||
'userEditClientCallbacks',
|
||||
|
@ -73,6 +79,8 @@ Package.onUse(function (api) {
|
|||
'getTemplate',
|
||||
'templates',
|
||||
|
||||
'themeSettings'
|
||||
'themeSettings',
|
||||
|
||||
'votePowerEq'
|
||||
]);
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue