mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
changesettracker: Remove unnecessary .numToAttrib
check
This commit is contained in:
parent
3ec5e84737
commit
d0e74ada2f
1 changed files with 34 additions and 35 deletions
|
@ -142,43 +142,42 @@ const makeChangesetTracker = (scheduler, apool, aceCallbacksProvider) => {
|
|||
// Sanitize authorship
|
||||
// We need to replace all author attribs with thisSession.author,
|
||||
// in case they copy/pasted or otherwise inserted other peoples changes
|
||||
if (apool.numToAttrib) {
|
||||
let authorAttr;
|
||||
for (const attr in apool.numToAttrib) {
|
||||
if (apool.numToAttrib[attr][0] === 'author' &&
|
||||
apool.numToAttrib[attr][1] === authorId) {
|
||||
authorAttr = Number(attr).toString(36);
|
||||
}
|
||||
let authorAttr;
|
||||
for (const attr in apool.numToAttrib) {
|
||||
if (apool.numToAttrib[attr][0] === 'author' &&
|
||||
apool.numToAttrib[attr][1] === authorId) {
|
||||
authorAttr = Number(attr).toString(36);
|
||||
}
|
||||
|
||||
// Replace all added 'author' attribs with the value of the current user
|
||||
const cs = Changeset.unpack(userChangeset);
|
||||
const iterator = Changeset.opIterator(cs.ops);
|
||||
let op;
|
||||
const assem = Changeset.mergingOpAssembler();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
op = iterator.next();
|
||||
if (op.opcode === '+') {
|
||||
let newAttrs = '';
|
||||
|
||||
op.attribs.split('*').forEach((attrNum) => {
|
||||
if (!attrNum) return;
|
||||
const attr = apool.getAttrib(parseInt(attrNum, 36));
|
||||
if (!attr) return;
|
||||
if ('author' === attr[0]) {
|
||||
// replace that author with the current one
|
||||
newAttrs += `*${authorAttr}`;
|
||||
} else { newAttrs += `*${attrNum}`; } // overtake all other attribs as is
|
||||
});
|
||||
op.attribs = newAttrs;
|
||||
}
|
||||
assem.append(op);
|
||||
}
|
||||
assem.endDocument();
|
||||
userChangeset = Changeset.pack(cs.oldLen, cs.newLen, assem.toString(), cs.charBank);
|
||||
Changeset.checkRep(userChangeset);
|
||||
}
|
||||
|
||||
// Replace all added 'author' attribs with the value of the current user
|
||||
const cs = Changeset.unpack(userChangeset);
|
||||
const iterator = Changeset.opIterator(cs.ops);
|
||||
let op;
|
||||
const assem = Changeset.mergingOpAssembler();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
op = iterator.next();
|
||||
if (op.opcode === '+') {
|
||||
let newAttrs = '';
|
||||
|
||||
op.attribs.split('*').forEach((attrNum) => {
|
||||
if (!attrNum) return;
|
||||
const attr = apool.getAttrib(parseInt(attrNum, 36));
|
||||
if (!attr) return;
|
||||
if ('author' === attr[0]) {
|
||||
// replace that author with the current one
|
||||
newAttrs += `*${authorAttr}`;
|
||||
} else { newAttrs += `*${attrNum}`; } // overtake all other attribs as is
|
||||
});
|
||||
op.attribs = newAttrs;
|
||||
}
|
||||
assem.append(op);
|
||||
}
|
||||
assem.endDocument();
|
||||
userChangeset = Changeset.pack(cs.oldLen, cs.newLen, assem.toString(), cs.charBank);
|
||||
Changeset.checkRep(userChangeset);
|
||||
|
||||
if (Changeset.isIdentity(userChangeset)) toSubmit = null;
|
||||
else toSubmit = userChangeset;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue