Pad: Improve readability of appendRevision()

This commit is contained in:
Richard Hansen 2021-11-27 18:14:05 -05:00
parent 0d52f985bd
commit 2ca740c1db

View file

@ -81,27 +81,24 @@ class Pad {
const newRev = ++this.head; const newRev = ++this.head;
const newRevData = {};
newRevData.changeset = aChangeset;
newRevData.meta = {};
newRevData.meta.author = authorId;
newRevData.meta.timestamp = Date.now();
// ex. getNumForAuthor // ex. getNumForAuthor
if (authorId !== '') this.pool.putAttrib(['author', authorId]); if (authorId !== '') this.pool.putAttrib(['author', authorId]);
if (newRev === this.getKeyRevisionNumber(newRev)) { const p = Promise.all([
newRevData.meta.pool = this.pool; this.db.set(`pad:${this.id}:revs:${newRev}`, {
newRevData.meta.atext = this.atext; changeset: aChangeset,
} meta: {
author: authorId,
const p = [ timestamp: Date.now(),
this.db.set(`pad:${this.id}:revs:${newRev}`, newRevData), ...newRev === this.getKeyRevisionNumber(newRev) ? {
pool: this.pool,
atext: this.atext,
} : {},
},
}),
this.saveToDatabase(), this.saveToDatabase(),
]; authorId && authorManager.addPad(authorId, this.id),
]);
// set the author to pad
if (authorId) p.push(authorManager.addPad(authorId, this.id));
let hook = 'padCreate'; let hook = 'padCreate';
const context = { const context = {
@ -123,7 +120,7 @@ class Pad {
} }
hooks.callAll(hook, context); hooks.callAll(hook, context);
await Promise.all(p); await p;
return newRev; return newRev;
} }