Fix authorship sanitization

author colors wouldn't get disttributed, if their id was greater than 9
(due to apool encoding them to base 36)
pull/1750/head
Marcel Klehr 2013-04-17 15:24:40 +02:00
parent a3ed936d5f
commit 560fd55bf2
1 changed files with 9 additions and 8 deletions

View File

@ -163,19 +163,20 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider)
{
// Get my authorID
var authorId = parent.parent.pad.myUserInfo.userId;
// Rewrite apool authors with my author information
// We need to replace all new author attribs with thisSession.author, in case someone copy/pasted or otherwise inserted other peoples changes
// 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){
for (var attr in apool.numToAttrib){
if (apool.numToAttrib[attr][0] == 'author' && apool.numToAttrib[attr][1] == authorId) authorAttr = attr
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
var cs = Changeset.unpack(userChangeset)
, iterator = Changeset.opIterator(cs.ops)
, op
, assem = Changeset.mergingOpAssembler();
while(iterator.hasNext()) {
op = iterator.next()
if(op.opcode == '+') {
@ -183,13 +184,13 @@ function makeChangesetTracker(scheduler, apool, aceCallbacksProvider)
op.attribs.split('*').forEach(function(attrNum) {
if(!attrNum) return
attr = apool.getAttrib(attrNum)
var attr = apool.getAttrib(parseInt(attrNum, 36))
if(!attr) return
if('author' == attr[0] && !~newAttrs.indexOf(authorAttr)) {
if('author' == attr[0]) {
// replace that author with the current one
newAttrs += '*'+authorAttr;
// console.log('replacing author attribute ', attrNum, '(', attr[1], ') with', authorAttr)
}
else newAttrs += '*'+attrNum
else newAttrs += '*'+attrNum // overtake all other attribs as is
})
op.attribs = newAttrs
}