diff --git a/lib/vote.js b/lib/vote.js index 52550704b..63415c520 100644 --- a/lib/vote.js +++ b/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; diff --git a/packages/telescope-base/lib/base.js b/packages/telescope-base/lib/base.js index fc7c483d9..f1a401d5c 100644 --- a/packages/telescope-base/lib/base.js +++ b/packages/telescope-base/lib/base.js @@ -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 = []; \ No newline at end of file +preloadSubscriptions = []; + +// ------------------------------- Vote Power -------------------------------- // + +// The equation to determine Vote Power +votePowerEq = null; diff --git a/packages/telescope-base/package.js b/packages/telescope-base/package.js index 442efc860..b49b9ccb3 100644 --- a/packages/telescope-base/package.js +++ b/packages/telescope-base/package.js @@ -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' ]); });