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

Method _isClearAuthorship

src/node/utils/padDiff.ts:38–80  ·  view source on GitHub ↗
(changeset: any)

Source from the content-addressed store, hash-verified

36 this._authors = [];
37 }
38 _isClearAuthorship(changeset: any){
39 // unpack
40 const unpacked = unpack(changeset);
41
42 // check if there is nothing in the charBank
43 if (unpacked.charBank !== '') {
44 return false;
45 }
46
47 // check if oldLength == newLength
48 if (unpacked.oldLen !== unpacked.newLen) {
49 return false;
50 }
51
52 const [clearOperator, anotherOp] = deserializeOps(unpacked.ops);
53
54 // check if there is only one operator
55 if (anotherOp != null) return false;
56
57 // check if this operator doesn't change text
58 if (clearOperator.opcode !== '=') {
59 return false;
60 }
61
62 // check that this operator applys to the complete text
63 // if the text ends with a new line, its exactly one character less, else it has the same length
64 if (clearOperator.chars !== unpacked.oldLen - 1 && clearOperator.chars !== unpacked.oldLen) {
65 return false;
66 }
67
68 const [appliedAttribute, anotherAttribute] =
69 attributes.attribsFromString(clearOperator.attribs, this._pad.pool);
70
71 // Check that the operation has exactly one attribute.
72 if (appliedAttribute == null || anotherAttribute != null) return false;
73
74 // check if the applied attribute is an anonymous author attribute
75 if (appliedAttribute[0] !== 'author' || appliedAttribute[1] !== '') {
76 return false;
77 }
78
79 return true;
80 }
81 async _createClearAuthorship(rev: any){
82 const atext = await this._pad.getInternalRevisionAText(rev);
83

Callers 1

_createDiffAtextMethod · 0.95

Calls 1

unpackFunction · 0.90

Tested by

no test coverage detected