v1.18.x
barisusakli 9 years ago
parent 3fe786e737
commit f9f4b3b91f

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

Loading…
Cancel
Save