Skip to content

Commit 1b52c9f

Browse files
committed
PadMessageHandler: Deprecate client context property
1 parent 8539a66 commit 1b52c9f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
#### For plugin authors
3939

40+
* The `client` context property for the `handleMessageSecurity` and
41+
`handleMessage` server-side hooks is deprecated; use the `socket` context
42+
property instead.
4043
* Changes to the `src/static/js/Changeset.js` library:
4144
* The following attribute processing functions are deprecated (use the new
4245
attribute APIs instead):

src/node/handler/PadMessageHandler.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ChatMessage = require('../../static/js/ChatMessage');
2626
const AttributePool = require('../../static/js/AttributePool');
2727
const AttributeManager = require('../../static/js/AttributeManager');
2828
const authorManager = require('../db/AuthorManager');
29+
const {padutils} = require('../../static/js/pad_utils');
2930
const readOnlyManager = require('../db/ReadOnlyManager');
3031
const settings = require('../utils/Settings');
3132
const securityManager = require('../db/SecurityManager');
@@ -270,7 +271,16 @@ exports.handleMessage = async (socket, message) => {
270271
thisSession.author = authorID;
271272

272273
// Allow plugins to bypass the readonly message blocker
273-
const context = {message, socket, client: socket}; // `client` for backwards compatibility.
274+
const context = {
275+
message,
276+
socket,
277+
get client() {
278+
padutils.warnDeprecated(
279+
'the `client` context property for the handleMessageSecurity and handleMessage hooks ' +
280+
'is deprecated; use the `socket` property instead');
281+
return this.socket;
282+
},
283+
};
274284
if ((await hooks.aCallAll('handleMessageSecurity', context)).some((w) => w === true)) {
275285
thisSession.readonly = false;
276286
}

0 commit comments

Comments
 (0)