Merge pull request #797 from Baxter900/devel

Improved vote accessability for packages
This commit is contained in:
Sacha Greif 2015-03-10 10:59:49 +09:00
commit b6ccc63182
3 changed files with 82 additions and 4 deletions

View file

@ -1,8 +1,10 @@
// returns how much "power" a user's votes have // returns how much "power" a user's votes have
var getVotePower = function (user) { var getVotePower = function (user) {
// return isAdmin(user) ? 5 : 1; power = 1;
return 1; // for now, leave everybody at 1 including admins; 5 is too unbalanced if(typeof votePowerEq == 'function')
power = votePowerEq(user);
return power;
}; };
var modifyKarma = function (userId, karma) { 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 --------------------- // // --------------------- Server-Side Async Callbacks --------------------- //
if (Meteor.isServer) { if (Meteor.isServer) {
@ -135,6 +144,14 @@ downvoteItem = function (collection, item, user) {
modifyKarma(item.userId, votePower); 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 --------------------- // // --------------------- Server-Side Async Callbacks --------------------- //
if (Meteor.isServer) { 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 the item is being upvoted by its own author, don't give karma
if (item.userId != user._id) if (item.userId != user._id)
modifyKarma(item.userId, votePower); 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)); // console.log(collection.findOne(item._id));
return true; 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 the item is being upvoted by its own author, don't give karma
if (item.userId != user._id) if (item.userId != user._id)
modifyKarma(item.userId, votePower); 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)); // console.log(collection.findOne(item._id));
return true; return true;

View file

@ -278,6 +278,12 @@ userProfileCompleteChecks = [];
upvoteCallbacks = []; upvoteCallbacks = [];
downvoteCallbacks = []; downvoteCallbacks = [];
cancelUpvoteCallbacks = [];
cancelDownvoteCallbacks = [];
upvoteMethodCallbacks = [];
downvoteMethodCallbacks = [];
cancelUpvoteMethodCallbacks = [];
cancelDownvoteMethodCallbacks = [];
// ------------------------------------- User Profiles -------------------------------- // // ------------------------------------- User Profiles -------------------------------- //
@ -336,4 +342,9 @@ themeSettings = {
// ------------------------------ Subscriptions ------------------------------ // // ------------------------------ Subscriptions ------------------------------ //
// array containing subscriptions to be preloaded // array containing subscriptions to be preloaded
preloadSubscriptions = []; preloadSubscriptions = [];
// ------------------------------- Vote Power -------------------------------- //
// The equation to determine Vote Power
votePowerEq = null;

View file

@ -62,6 +62,12 @@ Package.onUse(function (api) {
'upvoteCallbacks', 'upvoteCallbacks',
'downvoteCallbacks', 'downvoteCallbacks',
'cancelUpvoteCallbacks',
'cancelDownvoteCallbacks',
'upvoteMethodCallbacks',
'downvoteMethodCallbacks',
'cancelUpvoteMethodCallbacks',
'cancelDownvoteMethodCallbacks',
'userEditRenderedCallbacks', 'userEditRenderedCallbacks',
'userEditClientCallbacks', 'userEditClientCallbacks',
@ -73,6 +79,8 @@ Package.onUse(function (api) {
'getTemplate', 'getTemplate',
'templates', 'templates',
'themeSettings' 'themeSettings',
'votePowerEq'
]); ]);
}); });