Skip to content

Node.js based forum software built for the modern web

content length changes

Baris Soner Usakli65029ae169d3
diff --git a/src/posts.js b/src/posts.js
index 9fb37cc0fe..660ba6945e 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -15,6 +15,8 @@ marked.setOptions({
(function(Posts) {
+ Posts.minimumPostLength = 8;
+
Posts.getPostsByTid = function(tid, start, end, callback) {
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
@@ -171,6 +173,16 @@ marked.setOptions({
});
}
+ Posts.emitContentTooShortAlert = function(socket) {
+ socket.emit('event:alert', {
+ type: 'error',
+ timeout: 2000,
+ title: 'Content too short',
+ message: "Please enter a longer post.",
+ alert_id: 'post_error'
+ });
+ }
+
Posts.reply = function(socket, tid, uid, content) {
if (uid < 1) {
socket.emit('event:alert', {
@@ -180,14 +192,8 @@ marked.setOptions({
timeout: 2000
});
return;
- } else if (!content || content.length <= 9) {
- socket.emit('event:alert', {
- type: 'error',
- timeout: 5000,
- title: 'Content too short',
- message: "Please enter a longer post.",
- alert_id: 'post_error'
- });
+ } else if (!content || content.length < Posts.minimumPostLength) {
+ Posts.emitContentTooShortAlert(socket);
return;
}
diff --git a/src/topics.js b/src/topics.js
index 1d8eef2f92..7cb1ae0b4b 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -18,6 +18,8 @@ marked.setOptions({
(function(Topics) {
+ Topics.minimumTitleLength = 3;
+
Topics.getTopicData = function(tid, callback) {
RDB.hgetall('topic:' + tid, function(err, data) {
if(err === null)
@@ -301,6 +303,16 @@ marked.setOptions({
});
}
+ Topics.emitTitleTooShortAlert = function(socket) {
+ socket.emit('event:alert', {
+ type: 'error',
+ timeout: 2000,
+ title: 'Title too short',
+ message: "Please enter a longer title.",
+ alert_id: 'post_error'
+ });
+ }
+
Topics.post = function(socket, uid, title, content, category_id) {
if (!category_id)
throw new Error('Attempted to post without a category_id');
@@ -316,23 +328,11 @@ marked.setOptions({
}
});
return; // for now, until anon code is written.
- } else if(!title || title.length <= 3) {
- socket.emit('event:alert', {
- type: 'error',
- timeout: 5000,
- title: 'Title too short',
- message: "Please enter a longer title.",
- alert_id: 'post_error'
- });
+ } else if(!title || title.length < Topics.minimumTitleLength) {
+ Topics.emitTitleTooShortAlert(socket);
return;
- } else if (!content || content.length <= 9) {
- socket.emit('event:alert', {
- type: 'error',
- timeout: 5000,
- title: 'Content too short',
- message: "Please enter a longer post.",
- alert_id: 'post_error'
- });
+ } else if (!content || content.length < posts.miminumPostLength) {
+ posts.emitContentTooShortAlert(socket);
return;
}
diff --git a/src/websockets.js b/src/websockets.js
index 837ea8f3f1..ed510bffd6 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -384,23 +384,11 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }),
});
socket.on('api:posts.edit', function(data) {
- if(!data.title || data.title.length <= 3) {
- socket.emit('event:alert', {
- type: 'error',
- timeout: 5000,
- title: 'Title too short',
- message: "Please enter a longer title.",
- alert_id: 'post_error'
- });
+ if(!data.title || data.title.length < topics.minimumTitleLength) {
+ topics.emitTitleTooShortAlert(socket);
return;
- } else if (!data.content || data.content.length <= 9) {
- socket.emit('event:alert', {
- type: 'error',
- timeout: 5000,
- title: 'Content too short',
- message: "Please enter a longer post.",
- alert_id: 'post_error'
- });
+ } else if (!data.content || data.content.length < posts.minimumPostLength) {
+ posts.emitContentTooShortAlert(socket);
return;
}
postTools.edit(uid, data.pid, data.title, data.content);