From 0ffd5254ada254d42de0adb9ca06ec64614a8781 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 10 Dec 2015 09:00:46 +0200 Subject: [PATCH] closes #3933, closes #3934 --- public/src/client/topic/postTools.js | 10 ++++++---- src/favourites.js | 23 ++++++++++------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.js index 6be1fce55d..c971a7e5fc 100644 --- a/public/src/client/topic/postTools.js +++ b/public/src/client/topic/postTools.js @@ -255,10 +255,12 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator pid: post.attr('data-pid'), room_id: app.currentRoom }, function(err) { - if (err.message === 'self-vote') { - showVotes(post.attr('data-pid')); - } else { - app.alertError(err.message); + if (err) { + if (err.message === 'self-vote') { + showVotes(post.attr('data-pid')); + } else { + app.alertError(err.message); + } } }); diff --git a/src/favourites.js b/src/favourites.js index c5d71f6de2..5af0a7f051 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -133,19 +133,9 @@ var async = require('async'), putVoteInProgress(pid, uid); - user.getUserField(uid, 'reputation', function(err, reputation) { - if (err) { - return callback(err); - } - - if (reputation < parseInt(meta.config['privileges:downvote'], 10)) { - return callback(new Error('[[error:not-enough-reputation-to-downvote]]')); - } - - toggleVote('downvote', pid, uid, function(err, data) { - clearVoteProgress(pid, uid); - callback(err, data); - }); + toggleVote('downvote', pid, uid, function(err, data) { + clearVoteProgress(pid, uid); + callback(err, data); }); }; @@ -197,6 +187,9 @@ var async = require('async'), }, voteStatus: function(next) { Favourites.hasVoted(pid, uid, next); + }, + reputation: function(next) { + user.getUserField(uid, 'reputation', next); } }, function(err, results) { if (err) { @@ -207,6 +200,10 @@ var async = require('async'), return callback(new Error('self-vote')); } + if (command === 'downvote' && parseInt(results.reputation) < parseInt(meta.config['privileges:downvote'], 10)) { + return callback(new Error('[[error:not-enough-reputation-to-downvote]]')); + } + var voteStatus = results.voteStatus, hook, current = voteStatus.upvoted ? 'upvote' : 'downvote';