mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 11:11:04 +01:00
closes #5831
This commit is contained in:
@@ -59,6 +59,25 @@ module.exports = function (Categories) {
|
|||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Categories.updateRecentTidForCid = function (cid, callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getSortedSetRevRange('cid:' + cid + ':pids', 0, 0, next);
|
||||||
|
},
|
||||||
|
function (pid, next) {
|
||||||
|
pid = pid[0];
|
||||||
|
posts.getPostField(pid, 'tid', next);
|
||||||
|
},
|
||||||
|
function (tid, next) {
|
||||||
|
if (!parseInt(tid, 10)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
Categories.updateRecentTid(cid, tid, next);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
Categories.getRecentTopicReplies = function (categoryData, uid, callback) {
|
Categories.getRecentTopicReplies = function (categoryData, uid, callback) {
|
||||||
if (!Array.isArray(categoryData) || !categoryData.length) {
|
if (!Array.isArray(categoryData) || !categoryData.length) {
|
||||||
return callback();
|
return callback();
|
||||||
@@ -180,8 +199,11 @@ module.exports = function (Categories) {
|
|||||||
|
|
||||||
Categories.moveRecentReplies = function (tid, oldCid, cid, callback) {
|
Categories.moveRecentReplies = function (tid, oldCid, cid, callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
updatePostCount(tid, oldCid, cid);
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
updatePostCount(tid, oldCid, cid, next);
|
||||||
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
topics.getPids(tid, next);
|
topics.getPids(tid, next);
|
||||||
},
|
},
|
||||||
@@ -212,7 +234,6 @@ module.exports = function (Categories) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function updatePostCount(tid, oldCid, newCid, callback) {
|
function updatePostCount(tid, oldCid, newCid, callback) {
|
||||||
callback = callback || function () {};
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
topics.getTopicField(tid, 'postcount', next);
|
topics.getTopicField(tid, 'postcount', next);
|
||||||
@@ -228,7 +249,9 @@ module.exports = function (Categories) {
|
|||||||
function (next) {
|
function (next) {
|
||||||
db.incrObjectFieldBy('category:' + newCid, 'post_count', postCount, next);
|
db.incrObjectFieldBy('category:' + newCid, 'post_count', postCount, next);
|
||||||
},
|
},
|
||||||
], next);
|
], function (err) {
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ module.exports = function (Topics) {
|
|||||||
|
|
||||||
Topics[isDelete ? 'delete' : 'restore'](tid, uid, next);
|
Topics[isDelete ? 'delete' : 'restore'](tid, uid, next);
|
||||||
},
|
},
|
||||||
|
function (next) {
|
||||||
|
categories.updateRecentTidForCid(topicData.cid, next);
|
||||||
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
topicData.deleted = isDelete ? 1 : 0;
|
topicData.deleted = isDelete ? 1 : 0;
|
||||||
|
|
||||||
@@ -261,7 +264,8 @@ module.exports = function (Topics) {
|
|||||||
db.sortedSetsRemove([
|
db.sortedSetsRemove([
|
||||||
'cid:' + topicData.cid + ':tids',
|
'cid:' + topicData.cid + ':tids',
|
||||||
'cid:' + topicData.cid + ':tids:pinned',
|
'cid:' + topicData.cid + ':tids:pinned',
|
||||||
'cid:' + topicData.cid + ':tids:posts', // post count
|
'cid:' + topicData.cid + ':tids:posts',
|
||||||
|
'cid:' + topicData.cid + ':recent_tids',
|
||||||
], tid, next);
|
], tid, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -283,8 +287,9 @@ module.exports = function (Topics) {
|
|||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
oldCid = topic.cid;
|
oldCid = topic.cid;
|
||||||
categories.moveRecentReplies(tid, oldCid, cid);
|
categories.moveRecentReplies(tid, oldCid, cid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
async.parallel([
|
async.parallel([
|
||||||
function (next) {
|
function (next) {
|
||||||
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1, next);
|
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1, next);
|
||||||
@@ -292,6 +297,12 @@ module.exports = function (Topics) {
|
|||||||
function (next) {
|
function (next) {
|
||||||
categories.incrementCategoryFieldBy(cid, 'topic_count', 1, next);
|
categories.incrementCategoryFieldBy(cid, 'topic_count', 1, next);
|
||||||
},
|
},
|
||||||
|
function (next) {
|
||||||
|
categories.updateRecentTid(cid, tid, next);
|
||||||
|
},
|
||||||
|
function (next) {
|
||||||
|
categories.updateRecentTidForCid(oldCid, next);
|
||||||
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
Topics.setTopicFields(tid, {
|
Topics.setTopicFields(tid, {
|
||||||
cid: cid,
|
cid: cid,
|
||||||
|
|||||||
Reference in New Issue
Block a user