From de6a66a8778b465b993a97700f4295df5859fa46 Mon Sep 17 00:00:00 2001 From: hippoz Date: Fri, 20 Nov 2020 19:25:56 +0200 Subject: [PATCH] maybe fix weird crash --- api/v1/gateway/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/v1/gateway/index.js b/api/v1/gateway/index.js index 91740a5..b068c2f 100644 --- a/api/v1/gateway/index.js +++ b/api/v1/gateway/index.js @@ -81,7 +81,7 @@ GatewayServer.prototype.eventSetup = function() { socket.isConnected = true; socket.on('message', ({ category, content }) => { - if (!category || !content) return; + if (!category || !content || !socket.joinedCategories || !socket.isConnected || !socket.user) return; content = content.trim(); if (!content || content === '' || content === ' ') return; @@ -102,12 +102,12 @@ GatewayServer.prototype.eventSetup = function() { _id: uuid.v4() }; - socket.to(category._id).emit('message', messageObject); + socket.broadcast.to(category._id).emit('message', messageObject); socket.emit('message', messageObject); }); socket.on('subscribe', async (categories) => { - if (!categories || !Array.isArray(categories) || categories === []) return; + if ( !socket.isConnected || !socket.user || !categories || !Array.isArray(categories) || categories === []) return; for (const v of categories) { if (!v) continue; // TODO: When/if category permissions are added, check if the user has permissions for that category