From 1b52c9f0c4f2f6bd63530899008e67fe440ec2fb Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Mon, 20 Dec 2021 16:58:39 -0500 Subject: [PATCH] PadMessageHandler: Deprecate `client` context property --- CHANGELOG.md | 3 +++ src/node/handler/PadMessageHandler.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87bf6d203..563d8c40c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,9 @@ #### For plugin authors +* The `client` context property for the `handleMessageSecurity` and + `handleMessage` server-side hooks is deprecated; use the `socket` context + property instead. * Changes to the `src/static/js/Changeset.js` library: * The following attribute processing functions are deprecated (use the new attribute APIs instead): diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index 3460983bd..da25b38dd 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -26,6 +26,7 @@ const ChatMessage = require('../../static/js/ChatMessage'); const AttributePool = require('../../static/js/AttributePool'); const AttributeManager = require('../../static/js/AttributeManager'); const authorManager = require('../db/AuthorManager'); +const {padutils} = require('../../static/js/pad_utils'); const readOnlyManager = require('../db/ReadOnlyManager'); const settings = require('../utils/Settings'); const securityManager = require('../db/SecurityManager'); @@ -270,7 +271,16 @@ exports.handleMessage = async (socket, message) => { thisSession.author = authorID; // Allow plugins to bypass the readonly message blocker - const context = {message, socket, client: socket}; // `client` for backwards compatibility. + const context = { + message, + socket, + get client() { + padutils.warnDeprecated( + 'the `client` context property for the handleMessageSecurity and handleMessage hooks ' + + 'is deprecated; use the `socket` property instead'); + return this.socket; + }, + }; if ((await hooks.aCallAll('handleMessageSecurity', context)).some((w) => w === true)) { thisSession.readonly = false; }