mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
action:post.upvote / action:post.downvote now sends current status; new: action:post.unvote
This commit is contained in:
@@ -122,7 +122,7 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Favourites.upvote = function(pid, uid, callback) {
|
Favourites.upvote = function(pid, uid, commmand, callback) {
|
||||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
||||||
return callback(new Error('[[error:reputation-system-disabled]]'));
|
return callback(new Error('[[error:reputation-system-disabled]]'));
|
||||||
}
|
}
|
||||||
@@ -131,16 +131,12 @@ var async = require('async'),
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
plugins.fireHook('action:post.upvote', {
|
|
||||||
pid: pid,
|
|
||||||
uid: uid
|
|
||||||
});
|
|
||||||
|
|
||||||
callback(null, votes);
|
callback(null, votes);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Favourites.downvote = function(pid, uid, callback) {
|
Favourites.downvote = function(pid, uid, command, callback) {
|
||||||
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
|
||||||
return callback(new Error('[[error:reputation-system-disabled]]'));
|
return callback(new Error('[[error:reputation-system-disabled]]'));
|
||||||
}
|
}
|
||||||
@@ -162,17 +158,14 @@ var async = require('async'),
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
plugins.fireHook('action:post.downvote', {
|
|
||||||
pid: pid,
|
|
||||||
uid: uid
|
|
||||||
});
|
|
||||||
callback(null, votes);
|
callback(null, votes);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function toggleVote(type, pid, uid, callback) {
|
function toggleVote(type, pid, uid, callback) {
|
||||||
Favourites.unvote(pid, uid, function(err) {
|
Favourites.unvote(pid, uid, type, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
@@ -181,24 +174,43 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Favourites.unvote = function(pid, uid, callback) {
|
Favourites.unvote = function(pid, uid, command, callback) {
|
||||||
Favourites.hasVoted(pid, uid, function(err, voteStatus) {
|
Favourites.hasVoted(pid, uid, function(err, voteStatus) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hook,
|
||||||
|
current = voteStatus.upvoted ? 'upvote' : 'downvote';
|
||||||
|
|
||||||
|
if (voteStatus.upvoted && command === 'downvote' || voteStatus.downvoted && command === 'upvote') {
|
||||||
|
hook = command;
|
||||||
|
} else if (voteStatus.upvoted || voteStatus.downvoted) {
|
||||||
|
hook = 'unvote';
|
||||||
|
} else {
|
||||||
|
hook = command;
|
||||||
|
current = 'unvote';
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.fireHook('action:post.' + hook, {
|
||||||
|
pid: pid,
|
||||||
|
uid: uid,
|
||||||
|
current: current
|
||||||
|
});
|
||||||
|
|
||||||
if (!voteStatus || (!voteStatus.upvoted && !voteStatus.downvoted)) {
|
if (!voteStatus || (!voteStatus.upvoted && !voteStatus.downvoted)) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
vote(voteStatus.upvoted ? 'downvote' : 'upvote', true, pid, uid, callback);
|
vote(voteStatus.upvoted ? 'downvote' : 'upvote', true, pid, uid, callback);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
Favourites.hasVoted = function(pid, uid, callback) {
|
Favourites.hasVoted = function(pid, uid, callback) {
|
||||||
if (!parseInt(uid, 10)) {
|
if (!parseInt(uid, 10)) {
|
||||||
return callback(null, {upvoted: false, downvoted: false});
|
return callback(null, {upvoted: false, downvoted: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function(err, hasVoted) {
|
db.isMemberOfSets(['pid:' + pid + ':upvote', 'pid:' + pid + ':downvote'], uid, function(err, hasVoted) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -231,11 +243,11 @@ var async = require('async'),
|
|||||||
}, callback);
|
}, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Favourites.favourite = function (pid, uid, callback) {
|
Favourites.favourite = function (pid, uid, command, callback) {
|
||||||
toggleFavourite('favourite', pid, uid, callback);
|
toggleFavourite('favourite', pid, uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
Favourites.unfavourite = function(pid, uid, callback) {
|
Favourites.unfavourite = function(pid, uid, command, callback) {
|
||||||
toggleFavourite('unfavourite', pid, uid, callback);
|
toggleFavourite('unfavourite', pid, uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ function favouriteCommand(command, eventName, socket, data, callback) {
|
|||||||
return callback(new Error('[[error:post-deleted]]'));
|
return callback(new Error('[[error:post-deleted]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
favourites[command](data.pid, socket.uid, function(err, result) {
|
favourites[command](data.pid, socket.uid, command, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user