mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 19:21:04 +01:00
fix vote progress
This commit is contained in:
@@ -106,7 +106,16 @@ var async = require('async'),
|
|||||||
return callback(new Error('[[error:reputation-system-disabled]]'));
|
return callback(new Error('[[error:reputation-system-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleVote('upvote', pid, uid, callback);
|
if (voteInProgress(pid, uid)) {
|
||||||
|
return callback(new Error('[[error:already-voting-for-this-post]]'));
|
||||||
|
}
|
||||||
|
|
||||||
|
putVoteInProgress(pid, uid);
|
||||||
|
|
||||||
|
toggleVote('upvote', pid, uid, function(err, data) {
|
||||||
|
clearVoteProgress(pid, uid);
|
||||||
|
callback(err, data);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Favourites.downvote = function(pid, uid, callback) {
|
Favourites.downvote = function(pid, uid, callback) {
|
||||||
@@ -118,6 +127,12 @@ var async = require('async'),
|
|||||||
return callback(new Error('[[error:downvoting-disabled]]'));
|
return callback(new Error('[[error:downvoting-disabled]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (voteInProgress(pid, uid)) {
|
||||||
|
return callback(new Error('[[error:already-voting-for-this-post]]'));
|
||||||
|
}
|
||||||
|
|
||||||
|
putVoteInProgress(pid, uid);
|
||||||
|
|
||||||
user.getUserField(uid, 'reputation', function(err, reputation) {
|
user.getUserField(uid, 'reputation', function(err, reputation) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -127,7 +142,23 @@ var async = require('async'),
|
|||||||
return callback(new Error('[[error:not-enough-reputation-to-downvote]]'));
|
return callback(new Error('[[error:not-enough-reputation-to-downvote]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleVote('downvote', pid, uid, callback);
|
toggleVote('downvote', pid, uid, function(err, data) {
|
||||||
|
clearVoteProgress(pid, uid);
|
||||||
|
callback(err, data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Favourites.unvote = function(pid, uid, callback) {
|
||||||
|
if (voteInProgress(pid, uid)) {
|
||||||
|
return callback(new Error('[[error:already-voting-for-this-post]]'));
|
||||||
|
}
|
||||||
|
|
||||||
|
putVoteInProgress(pid, uid);
|
||||||
|
|
||||||
|
unvote(pid, uid, 'unvote', function(err, data) {
|
||||||
|
clearVoteProgress(pid, uid);
|
||||||
|
callback(err, data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,29 +181,15 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toggleVote(type, pid, uid, callback) {
|
function toggleVote(type, pid, uid, callback) {
|
||||||
function done(err, data) {
|
|
||||||
clearVoteProgress(pid, uid);
|
|
||||||
callback(err, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (voteInProgress(pid, uid)) {
|
|
||||||
return callback(new Error('[[error:already-voting-for-this-post]]'));
|
|
||||||
}
|
|
||||||
putVoteInProgress(pid, uid);
|
|
||||||
|
|
||||||
unvote(pid, uid, type, function(err) {
|
unvote(pid, uid, type, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
vote(type, false, pid, uid, done);
|
vote(type, false, pid, uid, callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Favourites.unvote = function(pid, uid, callback) {
|
|
||||||
unvote(pid, uid, 'unvote', callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
function unvote(pid, uid, command, callback) {
|
function unvote(pid, uid, command, callback) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
owner: function(next) {
|
owner: function(next) {
|
||||||
|
|||||||
@@ -142,13 +142,12 @@ module.exports = function(SocketPosts) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('posts.' + command, result);
|
|
||||||
|
|
||||||
if (result && eventName) {
|
if (result && eventName) {
|
||||||
|
socket.emit('posts.' + command, result);
|
||||||
websockets.in(data.room_id).emit('event:' + eventName, result);
|
websockets.in(data.room_id).emit('event:' + eventName, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notification) {
|
if (result && notification) {
|
||||||
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, notification);
|
SocketPosts.sendNotificationToPostOwner(data.pid, socket.uid, notification);
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
Reference in New Issue
Block a user