{"action":"created","issue":{"url":"https://api.github.com/repos/TelescopeJS/Telescope/issues/797","labels_url":"https://api.github.com/repos/TelescopeJS/Telescope/issues/797/labels{/name}","comments_url":"https://api.github.com/repos/TelescopeJS/Telescope/issues/797/comments","events_url":"https://api.github.com/repos/TelescopeJS/Telescope/issues/797/events","html_url":"https://github.com/TelescopeJS/Telescope/pull/797","id":60268591,"number":797,"title":"Improved vote accessability for packages","user":{"login":"Baxter900","id":5560914,"avatar_url":"https://avatars.githubusercontent.com/u/5560914?v=3","gravatar_id":"","url":"https://api.github.com/users/Baxter900","html_url":"https://github.com/Baxter900","followers_url":"https://api.github.com/users/Baxter900/followers","following_url":"https://api.github.com/users/Baxter900/following{/other_user}","gists_url":"https://api.github.com/users/Baxter900/gists{/gist_id}","starred_url":"https://api.github.com/users/Baxter900/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Baxter900/subscriptions","organizations_url":"https://api.github.com/users/Baxter900/orgs","repos_url":"https://api.github.com/users/Baxter900/repos","events_url":"https://api.github.com/users/Baxter900/events{/privacy}","received_events_url":"https://api.github.com/users/Baxter900/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-03-08T18:07:34Z","updated_at":"2015-03-10T22:49:27Z","closed_at":"2015-03-10T01:59:49Z","pull_request":{"url":"https://api.github.com/repos/TelescopeJS/Telescope/pulls/797","html_url":"https://github.com/TelescopeJS/Telescope/pull/797","diff_url":"https://github.com/TelescopeJS/Telescope/pull/797.diff","patch_url":"https://github.com/TelescopeJS/Telescope/pull/797.patch"},"body":"This is a modification which adds various callback hooks for the voting system.\r\n\r\nIt adds the callbacks:\r\n<pre><code>cancelUpvoteCallbacks\r\ncancelDownvoteCallbacks\r\nupvoteMethodCallbacks\r\ndownvoteMethodCallbacks\r\ncancelUpvoteMethodCallbacks\r\ncancelDownvoteMethodCallbacks\r\n</code></pre>\r\nTo the existing callbacks of:\r\n<pre><code>upvoteCallbacks\r\ndownvoteCallbacks\r\n</code></pre>\r\n\r\nThe advantage of the Method callbacks over the original ones is that the original ones ran asynchronously server-side, wheras the Method callbacks will hold up the vote action until the code in the callbacks finishes, which may be useful in some cases, and they run on both the server and client.\r\n\r\nThe original names were left consistent for backwards compatibility, but it may be worth considering changing the names to something that makes more sense, like upvoteServerCallbacks or upvoteAsyncCallbacks.\r\n\r\n\r\nThe other modification is a hook which allows for one to set an equation which will determine the power of a vote from within a package. This is done by, within the package, setting votePowerEq equal to a function which returns the value, such as this:\r\n<pre><code>votePowerEq = function (user) {\r\n  var power = user.karma/10 + 1;\r\n  if(isAdmin(user)){\r\n    power *= 2;\r\n  }\r\n  return Math.round(power);\r\n};\r\n</code></pre>\r\n\r\nThen the package must re-export votePowerEq. It's worth noting that the last package to load will be the one that has the equation chosen, if there are multiple ones, but really you should be designing your packages modularly enough that you should be able to remove the package which is conflicting with the one you want to work. If a function is not defined, then the vote power defaults to one. This can be changed from within the vote.js code easily."},"comment":{"url":"https://api.github.com/repos/TelescopeJS/Telescope/issues/comments/78165586","html_url":"https://github.com/TelescopeJS/Telescope/pull/797#issuecomment-78165586","issue_url":"https://api.github.com/repos/TelescopeJS/Telescope/issues/797","id":78165586,"user":{"login":"Baxter900","id":5560914,"avatar_url":"https://avatars.githubusercontent.com/u/5560914?v=3","gravatar_id":"","url":"https://api.github.com/users/Baxter900","html_url":"https://github.com/Baxter900","followers_url":"https://api.github.com/users/Baxter900/followers","following_url":"https://api.github.com/users/Baxter900/following{/other_user}","gists_url":"https://api.github.com/users/Baxter900/gists{/gist_id}","starred_url":"https://api.github.com/users/Baxter900/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Baxter900/subscriptions","organizations_url":"https://api.github.com/users/Baxter900/orgs","repos_url":"https://api.github.com/users/Baxter900/repos","events_url":"https://api.github.com/users/Baxter900/events{/privacy}","received_events_url":"https://api.github.com/users/Baxter900/received_events","type":"User","site_admin":false},"created_at":"2015-03-10T22:49:27Z","updated_at":"2015-03-10T22:49:27Z","body":"Sounds good!\r\n\r\nWould you like me to move the method callback to occur before the voting takes place and then you can do another merge? Or do you want to just move it, since it's pretty much a copy and paste.\r\n\r\nOne thing I thought of though, if we want one to be able to change the vote power with the methodCallback, it would make more sense to do it entirely through that. For example, once the upvoteMethodCallback is called, the way it is set up now you would run whatever function you want to check before, then you would create a function which would return that variable, then set votePowerEq to that function. It's a bit convoluted. However, once upvoteMethodCallback is before the vote, you could instead have votePowerEq be a number instead of a function, then run your function to determine what you want, as the upvoteMethodCallback has the User variable, and other variables. and set votePowerEq (probably better to just call it votePower if it's no longer a function) to the end result. Anyway, tell me what you think, I can implement that change easily enough if you think it's a good idea. "}}