PadMessageHandler: Deprecate `client` context property

pull/5336/head
Richard Hansen 2021-12-20 16:58:39 -05:00
parent 8539a66439
commit 1b52c9f0c4
2 changed files with 14 additions and 1 deletions

View File

@ -37,6 +37,9 @@
#### For plugin authors #### 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: * Changes to the `src/static/js/Changeset.js` library:
* The following attribute processing functions are deprecated (use the new * The following attribute processing functions are deprecated (use the new
attribute APIs instead): attribute APIs instead):

View File

@ -26,6 +26,7 @@ const ChatMessage = require('../../static/js/ChatMessage');
const AttributePool = require('../../static/js/AttributePool'); const AttributePool = require('../../static/js/AttributePool');
const AttributeManager = require('../../static/js/AttributeManager'); const AttributeManager = require('../../static/js/AttributeManager');
const authorManager = require('../db/AuthorManager'); const authorManager = require('../db/AuthorManager');
const {padutils} = require('../../static/js/pad_utils');
const readOnlyManager = require('../db/ReadOnlyManager'); const readOnlyManager = require('../db/ReadOnlyManager');
const settings = require('../utils/Settings'); const settings = require('../utils/Settings');
const securityManager = require('../db/SecurityManager'); const securityManager = require('../db/SecurityManager');
@ -270,7 +271,16 @@ exports.handleMessage = async (socket, message) => {
thisSession.author = authorID; thisSession.author = authorID;
// Allow plugins to bypass the readonly message blocker // 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)) { if ((await hooks.aCallAll('handleMessageSecurity', context)).some((w) => w === true)) {
thisSession.readonly = false; thisSession.readonly = false;
} }