From aec512d1fa47a3f80b81e71750852c8961d3b308 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 16 Feb 2022 22:20:18 -0500 Subject: [PATCH] Pad: Rename `author` context properties to `authorId` --- CHANGELOG.md | 2 ++ doc/api/hooks_server-side.md | 6 ++++-- src/node/db/Pad.js | 23 +++++++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c426b8526..c6f9d701c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,8 @@ * The `client` context property for the `handleMessageSecurity` and `handleMessage` server-side hooks is deprecated; use the `socket` context property instead. +* The `author` context property for the `padCreate` and `padUpdate` server-side + hooks is deprecated; use the new `authorId` context property instead. * Returning `true` from a `handleMessageSecurity` hook function is deprecated; return `'permitOnce'` instead. * Changes to the `src/static/js/Changeset.js` library: diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index 8baf32a88..a5b153f56 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -213,7 +213,8 @@ Called when a new pad is created. Context properties: * `pad`: The Pad object. -* `author`: The ID of the author who created the pad. +* `authorId`: The ID of the author who created the pad. +* `author` (**deprecated**): Synonym of `authorId`. ## `padLoad` @@ -234,7 +235,8 @@ Called when an existing pad is updated. Context properties: * `pad`: The Pad object. -* `author`: The ID of the author who updated the pad. +* `authorId`: The ID of the author who updated the pad. +* `author` (**deprecated**): Synonym of `authorId`. * `revs`: The index of the new revision. * `changeset`: The changeset of this revision (see [Changeset Library](#index_changeset_library)). diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 3d529b80f..7904b4e14 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -18,6 +18,7 @@ const CustomError = require('../utils/customError'); const readOnlyManager = require('./ReadOnlyManager'); const randomString = require('../utils/randomstring'); const hooks = require('../../static/js/pluginfw/hooks'); +const {padutils: {warnDeprecated}} = require('../../static/js/pad_utils'); const promises = require('../utils/promises'); // serialization/deserialization attributes @@ -109,11 +110,25 @@ Pad.prototype.appendRevision = async function (aChangeset, authorId) { // set the author to pad if (authorId) p.push(authorManager.addPad(authorId, this.id)); - if (this.head === 0) { - hooks.callAll('padCreate', {pad: this, author: authorId}); - } else { - hooks.callAll('padUpdate', {pad: this, author: authorId, revs: newRev, changeset: aChangeset}); + let hook = 'padCreate'; + const context = { + pad: this, + authorId, + get author() { + warnDeprecated(`${hook} hook author context is deprecated; use authorId instead`); + return this.authorId; + }, + set author(authorId) { + warnDeprecated(`${hook} hook author context is deprecated; use authorId instead`); + this.authorId = authorId; + }, + }; + if (this.head !== 0) { + hook = 'padUpdate'; + context.revs = newRev; + context.changeset = aChangeset; } + hooks.callAll(hook, context); await Promise.all(p); return newRev;