From 2e684476cba8117591d032c6ef7b824f8014cc9a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 8 Apr 2022 00:00:38 -0400 Subject: [PATCH] chat: Move `chatHead` client var to `clientVars` hook --- CHANGELOG.md | 1 + src/ep.json | 1 + src/node/chat.js | 2 ++ src/node/handler/PadMessageHandler.js | 3 --- src/templates/pad.html | 11 ++++++++++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94cfe4ac8..764cd40a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -96,6 +96,7 @@ * The `sendChatMessageToPadClients()` function in `src/node/handler/PadMessageHandler.js` is deprecated. * Client-side: + * The `chat` global variable is deprecated. * The `pad.determineChatVisibility()` method was removed. * The `pad.determineChatAndUsersVisibility()` method was removed. * Returning `true` from a `handleMessageSecurity` hook function is deprecated; diff --git a/src/ep.json b/src/ep.json index a7e7af0df..10ac09e08 100644 --- a/src/ep.json +++ b/src/ep.json @@ -21,6 +21,7 @@ "postAceInit": "ep_etherpad-lite/static/js/chat" }, "hooks": { + "clientVars": "ep_etherpad-lite/node/chat", "eejsBlock_mySettings": "ep_etherpad-lite/node/chat", "eejsBlock_stickyContainer": "ep_etherpad-lite/node/chat", "handleMessage": "ep_etherpad-lite/node/chat", diff --git a/src/node/chat.js b/src/node/chat.js index a7afd8a20..bd78a93f2 100644 --- a/src/node/chat.js +++ b/src/node/chat.js @@ -23,6 +23,8 @@ const sendChatMessageToPadClients = async (message, padId) => { await promise; }; +exports.clientVars = (hookName, {pad: {chatHead}}) => ({chatHead}); + exports.eejsBlock_mySettings = (hookName, context) => { context.content += `

diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 871d0db10..35965825a 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -903,9 +903,6 @@ const handleClientReady = async (socket, message) => { padShortcutEnabled: settings.padShortcutEnabled, initialTitle: `Pad: ${sessionInfo.auth.padID}`, opts: {}, - // tell the client the number of the latest chat-message, which will be - // used to request the latest 100 chat-messages later (GET_CHAT_MESSAGES) - chatHead: pad.chatHead, numConnectedUsers: roomSockets.length, readOnlyId: sessionInfo.readOnlyPadId, readonly: sessionInfo.readonly, diff --git a/src/templates/pad.html b/src/templates/pad.html index 84a99f3de..497a05201 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -467,9 +467,18 @@ /* TODO: These globals shouldn't exist. */ pad = require('ep_etherpad-lite/static/js/pad').pad; - chat = require('ep_etherpad-lite/static/js/chat').chat; padeditbar = require('ep_etherpad-lite/static/js/pad_editbar').padeditbar; padimpexp = require('ep_etherpad-lite/static/js/pad_impexp').padimpexp; + + Object.defineProperty(window, 'chat', { + get: () => { + const {padutils: {warnDeprecated}} = require('ep_etherpad-lite/static/js/pad_utils'); + warnDeprecated( + 'window.chat is deprecated and will be removed in a future version of Etherpad'); + return require('ep_etherpad-lite/static/js/chat').chat; + }, + }); + require('ep_etherpad-lite/static/js/skin_variants'); }());