PadMessageHandler: Move code out of unnecessary closure

Also simplify the logic.
This commit is contained in:
Richard Hansen 2020-09-04 22:57:36 -04:00 committed by John McLear
parent a261fdf430
commit 80c0e2487d

View file

@ -199,30 +199,15 @@ exports.handleMessage = async function(client, message)
return; return;
} }
async function handleMessageHook() { // Allow plugins to bypass the readonly message blocker
// Allow plugins to bypass the readonly message blocker if ((await hooks.aCallAll('handleMessageSecurity', {client, message})).some((w) => w === true)) {
let messages = await hooks.aCallAll("handleMessageSecurity", { client: client, message: message }); thisSession.readonly = false;
}
for (let message of messages) { // Call handleMessage hook. If a plugin returns null, the message will be dropped. Note that for
if (message === true) { // all messages handleMessage will be called, even if the client is not authorized
thisSession.readonly = false; if ((await hooks.aCallAll('handleMessage', {client, message})).some((m) => m === null)) {
break; return;
}
}
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;
} }
function finalHandler() { function finalHandler() {
@ -259,9 +244,6 @@ exports.handleMessage = async function(client, message)
} }
} }
let dropMessage = await handleMessageHook();
if (dropMessage) return;
if (message.type === "CLIENT_READY") { if (message.type === "CLIENT_READY") {
// client tried to auth for the first time (first msg from the client) // client tried to auth for the first time (first msg from the client)
createSessionInfoAuth(client, message); createSessionInfoAuth(client, message);