From f6be4efe8bb881cb0cb5a1dfccb294dfb0950afe Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 4 Aug 2015 14:25:56 -0400 Subject: [PATCH] when a post is moved update recent topics order --- src/topics/fork.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/topics/fork.js b/src/topics/fork.js index 3302797f38..34eb758300 100644 --- a/src/topics/fork.js +++ b/src/topics/fork.js @@ -44,7 +44,7 @@ module.exports = function(Topics) { if (err) { return callback(err); } - + Topics.create({uid: results.postData.uid, title: title, cid: results.cid}, function(err, tid) { if (err) { return callback(err); @@ -94,7 +94,7 @@ module.exports = function(Topics) { } if (parseInt(post.tid, 10) === parseInt(tid, 10)) { - return next(new Error('[[error:cant-move-to-same-topic]]')) + return next(new Error('[[error:cant-move-to-same-topic]]')); } postData = post; @@ -117,6 +117,12 @@ module.exports = function(Topics) { Topics.addPostToTopic(tid, pid, postData.timestamp, postData.votes, next); } ], next); + }, + function(results, next) { + async.parallel([ + async.apply(updateRecentTopic, tid), + async.apply(updateRecentTopic, postData.tid) + ], next); } ], function(err) { if (err) { @@ -126,4 +132,23 @@ module.exports = function(Topics) { callback(); }); }; + + function updateRecentTopic(tid, callback) { + async.waterfall([ + function(next) { + Topics.getLatestUndeletedPid(tid, next); + }, + function(pid, next) { + if (!pid) { + return callback(); + } + posts.getPostField(pid, 'timestamp', next); + }, + function(timestamp, next) { + Topics.updateTimestamp(tid, timestamp, next); + } + ], callback); + } + + };