diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index d5968a5..0f24933 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -83,7 +83,7 @@ GatewayServer.prototype.eventSetup = function() { socket.on('message', ({ category, content }) => { if (!category || !content || !socket.joinedCategories || !socket.isConnected || !socket.user) return; content = content.trim(); - if (!content || content === '' || content === ' ') return; + if (!content || content === '' || content === ' ' || content.length >= 2000) return; // TODO: When/if category permissions are added, check if the user has permissions for that category const categoryTitle = socket.joinedCategories[category._id]; diff --git a/app/resources/js/app.js b/app/resources/js/app.js index 9ace675..f7d6b58 100755 --- a/app/resources/js/app.js +++ b/app/resources/js/app.js @@ -110,7 +110,8 @@ GatewayConnection.prototype.connect = function(token) { }; GatewayConnection.prototype.sendMessage = function(categoryId, content) { - if (!this.isConnected) return; + if (!this.isConnected) return 1; + if (content.length >= 2000) return 1; this.socket.emit('message', { category: { @@ -250,7 +251,11 @@ const app = new Vue({ this.selection.category._id = categoryId; }, sendCurrentMessage: async function() { - this.gateway.sendMessage(this.selection.category._id, this.message.typed); + const status = this.gateway.sendMessage(this.selection.category._id, this.message.typed); + if (status === 1) { + this.okNotification('Failed to send message!'); + return; + } this.message.typed = ''; },