|
|
|
@ -11,11 +11,6 @@ var batch = require('../batch');
|
|
|
|
|
|
|
|
|
|
module.exports = function (Topics) {
|
|
|
|
|
Topics.delete = function (tid, uid, callback) {
|
|
|
|
|
Topics.getTopicFields(tid, ['cid'], function (err, topicData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.setTopicFields(tid, {
|
|
|
|
@ -28,25 +23,35 @@ module.exports = function (Topics) {
|
|
|
|
|
db.sortedSetsRemove(['topics:recent', 'topics:posts', 'topics:views'], tid, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getPids(tid, function (err, pids) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
db.sortedSetRemove('cid:' + topicData.cid + ':pids', pids, next);
|
|
|
|
|
});
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
cid: function (next) {
|
|
|
|
|
Topics.getTopicField(tid, 'cid', next);
|
|
|
|
|
},
|
|
|
|
|
pids: function (next) {
|
|
|
|
|
Topics.getPids(tid, next);
|
|
|
|
|
},
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
db.sortedSetRemove('cid:' + results.cid + ':pids', results.pids, next);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
], function (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.restore = function (tid, uid, callback) {
|
|
|
|
|
Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], function (err, topicData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var topicData;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount', 'viewcount'], next);
|
|
|
|
|
},
|
|
|
|
|
function (_topicData, next) {
|
|
|
|
|
topicData = _topicData;
|
|
|
|
|
async.parallel([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.setTopicField(tid, 'deleted', 0, next);
|
|
|
|
@ -64,15 +69,14 @@ module.exports = function (Topics) {
|
|
|
|
|
db.sortedSetAdd('topics:views', topicData.viewcount, tid, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getPids(tid, function (err, pids) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], function (err, postData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getPids(tid, next);
|
|
|
|
|
},
|
|
|
|
|
function (pids, next) {
|
|
|
|
|
posts.getPostsFields(pids, ['pid', 'timestamp', 'deleted'], next);
|
|
|
|
|
},
|
|
|
|
|
function (postData, next) {
|
|
|
|
|
postData = postData.filter(function (post) {
|
|
|
|
|
return post && parseInt(post.deleted, 10) !== 1;
|
|
|
|
|
});
|
|
|
|
@ -83,13 +87,14 @@ module.exports = function (Topics) {
|
|
|
|
|
scores.push(post.timestamp);
|
|
|
|
|
});
|
|
|
|
|
db.sortedSetAdd('cid:' + topicData.cid + ':pids', scores, pidsToAdd, next);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
], function (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
});
|
|
|
|
|
next(err);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.purgePostsAndTopic = function (tid, uid, callback) {
|
|
|
|
@ -144,15 +149,15 @@ module.exports = function (Topics) {
|
|
|
|
|
function (next) {
|
|
|
|
|
reduceCounters(tid, next);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
], function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
plugins.fireHook('action:topic.purge', tid);
|
|
|
|
|
db.delete('topic:' + tid, callback);
|
|
|
|
|
next(err);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('action:topic.purge', tid);
|
|
|
|
|
db.delete('topic:' + tid, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function deleteFromFollowersIgnorers(tid, callback) {
|
|
|
|
@ -176,10 +181,11 @@ module.exports = function (Topics) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteTopicFromCategoryAndUser(tid, callback) {
|
|
|
|
|
Topics.getTopicFields(tid, ['cid', 'uid'], function (err, topicData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getTopicFields(tid, ['cid', 'uid'], next);
|
|
|
|
|
},
|
|
|
|
|
function (topicData, next) {
|
|
|
|
|
async.parallel([
|
|
|
|
|
function (next) {
|
|
|
|
|
db.sortedSetsRemove([
|
|
|
|
@ -193,7 +199,10 @@ module.exports = function (Topics) {
|
|
|
|
|
function (next) {
|
|
|
|
|
user.decrementUserFieldBy(topicData.uid, 'topiccount', 1, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
], function (err) {
|
|
|
|
|
callback(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -204,10 +213,11 @@ module.exports = function (Topics) {
|
|
|
|
|
db.incrObjectFieldBy('global', 'topicCount', incr, next);
|
|
|
|
|
},
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getTopicFields(tid, ['cid', 'postcount'], function (err, topicData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Topics.getTopicFields(tid, ['cid', 'postcount'], next);
|
|
|
|
|
},
|
|
|
|
|
function (topicData, next) {
|
|
|
|
|
topicData.postcount = parseInt(topicData.postcount, 10);
|
|
|
|
|
topicData.postcount = topicData.postcount || 0;
|
|
|
|
|
var postCountChange = incr * topicData.postcount;
|
|
|
|
@ -223,7 +233,8 @@ module.exports = function (Topics) {
|
|
|
|
|
db.incrObjectFieldBy('category:' + topicData.cid, 'topic_count', incr, next);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|
|
|
|
|