MCPcopy Index your code
hub / github.com/ether/etherpad / appendRevision

Method appendRevision

src/node/db/Pad.ts:280–335  ·  view source on GitHub ↗

* Appends a new revision * @param {Object} aChangeset The changeset to append to the pad * @param {String} authorId The id of the author * @return {Promise }

(aChangeset:string, authorId = '')

Source from the content-addressed store, hash-verified

278 * @return {Promise<number|string>}
279 */
280 async appendRevision(aChangeset:string, authorId = '') {
281 // Centralised "every insert op carries an author attribute"
282 // invariant. The socket handler enforces the same rule at the wire
283 // boundary; checking here covers the non-wire callers (HTTP API
284 // setHTML/setText/restoreRevision, plugin paths that call
285 // appendRevision directly).
286 Pad._assertInsertOpsCarryAuthor(aChangeset, this.pool);
287
288 const newAText = applyToAText(aChangeset, this.atext, this.pool);
289 if (newAText.text === this.atext.text && newAText.attribs === this.atext.attribs &&
290 this.head !== -1) {
291 return this.head;
292 }
293 copyAText(newAText, this.atext);
294
295 const newRev = ++this.head;
296
297 // ex. getNumForAuthor
298 if (authorId !== '') this.pool.putAttrib(['author', authorId]);
299
300 const hook = this.head === 0 ? 'padCreate' : 'padUpdate';
301 await Promise.all([
302 // @ts-ignore
303 this.db.set(`pad:${this.id}:revs:${newRev}`, {
304 changeset: aChangeset,
305 meta: {
306 author: authorId,
307 timestamp: Date.now(),
308 ...newRev === this.getKeyRevisionNumber(newRev) ? {
309 pool: this.pool,
310 atext: this.atext,
311 } : {},
312 },
313 }),
314 this.saveToDatabase(),
315 authorId && authorManager.addPad(authorId, this.id),
316 hooks.aCallAll(hook, {
317 pad: this,
318 padId: this.id,
319 authorId,
320 get author() {
321 pad_utils.warnDeprecated(`${hook} hook author context is deprecated; use authorId instead`);
322 return this.authorId;
323 },
324 set author(authorId) {
325 pad_utils.warnDeprecated(`${hook} hook author context is deprecated; use authorId instead`);
326 this.authorId = authorId;
327 },
328 ...this.head === 0 ? {} : {
329 revs: newRev,
330 changeset: aChangeset,
331 },
332 }),
333 ]);
334 return newRev;
335 }
336
337 toJSON() {

Callers 7

spliceTextMethod · 0.95
initMethod · 0.95
ImportHtml.tsFile · 0.80
copyPadWithoutHistoryMethod · 0.80
API.tsFile · 0.80
handleUserChangesFunction · 0.80

Calls 9

getKeyRevisionNumberMethod · 0.95
saveToDatabaseMethod · 0.95
applyToATextFunction · 0.90
copyATextFunction · 0.90
putAttribMethod · 0.80
setMethod · 0.80
nowMethod · 0.80
addPadMethod · 0.80

Tested by

no test coverage detected