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;
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) {
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) {
Posts.flag = function(pid, callback) {
async.parallel([
function(next) {
db.sortedSetAdd('posts:flagged', Date.now(), pid, next);
},
function(next) {
db.incrObjectField('post:' + pid, 'flags', next);
Posts.exists(pid, function(err, exists) {
if (err || !exists) {
return callback(err || new Error('[[error:no-post]]'));
}
], 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;
async.waterfall([
function(next) {
posts.flag(pid, next);
},
function(next) {
user.getUserFields(socket.uid, ['username', 'reputation'], next);
},
@ -323,7 +326,7 @@ SocketPosts.flag = function(socket, pid, callback) {
},
function(topicTitle, next) {
message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topicTitle + ']]';
postTools.parse(post, socket.uid, next);
postTools.parsePost(post, socket.uid, next);
},
function(post, next) {
groups.get('administrators', {}, next);
@ -342,9 +345,6 @@ SocketPosts.flag = function(socket, pid, callback) {
notifications.push(notification, adminGroup.members, next);
});
},
function(next) {
posts.flag(pid, next);
},
function(next) {
if (!parseInt(post.uid, 10)) {
return next();

Loading…
Cancel
Save