From 884adfd739e8abcaeca3fbc6454b94189177faa3 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sat, 18 May 2024 03:07:40 +0530 Subject: [PATCH] SimpleChat: Ignore empty user input, without trimming --- examples/server/public_simplechat/simplechat.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index f1770ec92..35a74109e 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -30,9 +30,10 @@ class SimpleChat { */ add(role, content) { if ((content == undefined) || (content == null) || (content == "")) { - return; + return false; } this.xchat.push( {role: role, content: content} ); + return true; } /** @@ -105,7 +106,10 @@ async function handle_submit(inputSystem, inputUser, divChat, apiEP) { } let content = inputUser?.value; - gChat.add(Roles.User, content); + if (!gChat.add(Roles.User, content)) { + console.debug("WARN:HandleSubmit:Ignoring empty user input..."); + return; + } gChat.show(divChat); let theBody;