mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-24 17:36:14 -04:00
Pad: New padDefaultContent
hook
This commit is contained in:
parent
aa286b7dbd
commit
2e0e872ae3
3 changed files with 38 additions and 8 deletions
|
@ -372,11 +372,6 @@ Pad.prototype.getChatMessages = async function (start, end) {
|
|||
};
|
||||
|
||||
Pad.prototype.init = async function (text, authorId = '') {
|
||||
// replace text with default text if text isn't set
|
||||
if (text == null) {
|
||||
text = settings.defaultPadText;
|
||||
}
|
||||
|
||||
// try to load the pad
|
||||
const value = await this._db.get(`pad:${this.id}`);
|
||||
|
||||
|
@ -391,9 +386,18 @@ Pad.prototype.init = async function (text, authorId = '') {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// this pad doesn't exist, so create it
|
||||
const firstChangeset = Changeset.makeSplice('\n', 0, 0, exports.cleanText(text));
|
||||
|
||||
if (text == null) {
|
||||
const context = {
|
||||
pad: this,
|
||||
authorId,
|
||||
type: 'text',
|
||||
content: exports.cleanText(settings.defaultPadText),
|
||||
};
|
||||
await hooks.aCallAll('padDefaultContent', context);
|
||||
if (context.type !== 'text') throw new Error(`unsupported content type: ${context.type}`);
|
||||
text = context.content;
|
||||
}
|
||||
const firstChangeset = Changeset.makeSplice('\n', 0, 0, text);
|
||||
await this.appendRevision(firstChangeset, authorId);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue