Closed nrk closed 11 years ago
Looking at the diff between handle_news_vote and handle_comment_vote, it would be quite simple to create:
function handle_vote(vote_type, item_type, id, apisecret) {
with item_type 'news or 'comment'.
@beanz you are right, I had the same idea but decided to wait to see how we should handle the update of the number of up/down votes for news and points for comments after voting, since these two actions follow two completely different logics. This could be easily implemented with an optional callback argument, if @antirez finds it useful I can commit a couple of more changes to this PR while I'm at this.
Also, I just realized that apisecret
actually lives in the global scope so there's no need to have it as an argument. I'll push a fix for this later.
In the end I couldn't resist and so this is what I came up with with some further refactoring of the code following @beanz's comment. It's on a different branch on my repository, if it looks good I can merge it into this pull request.
This looks great, I need to check if this does not break existing code, and if so, merging it. Thanks.
p.s. what I mean is that after 11 months I'm not sure if there are more recent changes that will break your fixes. But it looks like everything is fine actually...
I've been running the code from the 'refactor_voting_handlers2' branch in production for some time, everything works flawlessly. Could you merge it to this pull request @nrk ? Thanks!
Merged the 'refactor_voting_handlers2' branch from @nrk repository. Thanks!
This pull request reduces code duplication in
app.js
and fixes a bug that was causing the inability to vote the main comment highlighted in the comment page.