Skip to content

Node.js based forum software built for the modern web

closes #705

Baris Soner Usakli8cfb239aac78
diff --git a/public/src/modules/composer.js b/public/src/modules/composer.js
index c95a8ed508..077a7c3a01 100644
--- a/public/src/modules/composer.js
+++ b/public/src/modules/composer.js
@@ -340,6 +340,7 @@ define(['taskbar'], function(taskbar) {
}
}
+
composer.post = function(post_uuid) {
var postData = composer.posts[post_uuid],
postContainer = $('#cmp-uuid-' + post_uuid),
@@ -350,33 +351,13 @@ define(['taskbar'], function(taskbar) {
bodyEl.val(bodyEl.val().trim());
if(postData.uploadsInProgress && postData.uploadsInProgress.length) {
- return app.alert({
- type: 'warning',
- timeout: 2000,
- title: 'Still uploading',
- message: "Please wait for uploads to complete.",
- alert_id: 'post_error'
- });
- }
-
- if (titleEl.val().length < config.minimumTitleLength) {
- return app.alert({
- type: 'danger',
- timeout: 2000,
- title: 'Title too short',
- message: "Please enter a longer title. At least " + config.minimumTitleLength+ " characters.",
- alert_id: 'post_error'
- });
- }
-
- if (bodyEl.val().length < config.minimumPostLength) {
- return app.alert({
- type: 'danger',
- timeout: 2000,
- title: 'Content too short',
- message: "Please enter a longer post. At least " + config.minimumPostLength + " characters.",
- alert_id: 'post_error'
- });
+ return composerAlert('Still uploading', 'Please wait for uploads to complete.');
+ } else if (titleEl.val().length < parseInt(config.minimumTitleLength, 10)) {
+ return composerAlert('Title too short', 'Please enter a longer title. At least ' + config.minimumTitleLength+ ' characters.');
+ } else if (titleEl.val().length > parseInt(config.maximumTitleLength, 10)) {
+ return composerAlert('Title too long', 'Please enter a shorter title. Titles can\'t be longer than ' + config.maximumTitleLength + ' characters.');
+ } else if (bodyEl.val().length < parseInt(config.minimumPostLength, 10)) {
+ return composerAlert('Content too short', 'Please enter a longer post. At least ' + config.minimumPostLength + ' characters.');
}
// Still here? Let's post.
@@ -402,6 +383,17 @@ define(['taskbar'], function(taskbar) {
composer.discard(post_uuid);
}
+ function composerAlert(title, message) {
+ app.alert({
+ type: 'danger',
+ timeout: 2000,
+ title: title,
+ message: message,
+ alert_id: 'post_error'
+ });
+ }
+
+
composer.discard = function(post_uuid) {
if (composer.posts[post_uuid]) {
$('#cmp-uuid-' + post_uuid).remove();
diff --git a/src/install.js b/src/install.js
index b5c4d4b089..dbbb748f01 100644
--- a/src/install.js
+++ b/src/install.js
@@ -215,6 +215,9 @@ var async = require('async'),
}, {
field: 'minimumTitleLength',
value: 3
+ }, {
+ field: 'maximumTitleLength',
+ value: 255
}, {
field: 'minimumUsernameLength',
value: 2
diff --git a/src/posts.js b/src/posts.js
index 469d256927..200af7c452 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -356,25 +356,6 @@ var db = require('./database'),
});
}
- Posts.emitContentTooShortAlert = function(socket) {
- socket.emit('event:alert', {
- type: 'danger',
- timeout: 2000,
- title: 'Content too short',
- message: "Please enter a longer post. At least " + meta.config.minimumPostLength + " characters.",
- alert_id: 'post_error'
- });
- }
-
- Posts.emitTooManyPostsAlert = function(socket) {
- socket.emit('event:alert', {
- title: 'Too many posts!',
- message: 'You can only post every ' + meta.config.postDelay + ' seconds.',
- type: 'danger',
- timeout: 2000
- });
- }
-
Posts.uploadPostImage = function(image, callback) {
if(!image) {
diff --git a/src/routes/api.js b/src/routes/api.js
index 9051916188..623d654fbd 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -30,6 +30,7 @@ var path = require('path'),
config.postDelay = meta.config.postDelay;
config.minimumTitleLength = meta.config.minimumTitleLength;
+ config.maximumTitleLength = meta.config.maximumTitleLength;
config.minimumPostLength = meta.config.minimumPostLength;
config.imgurClientIDSet = !! meta.config.imgurClientID;
config.minimumUsernameLength = meta.config.minimumUsernameLength;
diff --git a/src/upgrade.js b/src/upgrade.js
index a506cff10b..f526491398 100644
--- a/src/upgrade.js
+++ b/src/upgrade.js
@@ -81,6 +81,33 @@ Upgrade.upgrade = function(callback) {
winston.info('[2013/12/31] Re-slugify Topics and Users skipped');
next();
}
+ },
+ function(next) {
+ thisSchemaDate = new Date(2014, 0, 1).getTime();
+ if (schemaDate < thisSchemaDate) {
+ updatesMade = true;
+
+ db.isObjectField('config', 'maximumTitleLength', function(err, isField) {
+ if(err) {
+ return next(err);
+ }
+ if(!isField) {
+ db.setObjectField('config', 'maximumTitleLength', 255, function(err) {
+ if(err) {
+ return next(err);
+ }
+ winston.info('[2013/12/31] Added maximumTitleLength');
+ next();
+ });
+ } else {
+ winston.info('[2013/12/31] maximumTitleLength already set');
+ next();
+ }
+ });
+ } else {
+ winston.info('[2013/12/31] maximumTitleLength skipped');
+ next();
+ }
}
// Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!
diff --git a/src/websockets.js b/src/websockets.js
index 310af2fbc9..1a16b76af7 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -362,6 +362,35 @@ websockets.init = function(io) {
}
});
+ function emitAlert(socket, title, message) {
+ socket.emit('event:alert', {
+ type: 'danger',
+ timeout: 2000,
+ title: title,
+ message: message,
+ alert_id: 'post_error'
+ });
+ }
+
+ function emitContentTooShortAlert(socket) {
+ socket.emit('event:alert', {
+ type: 'danger',
+ timeout: 2000,
+ title: 'Content too short',
+ message: "Please enter a longer post. At least " + meta.config.minimumPostLength + " characters.",
+ alert_id: 'post_error'
+ });
+ }
+
+ function emitTooManyPostsAlert(socket) {
+ socket.emit('event:alert', {
+ title: 'Too many posts!',
+ message: 'You can only post every ' + meta.config.postDelay + ' seconds.',
+ type: 'danger',
+ timeout: 2000
+ });
+ }
+
socket.on('api:topics.post', function(data) {
if (uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
socket.emit('event:alert', {
@@ -376,11 +405,13 @@ websockets.init = function(io) {
topics.post(uid, data.title, data.content, data.category_id, function(err, result) {
if(err) {
if (err.message === 'title-too-short') {
- topics.emitTitleTooShortAlert(socket);
+ emitAlert(socket, 'Title too short', 'Please enter a longer title. At least ' + meta.config.minimumTitleLength + ' characters.');
+ } else if (err.message === 'title-too-long') {
+ emitAlert(socket, 'Title too long', 'Please enter a shorter title. Titles can\'t be longer than ' + meta.config.maximumTitleLength + ' characters.');
} else if (err.message === 'content-too-short') {
- posts.emitContentTooShortAlert(socket);
+ emitContentTooShortAlert(socket);
} else if (err.message === 'too-many-posts') {
- posts.emitTooManyPostsAlert(socket);
+ emitTooManyPostsAlert(socket);
} else if (err.message === 'no-privileges') {
socket.emit('event:alert', {
title: 'Unable to post',
@@ -445,16 +476,16 @@ websockets.init = function(io) {
}
if (Date.now() - lastPostTime < meta.config.postDelay * 1000) {
- posts.emitTooManyPostsAlert(socket);
+ emitTooManyPostsAlert(socket);
return;
}
topics.reply(data.topic_id, uid, data.content, function(err, postData) {
if(err) {
if (err.message === 'content-too-short') {
- posts.emitContentTooShortAlert(socket);
+ emitContentTooShortAlert(socket);
} else if (err.message === 'too-many-posts') {
- posts.emitTooManyPostsAlert(socket);
+ emitTooManyPostsAlert(socket);
} else if (err.message === 'reply-error') {
socket.emit('event:alert', {
title: 'Reply Unsuccessful',
@@ -628,7 +659,7 @@ websockets.init = function(io) {
topics.emitTitleTooShortAlert(socket);
return;
} else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) {
- posts.emitContentTooShortAlert(socket);
+ emitContentTooShortAlert(socket);
return;
}