From 6f28e415ecc7d92ac258f0a58a6edbb9c4118921 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 4 Sep 2020 23:00:15 -0400 Subject: [PATCH] PadMessageHandler: Move code out of unnecessary closure (again) --- src/node/handler/PadMessageHandler.js | 67 +++++++++++++-------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 47e4e413..b32631ac 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -210,40 +210,6 @@ exports.handleMessage = async function(client, message) return; } - function finalHandler() { - // Check what type of message we get and delegate to the other methods - if (message.type === "CLIENT_READY") { - handleClientReady(client, message); - } else if (message.type === "CHANGESET_REQ") { - handleChangesetRequest(client, message); - } else if(message.type === "COLLABROOM") { - if (thisSession.readonly) { - messageLogger.warn("Dropped message, COLLABROOM for readonly pad"); - } else if (message.data.type === "USER_CHANGES") { - stats.counter('pendingEdits').inc() - padChannels.emit(message.padId, {client: client, message: message}); // add to pad queue - } else if (message.data.type === "USERINFO_UPDATE") { - handleUserInfoUpdate(client, message); - } else if (message.data.type === "CHAT_MESSAGE") { - handleChatMessage(client, message); - } else if (message.data.type === "GET_CHAT_MESSAGES") { - handleGetChatMessages(client, message); - } else if (message.data.type === "SAVE_REVISION") { - handleSaveRevisionMessage(client, message); - } else if (message.data.type === "CLIENT_MESSAGE" && - message.data.payload != null && - message.data.payload.type === "suggestUserName") { - handleSuggestUserName(client, message); - } else { - messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type); - } - } else if(message.type === "SWITCH_TO_PAD") { - handleSwitchToPad(client, message); - } else { - messageLogger.warn("Dropped message, unknown Message Type " + message.type); - } - } - if (message.type === "CLIENT_READY") { // client tried to auth for the first time (first msg from the client) createSessionInfoAuth(client, message); @@ -282,7 +248,38 @@ exports.handleMessage = async function(client, message) } // access was granted - finalHandler(); + + // Check what type of message we get and delegate to the other methods + if (message.type === "CLIENT_READY") { + handleClientReady(client, message); + } else if (message.type === "CHANGESET_REQ") { + handleChangesetRequest(client, message); + } else if(message.type === "COLLABROOM") { + if (thisSession.readonly) { + messageLogger.warn("Dropped message, COLLABROOM for readonly pad"); + } else if (message.data.type === "USER_CHANGES") { + stats.counter('pendingEdits').inc() + padChannels.emit(message.padId, {client: client, message: message}); // add to pad queue + } else if (message.data.type === "USERINFO_UPDATE") { + handleUserInfoUpdate(client, message); + } else if (message.data.type === "CHAT_MESSAGE") { + handleChatMessage(client, message); + } else if (message.data.type === "GET_CHAT_MESSAGES") { + handleGetChatMessages(client, message); + } else if (message.data.type === "SAVE_REVISION") { + handleSaveRevisionMessage(client, message); + } else if (message.data.type === "CLIENT_MESSAGE" && + message.data.payload != null && + message.data.payload.type === "suggestUserName") { + handleSuggestUserName(client, message); + } else { + messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type); + } + } else if(message.type === "SWITCH_TO_PAD") { + handleSwitchToPad(client, message); + } else { + messageLogger.warn("Dropped message, unknown Message Type " + message.type); + } }