fix flagging and post filter

cant flag posts that don't exist anymore
v1.18.x
barisusakli 10 years ago
parent 11dc477dde
commit d2cddc734b

@ -113,7 +113,9 @@ var async = require('async'),
data.pid = pid; data.pid = pid;
plugins.fireHook('filter:post.getFields', {posts: [data], fields: fields}, callback); plugins.fireHook('filter:post.getFields', {posts: [data], fields: fields}, function(err, data) {
callback(err, (data && Array.isArray(data.posts) && data.posts.length) ? data.posts[0] : null);
});
}); });
}; };
@ -130,7 +132,9 @@ var async = require('async'),
if (err) { if (err) {
return callback(err); return callback(err);
} }
plugins.fireHook('filter:post.getFields', {posts: posts, fields: fields}, callback); plugins.fireHook('filter:post.getFields', {posts: posts, fields: fields}, function(err, data) {
callback(err, (data && Array.isArray(data.posts)) ? data.posts : null);
});
}); });
}; };

@ -8,15 +8,21 @@ var async = require('async'),
module.exports = function(Posts) { module.exports = function(Posts) {
Posts.flag = function(pid, callback) { Posts.flag = function(pid, callback) {
async.parallel([ Posts.exists(pid, function(err, exists) {
function(next) { if (err || !exists) {
db.sortedSetAdd('posts:flagged', Date.now(), pid, next); return callback(err || new Error('[[error:no-post]]'));
},
function(next) {
db.incrObjectField('post:' + pid, 'flags', next);
} }
], function(err, results) {
callback(err); async.parallel([
function(next) {
db.sortedSetAdd('posts:flagged', Date.now(), pid, next);
},
function(next) {
db.incrObjectField('post:' + pid, 'flags', next);
}
], function(err, results) {
callback(err);
});
}); });
}; };

@ -303,6 +303,9 @@ SocketPosts.flag = function(socket, pid, callback) {
post; post;
async.waterfall([ async.waterfall([
function(next) {
posts.flag(pid, next);
},
function(next) { function(next) {
user.getUserFields(socket.uid, ['username', 'reputation'], next); user.getUserFields(socket.uid, ['username', 'reputation'], next);
}, },
@ -323,7 +326,7 @@ SocketPosts.flag = function(socket, pid, callback) {
}, },
function(topicTitle, next) { function(topicTitle, next) {
message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topicTitle + ']]'; message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topicTitle + ']]';
postTools.parse(post, socket.uid, next); postTools.parsePost(post, socket.uid, next);
}, },
function(post, next) { function(post, next) {
groups.get('administrators', {}, next); groups.get('administrators', {}, next);
@ -342,9 +345,6 @@ SocketPosts.flag = function(socket, pid, callback) {
notifications.push(notification, adminGroup.members, next); notifications.push(notification, adminGroup.members, next);
}); });
}, },
function(next) {
posts.flag(pid, next);
},
function(next) { function(next) {
if (!parseInt(post.uid, 10)) { if (!parseInt(post.uid, 10)) {
return next(); return next();

Loading…
Cancel
Save