mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-02 22:00:34 +01:00
closes #4955
This commit is contained in:
@@ -32,7 +32,7 @@ module.exports = function(Topics) {
|
||||
db.sortedSetRemove('cid:' + topicData.cid + ':pids', pids, next);
|
||||
});
|
||||
}
|
||||
], function(err, results) {
|
||||
], function(err) {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
@@ -79,7 +79,7 @@ module.exports = function(Topics) {
|
||||
});
|
||||
});
|
||||
}
|
||||
], function(err, results) {
|
||||
], function(err) {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
@@ -109,28 +109,35 @@ module.exports = function(Topics) {
|
||||
};
|
||||
|
||||
Topics.purge = function(tid, uid, callback) {
|
||||
async.parallel([
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.deleteAll([
|
||||
'tid:' + tid + ':followers',
|
||||
'tid:' + tid + ':ignorers',
|
||||
'tid:' + tid + ':posts',
|
||||
'tid:' + tid + ':posts:votes',
|
||||
'tid:' + tid + ':bookmarks',
|
||||
'tid:' + tid + ':posters'
|
||||
deleteFromFollowersIgnorers(tid, next);
|
||||
},
|
||||
function(next) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
db.deleteAll([
|
||||
'tid:' + tid + ':followers',
|
||||
'tid:' + tid + ':ignorers',
|
||||
'tid:' + tid + ':posts',
|
||||
'tid:' + tid + ':posts:votes',
|
||||
'tid:' + tid + ':bookmarks',
|
||||
'tid:' + tid + ':posters'
|
||||
], next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetsRemove(['topics:tid', 'topics:recent', 'topics:posts', 'topics:views'], tid, next);
|
||||
},
|
||||
function(next) {
|
||||
deleteTopicFromCategoryAndUser(tid, next);
|
||||
},
|
||||
function(next) {
|
||||
Topics.deleteTopicTags(tid, next);
|
||||
},
|
||||
function(next) {
|
||||
reduceCounters(tid, next);
|
||||
}
|
||||
], next);
|
||||
},
|
||||
function(next) {
|
||||
db.sortedSetsRemove(['topics:tid', 'topics:recent', 'topics:posts', 'topics:views'], tid, next);
|
||||
},
|
||||
function(next) {
|
||||
deleteTopicFromCategoryAndUser(tid, next);
|
||||
},
|
||||
function(next) {
|
||||
Topics.deleteTopicTags(tid, next);
|
||||
},
|
||||
function(next) {
|
||||
reduceCounters(tid, next);
|
||||
}
|
||||
], function(err) {
|
||||
if (err) {
|
||||
@@ -141,6 +148,26 @@ module.exports = function(Topics) {
|
||||
});
|
||||
};
|
||||
|
||||
function deleteFromFollowersIgnorers(tid, callback) {
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
async.parallel({
|
||||
followers: async.apply(db.getSetMembers, 'tid:' + tid + ':followers'),
|
||||
ignorers: async.apply(db.getSetMembers, 'tid:' + tid + ':ignorers')
|
||||
}, next);
|
||||
},
|
||||
function(results, next) {
|
||||
var followerKeys = results.followers.map(function(uid) {
|
||||
return 'uid:' + uid + ':followed_tids';
|
||||
});
|
||||
var ignorerKeys = results.ignorers.map(function(uid) {
|
||||
return 'uid:' + uid + 'ignored_tids';
|
||||
});
|
||||
db.sortedSetsRemove(followerKeys.concat(ignorerKeys), tid, next);
|
||||
}
|
||||
], callback);
|
||||
}
|
||||
|
||||
function deleteTopicFromCategoryAndUser(tid, callback) {
|
||||
Topics.getTopicFields(tid, ['cid', 'uid'], function(err, topicData) {
|
||||
if (err) {
|
||||
|
||||
@@ -188,12 +188,24 @@ describe('Topic\'s', function() {
|
||||
|
||||
describe('.purge/.delete', function() {
|
||||
var newTopic;
|
||||
|
||||
var followerUid;
|
||||
before(function(done) {
|
||||
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
||||
newTopic = result.topicData;
|
||||
done();
|
||||
});
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
topics.post({uid: topic.userId, title: topic.title, content: topic.content, cid: topic.categoryId}, function(err, result) {
|
||||
assert.ifError(err);
|
||||
newTopic = result.topicData;
|
||||
next();
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
User.create({username: 'topicFollower', password: '123456'}, next);
|
||||
},
|
||||
function(_uid, next) {
|
||||
followerUid = _uid;
|
||||
topics.follow(newTopic.tid, _uid, next);
|
||||
}
|
||||
], done);
|
||||
});
|
||||
|
||||
it('should delete the topic', function(done) {
|
||||
@@ -206,7 +218,11 @@ describe('Topic\'s', function() {
|
||||
it('should purge the topic', function(done) {
|
||||
topics.purge(newTopic.tid, 1, function(err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
db.isSortedSetMember('uid:' + followerUid + ':followed_tids', newTopic.tid, function(err, isMember) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(false, isMember);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user