From 2579d2535d8afc93b40e43dc11ee7b4409434554 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 11 Nov 2014 20:10:51 -0500 Subject: [PATCH] closes #2396 --- src/topics.js | 4 ++-- src/topics/create.js | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/topics.js b/src/topics.js index 807138286d..630425fe25 100644 --- a/src/topics.js +++ b/src/topics.js @@ -69,7 +69,7 @@ var async = require('async'), return callback(null, 1); } user.getSettings(uid, function(err, settings) { - if(err) { + if (err) { return callback(err); } @@ -253,7 +253,7 @@ var async = require('async'), Topics.addPostData(posts, uid, next); }); }); - }, + }, category: async.apply(Topics.getCategoryData, tid), threadTools: async.apply(plugins.fireHook, 'filter:topic.thread_tools', []), tags: async.apply(Topics.getTopicTagsObjects, tid), diff --git a/src/topics/create.js b/src/topics/create.js index 2f8bf088be..d1b2428e0c 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -103,11 +103,14 @@ module.exports = function(Topics) { if (!title || title.length < parseInt(meta.config.minimumTitleLength, 10)) { return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]')); - } else if(title.length > parseInt(meta.config.maximumTitleLength, 10)) { + } else if (title.length > parseInt(meta.config.maximumTitleLength, 10)) { return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]')); } async.waterfall([ + function(next) { + checkContentLength(content, next); + }, function(next) { categories.exists(cid, next); }, @@ -220,11 +223,10 @@ module.exports = function(Topics) { content = content.trim(); } - if (!content || content.length < parseInt(meta.config.miminumPostLength, 10)) { - return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]')); - } - - posts.create({uid:uid, tid:tid, content:content, toPid:toPid}, next); + checkContentLength(content, next); + }, + function(next) { + posts.create({uid: uid, tid: tid, content: content, toPid: toPid}, next); }, function(data, next) { postData = data; @@ -277,4 +279,11 @@ module.exports = function(Topics) { ], callback); }; + function checkContentLength(content, callback) { + if (!content || content.length < parseInt(meta.config.miminumPostLength, 10)) { + return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]')); + } + callback(); + } + };