Skip to content

Node.js based forum software built for the modern web

closes #4632

barisusaklif9f4b3b91f09
diff --git a/src/posts/delete.js b/src/posts/delete.js
index 40b6554b6f..e28f3f8e36 100644
--- a/src/posts/delete.js
+++ b/src/posts/delete.js
@@ -24,15 +24,15 @@ module.exports = function(Posts) {
},
function (_post, next) {
postData = _post;
- topics.getTopicField(_post.tid, 'cid', next);
+ topics.getTopicFields(_post.tid, ['tid', 'cid', 'pinned'], next);
},
- function (cid, next) {
+ function (topicData, next) {
async.parallel([
function(next) {
- updateTopicTimestamp(postData.tid, next);
+ updateTopicTimestamp(topicData, next);
},
function(next) {
- db.sortedSetRemove('cid:' + cid + ':pids', pid, next);
+ db.sortedSetRemove('cid:' + topicData.cid + ':pids', pid, next);
},
function(next) {
Posts.dismissFlag(pid, next);
@@ -40,10 +40,11 @@ module.exports = function(Posts) {
function(next) {
topics.updateTeaser(postData.tid, next);
}
- ], function(err) {
- plugins.fireHook('action:post.delete', pid);
- next(err, postData);
- });
+ ], next);
+ },
+ function (results, next) {
+ plugins.fireHook('action:post.delete', pid);
+ next(null, postData);
}
], callback);
};
@@ -62,45 +63,56 @@ module.exports = function(Posts) {
},
function (_post, next) {
postData = _post;
- topics.getTopicField(_post.tid, 'cid', next);
+ topics.getTopicFields(_post.tid, ['tid', 'cid', 'pinned'], next);
},
- function (cid, next) {
- postData.cid = cid;
+ function (topicData, next) {
+ postData.cid = topicData.cid;
async.parallel([
function(next) {
- updateTopicTimestamp(postData.tid, next);
+ updateTopicTimestamp(topicData, next);
},
function(next) {
- db.sortedSetAdd('cid:' + cid + ':pids', postData.timestamp, pid, next);
+ db.sortedSetAdd('cid:' + topicData.cid + ':pids', postData.timestamp, pid, next);
},
function(next) {
topics.updateTeaser(postData.tid, next);
}
- ], function(err) {
- plugins.fireHook('action:post.restore', _.clone(postData));
- next(err, postData);
- });
+ ], next);
+ },
+ function (results, next) {
+ plugins.fireHook('action:post.restore', _.clone(postData));
+ next(null, postData);
}
], callback);
};
- function updateTopicTimestamp(tid, callback) {
- topics.getLatestUndeletedPid(tid, function(err, pid) {
- if(err || !pid) {
- return callback(err);
- }
-
- Posts.getPostField(pid, 'timestamp', function(err, timestamp) {
- if (err) {
- return callback(err);
+ function updateTopicTimestamp(topicData, callback) {
+ var timestamp;
+ async.waterfall([
+ function (next) {
+ topics.getLatestUndeletedPid(topicData.tid, next);
+ },
+ function (pid, next) {
+ if (!parseInt(pid, 10)) {
+ return callback();
}
-
- if (timestamp) {
- return topics.updateTimestamp(tid, timestamp, callback);
+ Posts.getPostField(pid, 'timestamp', next);
+ },
+ function (_timestamp, next) {
+ timestamp = _timestamp;
+ if (!parseInt(timestamp, 10)) {
+ return callback();
}
- callback();
- });
- });
+ topics.updateTimestamp(topicData.tid, timestamp, next);
+ },
+ function (next) {
+ if (parseInt(topicData.pinned, 10) !== 1) {
+ db.sortedSetAdd('cid:' + topicData.cid + ':tids', timestamp, topicData.tid, next);
+ } else {
+ next();
+ }
+ }
+ ], callback);
}
Posts.purge = function(pid, uid, callback) {
@@ -160,7 +172,7 @@ module.exports = function(Posts) {
return callback(err);
}
- topics.getTopicFields(postData.tid, ['cid'], function(err, topicData) {
+ topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], function(err, topicData) {
if (err) {
return callback(err);
}
@@ -178,6 +190,9 @@ module.exports = function(Posts) {
function(next) {
topics.updateTeaser(postData.tid, next);
},
+ function (next) {
+ updateTopicTimestamp(topicData, next);
+ },
function(next) {
db.sortedSetIncrBy('cid:' + topicData.cid + ':tids:posts', -1, postData.tid, next);
},