Pad: New `padCopy` hook `dstPad` context property

pull/5505/head
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.
* Pad server-side hook changes:
* `padCopy`: New `srcPad` context property.
* `padCopy`: New `srcPad` and `dstPad` context properties.
* `padDefaultContent`: New hook.
* The `db` property on Pad objects is now public.
* New `getAuthorId` server-side hook.
@ -68,8 +68,10 @@
`handleMessage` server-side hooks is deprecated; use the `socket` context
property instead.
* Pad server-side hook changes:
* `padCopy`: The `originalPad` context property is deprecated; use `srcPad`
instead.
* `padCopy`:
* The `originalPad` context property is deprecated; use `srcPad` instead.
* The `destinationID` context property is deprecated; use `dstPad.id`
instead.
* `padCreate`: The `author` context property is deprecated; use the new
`authorId` context property instead.
* `padUpdate`: The `author` context property is deprecated; use the new

View File

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

View File

@ -426,7 +426,7 @@ Pad.prototype.copy = async function (destinationID, force) {
}).call(this));
// 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
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');
return this.srcPad;
},
get destinationID() {
warnDeprecated('padCopy destinationID context property is deprecated; use dstPad.id instead');
return this.dstPad.id;
},
srcPad: this,
destinationID,
dstPad,
});
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
const newPad = await padManager.getPad(destinationID, '\n', authorId);
newPad.pool = this.pool.clone();
const dstPad = await padManager.getPad(destinationID, '\n', authorId);
dstPad.pool = this.pool.clone();
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);
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"
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
// all atributes present on the source pad
const changeset = Changeset.pack(oldLength, newLength, assem.toString(), newText);
newPad.appendRevision(changeset, authorId);
dstPad.appendRevision(changeset, authorId);
await hooks.aCallAll('padCopy', {
get originalPad() {
warnDeprecated('padCopy originalPad context property is deprecated; use srcPad instead');
return this.srcPad;
},
get destinationID() {
warnDeprecated('padCopy destinationID context property is deprecated; use dstPad.id instead');
return this.dstPad.id;
},
srcPad: this,
destinationID,
dstPad,
});
return {padID: destinationID};