mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
content length changes
This commit is contained in:
22
src/posts.js
22
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user