Node.js based forum software built for the modern web
closes #3929
barisusaklif0b333e8a121
diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.jsonindex dbdb2c3c69..deba829970 100644--- a/public/language/en_GB/error.json+++ b/public/language/en_GB/error.json@@ -98,6 +98,7 @@"cant-chat-with-yourself": "You can't chat with yourself!","chat-restricted": "This user has restricted their chat messages. They must follow you before you can chat with them",+ "chat-disabled": "Chat system disabled","too-many-messages": "You have sent too many messages, please wait awhile.","invalid-chat-message": "Invalid chat message","chat-message-too-long": "Chat message is too long",diff --git a/public/src/modules/chat.js b/public/src/modules/chat.jsindex a3d4620f08..dba83387c7 100644--- a/public/src/modules/chat.js+++ b/public/src/modules/chat.js@@ -273,13 +273,6 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tracheckStatus(chatModal);- module.canMessage(data.roomId, function(err) {- if (err) {- // Disable the text input- chatModal.find('input[type="text"]').attr('disabled', true);- }- });-taskbar.push('chat', chatModal.attr('UUID'), {title: data.users.length ? data.users[0].username : '',roomId: data.roomId,@@ -380,11 +373,6 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tramodule.toggleNew = taskbar.toggleNew;- module.canMessage = function(roomId, callback) {- socket.emit('modules.chats.canMessage', roomId, callback);- };--return module;});diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.jsindex 2c777e7266..49dd5091da 100644--- a/src/controllers/accounts/chats.js+++ b/src/controllers/accounts/chats.js@@ -46,7 +46,6 @@ chatsController.get = function(req, res, callback) {since: 'recent',isNew: false}),- allowed: async.apply(messaging.canMessageRoom, req.uid, req.params.roomid),owner: async.apply(messaging.isRoomOwner, req.uid, req.params.roomid)}, next);}diff --git a/src/messaging.js b/src/messaging.jsindex c7c8f26978..b560bbb989 100644--- a/src/messaging.js+++ b/src/messaging.js@@ -355,7 +355,7 @@ var async = require('async'),Messaging.canMessageRoom = function(uid, roomId, callback) {if (parseInt(meta.config.disableChat) === 1 || !uid) {- return callback(null, false);+ return callback(null, false, '[[error:chat-disabled]]');}async.waterfall([@@ -364,17 +364,17 @@ var async = require('async'),},function (inRoom, next) {if (!inRoom) {- return callback(null, false);+ return callback(null, false, '[[error:not-in-room]]');}user.getUserFields(uid, ['banned', 'email:confirmed'], next);},function (userData, next) {if (parseInt(userData.banned, 10) === 1) {- return callback(null, false);+ return callback(null, false, '[[error:user-banned]]');}if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {- return callback(null, false);+ return callback(null, false, '[[error:email-not-confirmed-chat]]');}next(null, true);diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex 3cd7ba3486..279b5d4d45 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -84,9 +84,9 @@ SocketModules.chats.send = function(socket, data, callback) {socket.lastChatMessageTime = now;}- Messaging.canMessageRoom(socket.uid, data.roomId, function(err, allowed) {+ Messaging.canMessageRoom(socket.uid, data.roomId, function(err, allowed, notAllowedMessage) {if (err || !allowed) {- return callback(err || new Error('[[error:chat-restricted]]'));+ return callback(err || new Error(notAllowedMessage));}Messaging.sendMessage(socket.uid, data.roomId, data.message, now, function(err, message) {@@ -183,8 +183,11 @@ SocketModules.chats.delete = function(socket, data, callback) {};SocketModules.chats.canMessage = function(socket, roomId, callback) {- Messaging.canMessageRoom(socket.uid, roomId, function(err, allowed) {- callback(!allowed ? new Error('[[error:chat-restricted]]') : undefined);+ Messaging.canMessageRoom(socket.uid, roomId, function(err, allowed, notAllowedMessage) {+ if (err || !allowed) {+ return callback(err || new Error(notAllowedMessage));+ }+ callback();});};