Pad: New padCopy hook dstPad context property

This commit is contained in:
Richard Hansen 2022-04-08 02:37:06 -04:00
parent 9cdb69c159
commit 8fe779b58c
3 changed files with 21 additions and 11 deletions

View file

@ -40,7 +40,7 @@
* New `expressPreSession` server-side hook. * New `expressPreSession` server-side hook.
* Pad server-side hook changes: * Pad server-side hook changes:
* `padCopy`: New `srcPad` context property. * `padCopy`: New `srcPad` and `dstPad` context properties.
* `padDefaultContent`: New hook. * `padDefaultContent`: New hook.
* The `db` property on Pad objects is now public. * The `db` property on Pad objects is now public.
* New `getAuthorId` server-side hook. * New `getAuthorId` server-side hook.
@ -68,7 +68,9 @@
`handleMessage` server-side hooks is deprecated; use the `socket` context `handleMessage` server-side hooks is deprecated; use the `socket` context
property instead. property instead.
* Pad server-side hook changes: * Pad server-side hook changes:
* `padCopy`: The `originalPad` context property is deprecated; use `srcPad` * `padCopy`:
* The `originalPad` context property is deprecated; use `srcPad` instead.
* The `destinationID` context property is deprecated; use `dstPad.id`
instead. instead.
* `padCreate`: The `author` context property is deprecated; use the new * `padCreate`: The `author` context property is deprecated; use the new
`authorId` context property instead. `authorId` context property instead.

View file

@ -345,7 +345,7 @@ Order of events when a pad is copied:
Context properties: Context properties:
* `srcPad`: The source Pad object. * `srcPad`: The source Pad object.
* `destinationID`: The ID of the pad copied from `originalPad`. * `dstPad`: The destination Pad object.
Usage examples: Usage examples:

View file

@ -426,7 +426,7 @@ Pad.prototype.copy = async function (destinationID, force) {
}).call(this)); }).call(this));
// Initialize the new pad (will update the listAllPads cache) // Initialize the new pad (will update the listAllPads cache)
await padManager.getPad(destinationID, null); const dstPad = await padManager.getPad(destinationID, null);
// let the plugins know the pad was copied // let the plugins know the pad was copied
await hooks.aCallAll('padCopy', { await hooks.aCallAll('padCopy', {
@ -434,8 +434,12 @@ Pad.prototype.copy = async function (destinationID, force) {
warnDeprecated('padCopy originalPad context property is deprecated; use srcPad instead'); warnDeprecated('padCopy originalPad context property is deprecated; use srcPad instead');
return this.srcPad; return this.srcPad;
}, },
get destinationID() {
warnDeprecated('padCopy destinationID context property is deprecated; use dstPad.id instead');
return this.dstPad.id;
},
srcPad: this, srcPad: this,
destinationID, dstPad,
}); });
return {padID: destinationID}; return {padID: destinationID};
@ -503,8 +507,8 @@ Pad.prototype.copyPadWithoutHistory = async function (destinationID, force, auth
} }
// initialize the pad with a new line to avoid getting the defaultText // initialize the pad with a new line to avoid getting the defaultText
const newPad = await padManager.getPad(destinationID, '\n', authorId); const dstPad = await padManager.getPad(destinationID, '\n', authorId);
newPad.pool = this.pool.clone(); dstPad.pool = this.pool.clone();
const oldAText = this.atext; const oldAText = this.atext;
@ -513,7 +517,7 @@ Pad.prototype.copyPadWithoutHistory = async function (destinationID, force, auth
for (const op of Changeset.opsFromAText(oldAText)) assem.append(op); for (const op of Changeset.opsFromAText(oldAText)) assem.append(op);
assem.endDocument(); assem.endDocument();
// although we have instantiated the newPad with '\n', an additional '\n' is // although we have instantiated the dstPad with '\n', an additional '\n' is
// added internally, so the pad text on the revision 0 is "\n\n" // added internally, so the pad text on the revision 0 is "\n\n"
const oldLength = 2; const oldLength = 2;
@ -523,15 +527,19 @@ Pad.prototype.copyPadWithoutHistory = async function (destinationID, force, auth
// create a changeset that removes the previous text and add the newText with // create a changeset that removes the previous text and add the newText with
// all atributes present on the source pad // all atributes present on the source pad
const changeset = Changeset.pack(oldLength, newLength, assem.toString(), newText); const changeset = Changeset.pack(oldLength, newLength, assem.toString(), newText);
newPad.appendRevision(changeset, authorId); dstPad.appendRevision(changeset, authorId);
await hooks.aCallAll('padCopy', { await hooks.aCallAll('padCopy', {
get originalPad() { get originalPad() {
warnDeprecated('padCopy originalPad context property is deprecated; use srcPad instead'); warnDeprecated('padCopy originalPad context property is deprecated; use srcPad instead');
return this.srcPad; return this.srcPad;
}, },
get destinationID() {
warnDeprecated('padCopy destinationID context property is deprecated; use dstPad.id instead');
return this.dstPad.id;
},
srcPad: this, srcPad: this,
destinationID, dstPad,
}); });
return {padID: destinationID}; return {padID: destinationID};