add character limit for chat message (?)

This commit is contained in:
hippoz 2020-11-20 21:35:43 +02:00
parent d1b1cce3bf
commit 76e0433753
2 changed files with 8 additions and 3 deletions

View file

@ -83,7 +83,7 @@ GatewayServer.prototype.eventSetup = function() {
socket.on('message', ({ category, content }) => { socket.on('message', ({ category, content }) => {
if (!category || !content || !socket.joinedCategories || !socket.isConnected || !socket.user) return; if (!category || !content || !socket.joinedCategories || !socket.isConnected || !socket.user) return;
content = content.trim(); 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 // TODO: When/if category permissions are added, check if the user has permissions for that category
const categoryTitle = socket.joinedCategories[category._id]; const categoryTitle = socket.joinedCategories[category._id];

View file

@ -110,7 +110,8 @@ GatewayConnection.prototype.connect = function(token) {
}; };
GatewayConnection.prototype.sendMessage = function(categoryId, content) { 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', { this.socket.emit('message', {
category: { category: {
@ -250,7 +251,11 @@ const app = new Vue({
this.selection.category._id = categoryId; this.selection.category._id = categoryId;
}, },
sendCurrentMessage: async function() { 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 = ''; this.message.typed = '';
}, },