mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 08:25:46 +01:00
closes #3779
This commit is contained in:
@@ -26,13 +26,13 @@ var async = require('async'),
|
|||||||
|
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
if(type === 'upvote' && !unvote) {
|
if (type === 'upvote' && !unvote) {
|
||||||
db.sortedSetAdd('uid:' + uid + ':upvote', now, pid);
|
db.sortedSetAdd('uid:' + uid + ':upvote', now, pid);
|
||||||
} else {
|
} else {
|
||||||
db.sortedSetRemove('uid:' + uid + ':upvote', pid);
|
db.sortedSetRemove('uid:' + uid + ':upvote', pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type === 'upvote' || unvote) {
|
if (type === 'upvote' || unvote) {
|
||||||
db.sortedSetRemove('uid:' + uid + ':downvote', pid);
|
db.sortedSetRemove('uid:' + uid + ':downvote', pid);
|
||||||
} else {
|
} else {
|
||||||
db.sortedSetAdd('uid:' + uid + ':downvote', now, pid);
|
db.sortedSetAdd('uid:' + uid + ':downvote', now, pid);
|
||||||
@@ -213,7 +213,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
if (voteStatus.upvoted && command === 'downvote' || voteStatus.downvoted && command === 'upvote') { // e.g. User *has* upvoted, and clicks downvote
|
if (voteStatus.upvoted && command === 'downvote' || voteStatus.downvoted && command === 'upvote') { // e.g. User *has* upvoted, and clicks downvote
|
||||||
hook = command;
|
hook = command;
|
||||||
} else if (voteStatus.upvoted || voteStatus.downvoted) { // e.g. User *has* upvotes, clicks upvote (so we "unvote")
|
} else if (voteStatus.upvoted || voteStatus.downvoted) { // e.g. User *has* upvoted, clicks upvote (so we "unvote")
|
||||||
hook = 'unvote';
|
hook = 'unvote';
|
||||||
} else { // e.g. User *has not* voted, clicks upvote
|
} else { // e.g. User *has not* voted, clicks upvote
|
||||||
hook = command;
|
hook = command;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ var async = require('async'),
|
|||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
posts = require('../posts'),
|
posts = require('../posts'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
|
favourites = require('../favourites'),
|
||||||
groups = require('../groups'),
|
groups = require('../groups'),
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
batch = require('../batch');
|
batch = require('../batch');
|
||||||
@@ -21,12 +22,35 @@ module.exports = function(User) {
|
|||||||
function(next) {
|
function(next) {
|
||||||
deleteTopics(uid, next);
|
deleteTopics(uid, next);
|
||||||
},
|
},
|
||||||
|
function(next) {
|
||||||
|
deleteVotes(uid, next);
|
||||||
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
User.deleteAccount(uid, next);
|
User.deleteAccount(uid, next);
|
||||||
}
|
}
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function deleteVotes(uid, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
async.parallel({
|
||||||
|
upvotedPids: async.apply(db.getSortedSetRange, 'uid:' + uid + ':upvote', 0, -1),
|
||||||
|
downvotedPids: async.apply(db.getSortedSetRange, 'uid:' + uid + ':downvote', 0, -1)
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function (pids, next) {
|
||||||
|
pids = pids.upvotedPids.concat(pids.downvotedPids).filter(function(pid, index, array) {
|
||||||
|
return pid && array.indexOf(pid) === index;
|
||||||
|
});
|
||||||
|
|
||||||
|
async.eachLimit(pids, 50, function(pid, next) {
|
||||||
|
favourites.unvote(pid, uid, next);
|
||||||
|
}, next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
|
}
|
||||||
|
|
||||||
function deletePosts(uid, callback) {
|
function deletePosts(uid, callback) {
|
||||||
deleteSortedSetElements('uid:' + uid + ':posts', posts.purge, callback);
|
deleteSortedSetElements('uid:' + uid + ':posts', posts.purge, callback);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user