Merge pull request #19 from sharelatex/ja-track-changes

Ignore comment updates
This commit is contained in:
James Allen 2017-01-16 11:38:45 +01:00 committed by GitHub
commit d0d7756517
4 changed files with 45 additions and 2 deletions

View file

@ -47,6 +47,9 @@ module.exports = DiffGenerator =
else if op.d?
return content.slice(0, op.p) + op.d + content.slice(op.p)
else
return content
rewindUpdates: (content, updates) ->
for update in updates.reverse()

View file

@ -24,7 +24,9 @@ module.exports = UpdateCompressor =
convertToSingleOpUpdates: (updates) ->
splitUpdates = []
for update in updates
if update.op.length == 0
# Reject any non-insert or delete ops, i.e. comments
ops = update.op.filter (o) -> o.i? or o.d?
if ops.length == 0
splitUpdates.push
op: UpdateCompressor.NOOP
meta:
@ -33,7 +35,7 @@ module.exports = UpdateCompressor =
user_id: update.meta.user_id
v: update.v
else
for op in update.op
for op in ops
splitUpdates.push
op: op
meta:

View file

@ -233,6 +233,28 @@ describe "Appending doc ops to the history", ->
expect(@updates[0].pack[0].v).to.equal 3
expect(@updates[0].pack[1].v).to.equal 4
describe "when there is a comment update", ->
before (done) ->
@project_id = ObjectId().toString()
@doc_id = ObjectId().toString()
@user_id = ObjectId().toString()
MockWebApi.projects[@project_id] = features: versioning: false
TrackChangesClient.pushRawUpdates @project_id, @doc_id, [{
op: [{ c: "foo", p: 3 }, {d: "bar", p: 6}]
meta: { ts: Date.now(), user_id: @user_id }
v: 3
}], (error) =>
throw error if error?
TrackChangesClient.flushAndGetCompressedUpdates @project_id, @doc_id, (error, @updates) =>
throw error if error?
done()
it "should ignore the comment op", ->
expect(@updates[0].pack[0].op).to.deep.equal [{d: "bar", p: 6}]
it "should insert the correct version numbers into mongo", ->
expect(@updates[0].pack[0].v).to.equal 3
describe "when the project has versioning enabled", ->
before (done) ->
@project_id = ObjectId().toString()

View file

@ -54,6 +54,22 @@ describe "UpdateCompressor", ->
v: 42
}]
it "should ignore comment ops", ->
expect(@UpdateCompressor.convertToSingleOpUpdates [{
op: [ @op1 = { p: 0, i: "Foo" }, @op2 = { p: 9, c: "baz"}, @op3 = { p: 6, i: "bar"} ]
meta: { ts: @ts1, user_id: @user_id }
v: 42
}])
.to.deep.equal [{
op: @op1,
meta: { start_ts: @ts1, end_ts: @ts1, user_id: @user_id },
v: 42
}, {
op: @op3,
meta: { start_ts: @ts1, end_ts: @ts1, user_id: @user_id },
v: 42
}]
describe "concatUpdatesWithSameVersion", ->
it "should concat updates with the same version", ->
expect(@UpdateCompressor.concatUpdatesWithSameVersion [{