Node.js based forum software built for the modern web
fix flagging and post filter
barisusaklid2cddc734b1a
diff --git a/src/posts.js b/src/posts.jsindex 33c6ce4657..9a66c3d5ec 100644--- a/src/posts.js+++ b/src/posts.js@@ -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);+ });});};diff --git a/src/posts/flags.js b/src/posts/flags.jsindex 20614b75be..638163e9b8 100644--- a/src/posts/flags.js+++ b/src/posts/flags.js@@ -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);+ });});};diff --git a/src/socket.io/posts.js b/src/socket.io/posts.jsindex 310099ae75..6db4f4b762 100644--- a/src/socket.io/posts.js+++ b/src/socket.io/posts.js@@ -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();