mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-15 17:10:50 +01:00
added error and success language files
removed some code from server side that was emitting alerts
This commit is contained in:
@@ -18,42 +18,17 @@ var async = require('async'),
|
||||
SocketPosts.reply = function(socket, data, callback) {
|
||||
|
||||
if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Reply Unsuccessful',
|
||||
message: 'You don't seem to be logged in, so you cannot reply.',
|
||||
type: 'danger',
|
||||
timeout: 2000
|
||||
});
|
||||
return callback(new Error('not-logged-in'));
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
|
||||
if(!data || !data.tid || !data.content) {
|
||||
return callback(new Error('invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
data.uid = socket.uid;
|
||||
|
||||
topics.reply(data, function(err, postData) {
|
||||
if(err) {
|
||||
if (err.message === 'content-too-short') {
|
||||
module.parent.exports.emitContentTooShortAlert(socket);
|
||||
} else if (err.message === 'too-many-posts') {
|
||||
module.parent.exports.emitTooManyPostsAlert(socket);
|
||||
} else if (err.message === 'reply-error') {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Reply Unsuccessful',
|
||||
message: 'Your reply could not be posted at this time. Please try again later.',
|
||||
type: 'warning',
|
||||
timeout: 2000
|
||||
});
|
||||
} else if (err.message === 'no-privileges') {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Unable to post',
|
||||
message: 'You do not have posting privileges in this category.',
|
||||
type: 'danger',
|
||||
timeout: 7500
|
||||
});
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -61,12 +36,6 @@ SocketPosts.reply = function(socket, data, callback) {
|
||||
|
||||
module.parent.exports.emitTopicPostStats();
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Reply Successful',
|
||||
message: 'You have successfully replied. Click here to view your reply.',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
var socketData = {
|
||||
posts: [postData]
|
||||
};
|
||||
|
||||
@@ -16,44 +16,15 @@ var topics = require('../topics'),
|
||||
SocketTopics.post = function(socket, data, callback) {
|
||||
|
||||
if(!data) {
|
||||
return callback(new Error('Invalid data'));
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Post Unsuccessful',
|
||||
message: 'You don't seem to be logged in, so you cannot reply.',
|
||||
type: 'danger',
|
||||
timeout: 2000
|
||||
});
|
||||
return callback(new Error('not-logged-in'));
|
||||
return callback(new Error('[[error:not-logged-in]]'));
|
||||
}
|
||||
|
||||
topics.post({uid: socket.uid, title: data.title, content: data.content, cid: data.category_id, thumb: data.topic_thumb}, function(err, result) {
|
||||
if(err) {
|
||||
if (err.message === 'title-too-short') {
|
||||
module.parent.exports.emitAlert(socket, 'Title too short', 'Please enter a longer title. At least ' + meta.config.minimumTitleLength + ' characters.');
|
||||
} else if (err.message === 'title-too-long') {
|
||||
module.parent.exports.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') {
|
||||
module.parent.exports.emitContentTooShortAlert(socket);
|
||||
} else if (err.message === 'too-many-posts') {
|
||||
module.parent.exports.emitTooManyPostsAlert(socket);
|
||||
} else if (err.message === 'no-privileges') {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Unable to post',
|
||||
message: 'You do not have posting privileges in this category.',
|
||||
type: 'danger',
|
||||
timeout: 7500
|
||||
});
|
||||
} else {
|
||||
socket.emit('event:alert', {
|
||||
title: 'Error',
|
||||
message: err.message,
|
||||
type: 'warning',
|
||||
timeout: 7500
|
||||
});
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
@@ -71,12 +42,6 @@ SocketTopics.post = function(socket, data, callback) {
|
||||
|
||||
module.parent.exports.emitTopicPostStats();
|
||||
|
||||
socket.emit('event:alert', {
|
||||
title: 'Thank you for posting',
|
||||
message: 'You have successfully posted. Click here to view your post.',
|
||||
type: 'success',
|
||||
timeout: 2000
|
||||
});
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -77,21 +77,9 @@ module.exports = function(Topics) {
|
||||
}
|
||||
|
||||
if (!title || title.length < parseInt(meta.config.minimumTitleLength, 10)) {
|
||||
return callback(new Error('title-too-short'));
|
||||
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
|
||||
} else if(title.length > parseInt(meta.config.maximumTitleLength, 10)) {
|
||||
return callback(new Error('title-too-long'));
|
||||
}
|
||||
|
||||
if (content) {
|
||||
content = content.trim();
|
||||
}
|
||||
|
||||
if (!content || content.length < meta.config.miminumPostLength) {
|
||||
return callback(new Error('content-too-short'));
|
||||
}
|
||||
|
||||
if (!cid) {
|
||||
return callback(new Error('invalid-cid'));
|
||||
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
@@ -100,13 +88,13 @@ module.exports = function(Topics) {
|
||||
},
|
||||
function(categoryExists, next) {
|
||||
if (!categoryExists) {
|
||||
return next(new Error('category doesn\'t exist'));
|
||||
return next(new Error('[[error:no-category]]'));
|
||||
}
|
||||
categoryTools.privileges(cid, uid, next);
|
||||
},
|
||||
function(privileges, next) {
|
||||
if(!privileges.write) {
|
||||
return next(new Error('no-privileges'));
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
next();
|
||||
},
|
||||
@@ -129,7 +117,7 @@ module.exports = function(Topics) {
|
||||
return next(err);
|
||||
}
|
||||
if(!topicData || !topicData.length) {
|
||||
return next(new Error('no-topic'));
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
topicData = topicData[0];
|
||||
topicData.unreplied = 1;
|
||||
@@ -157,14 +145,14 @@ module.exports = function(Topics) {
|
||||
},
|
||||
function(topicExists, next) {
|
||||
if (!topicExists) {
|
||||
return next(new Error('topic doesn\'t exist'));
|
||||
return next(new Error('[[error:no-topic]]'));
|
||||
}
|
||||
|
||||
Topics.isLocked(tid, next);
|
||||
},
|
||||
function(locked, next) {
|
||||
if (locked) {
|
||||
return next(new Error('topic-locked'));
|
||||
return next(new Error('[[error:topic-locked]]'));
|
||||
}
|
||||
|
||||
threadTools.privileges(tid, uid, next);
|
||||
@@ -172,7 +160,7 @@ module.exports = function(Topics) {
|
||||
function(privilegesData, next) {
|
||||
privileges = privilegesData;
|
||||
if (!privileges.write) {
|
||||
return next(new Error('no-privileges'));
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
next();
|
||||
},
|
||||
@@ -184,8 +172,8 @@ module.exports = function(Topics) {
|
||||
content = content.trim();
|
||||
}
|
||||
|
||||
if (!content || content.length < meta.config.minimumPostLength) {
|
||||
return next(new Error('content-too-short'));
|
||||
if (!content || content.length < meta.config.miminumPostLength) {
|
||||
return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]'));
|
||||
}
|
||||
|
||||
posts.create({uid:uid, tid:tid, content:content, toPid:toPid}, next);
|
||||
|
||||
@@ -139,7 +139,7 @@ var bcrypt = require('bcryptjs'),
|
||||
}
|
||||
|
||||
if (Date.now() - parseInt(lastposttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
|
||||
return callback(new Error('too-many-posts'));
|
||||
return callback(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
|
||||
}
|
||||
callback();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user