From 5fe5a87c856741fe2329d9ba842ac1ccf89b3158 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 5 Dec 2021 22:32:27 -0500 Subject: [PATCH] collab_client: Pass raw message to `handleClientMessage_*` hooks --- CHANGELOG.md | 2 ++ doc/api/hooks_client-side.md | 13 +++++++------ src/static/js/collab_client.js | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5d7098ca..c48c2da20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,8 @@ * New APIs for processing attributes: `ep_etherpad-lite/static/js/attributes` (low-level API) and `ep_etherpad-lite/static/js/AttributeMap` (high-level API). +* The `handleClientMessage_${name}` client-side hooks are now passed the raw + message object in the new `msg` context property. * The `import` server-side hook has a new `ImportError` context property. * New `exportEtherpad` and `importEtherpad` server-side hooks. * The `handleMessageSecurity` and `handleMessage` server-side hooks have a new diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md index 45ef18a01..cd4d22843 100755 --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.md @@ -393,15 +393,10 @@ This hook is called after the content of a node is collected by the usual methods. The cc object can be used to do a bunch of things that modify the content of the pad. See, for example, the heading1 plugin for etherpad original. -## handleClientMessage_`name` +## `handleClientMessage_${name}` Called from: `src/static/js/collab_client.js` -Things in context: - -1. payload - the data that got sent with the message (use it for custom message - content) - This hook gets called every time the client receives a message of type `name`. This can most notably be used with the new HTTP API call, "sendClientsMessage", which sends a custom message type to all clients connected to a pad. You can @@ -410,6 +405,12 @@ also use this to handle existing types. `collab_client.js` has a pretty extensive list of message types, if you want to take a look. +Context properties: + + * `msg`: The raw message object. + * `payload`: The data that got sent with the message. Usually this is + `msg.payload`. + ## aceStartLineAndCharForPoint-aceEndLineAndCharForPoint Called from: src/static/js/ace2_inner.js diff --git a/src/static/js/collab_client.js b/src/static/js/collab_client.js index 74bc66f9f..cd6c78ad0 100644 --- a/src/static/js/collab_client.js +++ b/src/static/js/collab_client.js @@ -300,7 +300,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad) // Similar for NEW_CHANGES if (msg.type === 'NEW_CHANGES') msg.payload = msg; - hooks.callAll(`handleClientMessage_${msg.type}`, {payload: msg.payload}); + hooks.callAll(`handleClientMessage_${msg.type}`, {msg, payload: msg.payload}); }; const updateUserInfo = (userInfo) => {