From 80c0e2487d2565dd48429d46d4281898b318417d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 4 Sep 2020 22:57:36 -0400 Subject: [PATCH] PadMessageHandler: Move code out of unnecessary closure Also simplify the logic. --- src/node/handler/PadMessageHandler.js | 34 +++++++-------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 624db6829..47e4e4138 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -199,30 +199,15 @@ exports.handleMessage = async function(client, message) return; } - async function handleMessageHook() { - // Allow plugins to bypass the readonly message blocker - let messages = await hooks.aCallAll("handleMessageSecurity", { client: client, message: message }); + // Allow plugins to bypass the readonly message blocker + if ((await hooks.aCallAll('handleMessageSecurity', {client, message})).some((w) => w === true)) { + thisSession.readonly = false; + } - for (let message of messages) { - if (message === true) { - thisSession.readonly = false; - break; - } - } - - let dropMessage = false; - - // Call handleMessage hook. If a plugin returns null, the message will be dropped. Note that for all messages - // handleMessage will be called, even if the client is not authorized - messages = await hooks.aCallAll("handleMessage", { client: client, message: message }); - for (let message of messages) { - if (message === null ) { - dropMessage = true; - break; - } - } - - return dropMessage; + // Call handleMessage hook. If a plugin returns null, the message will be dropped. Note that for + // all messages handleMessage will be called, even if the client is not authorized + if ((await hooks.aCallAll('handleMessage', {client, message})).some((m) => m === null)) { + return; } function finalHandler() { @@ -259,9 +244,6 @@ exports.handleMessage = async function(client, message) } } - let dropMessage = await handleMessageHook(); - if (dropMessage) return; - if (message.type === "CLIENT_READY") { // client tried to auth for the first time (first msg from the client) createSessionInfoAuth(client, message);