v1.18.x
barisusakli 8 years ago
parent 8a3c72797b
commit 1b34ebe230

@ -464,7 +464,7 @@ var utils = require('../public/src/utils');
notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]'; notifications[modifyIndex].bodyShort = '[[' + mergeId + '_multiple, ' + usernames[0] + ', ' + (numUsers - 1) + titleEscaped + ']]';
} }
notifications[modifyIndex].path = set[set.length - 1].path; notifications[modifyIndex].path = set[0].path;
break; break;
case 'new_register': case 'new_register':

@ -6,6 +6,7 @@ var _ = require('underscore');
var db = require('../database'); var db = require('../database');
var topics = require('../topics'); var topics = require('../topics');
var user = require('../user'); var user = require('../user');
var notifications = require('../notifications');
var plugins = require('../plugins'); var plugins = require('../plugins');
module.exports = function (Posts) { module.exports = function (Posts) {
@ -126,7 +127,7 @@ module.exports = function (Posts) {
function (data, next) { function (data, next) {
async.parallel([ async.parallel([
function (next) { function (next) {
deletePostFromTopicAndUser(pid, next); deletePostFromTopicUserNotification(pid, next);
}, },
function (next) { function (next) {
deletePostFromCategoryRecentPosts(pid, next); deletePostFromCategoryRecentPosts(pid, next);
@ -138,18 +139,7 @@ module.exports = function (Posts) {
deletePostFromUsersVotes(pid, next); deletePostFromUsersVotes(pid, next);
}, },
function (next) { function (next) {
Posts.getPostField(pid, 'toPid', function (err, toPid) { deletePostFromReplies(pid, next);
if (err) {
return next(err);
}
if (!parseInt(toPid, 10)) {
return next(null);
}
async.parallel([
async.apply(db.sortedSetRemove, 'pid:' + toPid + ':replies', pid),
async.apply(db.decrObjectField, 'post:' + toPid, 'replies')
], next);
});
}, },
function (next) { function (next) {
db.sortedSetsRemove(['posts:pid', 'posts:flagged'], pid, next); db.sortedSetsRemove(['posts:pid', 'posts:flagged'], pid, next);
@ -168,54 +158,56 @@ module.exports = function (Posts) {
], callback); ], callback);
}; };
function deletePostFromTopicAndUser(pid, callback) { function deletePostFromTopicUserNotification(pid, callback) {
Posts.getPostFields(pid, ['tid', 'uid'], function (err, postData) { var postData;
if (err) { async.waterfall([
return callback(err); function (next) {
} Posts.getPostFields(pid, ['tid', 'uid'], next);
},
db.sortedSetsRemove([ function (_postData, next) {
'tid:' + postData.tid + ':posts', postData = _postData;
'tid:' + postData.tid + ':posts:votes', db.sortedSetsRemove([
'uid:' + postData.uid + ':posts' 'tid:' + postData.tid + ':posts',
], pid, function (err) { 'tid:' + postData.tid + ':posts:votes',
if (err) { 'uid:' + postData.uid + ':posts'
return callback(err); ], pid, next);
} },
function (next) {
topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], function (err, topicData) { topics.getTopicFields(postData.tid, ['tid', 'cid', 'pinned'], next);
if (err) { },
return callback(err); function (topicData, next) {
async.parallel([
function (next) {
db.decrObjectField('global', 'postCount', next);
},
function (next) {
db.decrObjectField('category:' + topicData.cid, 'post_count', next);
},
function (next) {
topics.decreasePostCount(postData.tid, next);
},
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);
},
function (next) {
db.sortedSetIncrBy('tid:' + postData.tid + ':posters', -1, postData.uid, next);
},
function (next) {
user.incrementUserPostCountBy(postData.uid, -1, next);
},
function (next) {
notifications.rescind('new_post:tid:' + postData.tid + ':pid:' + pid + ':uid:' + postData.uid, next);
} }
], next);
async.parallel([ }
function (next) { ], function (err) {
db.decrObjectField('global', 'postCount', next); callback(err);
},
function (next) {
db.decrObjectField('category:' + topicData.cid, 'post_count', next);
},
function (next) {
topics.decreasePostCount(postData.tid, next);
},
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);
},
function (next) {
db.sortedSetIncrBy('tid:' + postData.tid + ':posters', -1, postData.uid, next);
},
function (next) {
user.incrementUserPostCountBy(postData.uid, -1, next);
}
], callback);
});
});
}); });
} }
@ -288,4 +280,20 @@ module.exports = function (Posts) {
}); });
} }
function deletePostFromReplies(pid, callback) {
Posts.getPostField(pid, 'toPid', function (err, toPid) {
if (err) {
return callback(err);
}
if (!parseInt(toPid, 10)) {
return callback(null);
}
async.parallel([
async.apply(db.sortedSetRemove, 'pid:' + toPid + ':replies', pid),
async.apply(db.decrObjectField, 'post:' + toPid, 'replies')
], callback);
});
}
}; };

Loading…
Cancel
Save