From 92cf5a8af2d84acb38376110925c5430791b7017 Mon Sep 17 00:00:00 2001 From: April Hall Date: Thu, 9 Jan 2025 12:36:43 -0500 Subject: [PATCH] fix: Prevent users from sending blank messages --- src/lib/websocketConfig.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib/websocketConfig.ts b/src/lib/websocketConfig.ts index 99d598d..07a061d 100644 --- a/src/lib/websocketConfig.ts +++ b/src/lib/websocketConfig.ts @@ -15,15 +15,18 @@ export function startupSocketIOServer(httpServer: HttpServer | null) { console.log(`[ws:kit] client connected (${socket.id})`); // Runs on message receive socket.on('message', async (msg) => { - console.log(`[ws:kit] message from ${socket.id}: ${msg}`); - // Store the message in the database - await createChannel(client, '000'); - await storeMessage(client, '000', msg.content, msg.id, uuidv4()); - io!.emit('message', { - user: msg.id, - message: msg.content, - imageSrc: 'https://www.arithefirst.com/images/pfp.png', - }); + // If message not empty + if (msg.content !== "") { + console.log(`[ws:kit] message from ${socket.id}: ${msg.content}`); + // Store the message in the database + await createChannel(client, '000'); + await storeMessage(client, '000', msg.content, msg.id, uuidv4()); + io!.emit('message', { + user: msg.id, + message: msg.content, + imageSrc: 'https://www.arithefirst.com/images/pfp.png', + }); + } }); // Runs on client disconnect