mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #19 from sharelatex/ja-track-changes
Ignore comment updates
This commit is contained in:
commit
d0d7756517
4 changed files with 45 additions and 2 deletions
|
@ -47,6 +47,9 @@ module.exports = DiffGenerator =
|
||||||
|
|
||||||
else if op.d?
|
else if op.d?
|
||||||
return content.slice(0, op.p) + op.d + content.slice(op.p)
|
return content.slice(0, op.p) + op.d + content.slice(op.p)
|
||||||
|
|
||||||
|
else
|
||||||
|
return content
|
||||||
|
|
||||||
rewindUpdates: (content, updates) ->
|
rewindUpdates: (content, updates) ->
|
||||||
for update in updates.reverse()
|
for update in updates.reverse()
|
||||||
|
|
|
@ -24,7 +24,9 @@ module.exports = UpdateCompressor =
|
||||||
convertToSingleOpUpdates: (updates) ->
|
convertToSingleOpUpdates: (updates) ->
|
||||||
splitUpdates = []
|
splitUpdates = []
|
||||||
for update in updates
|
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
|
splitUpdates.push
|
||||||
op: UpdateCompressor.NOOP
|
op: UpdateCompressor.NOOP
|
||||||
meta:
|
meta:
|
||||||
|
@ -33,7 +35,7 @@ module.exports = UpdateCompressor =
|
||||||
user_id: update.meta.user_id
|
user_id: update.meta.user_id
|
||||||
v: update.v
|
v: update.v
|
||||||
else
|
else
|
||||||
for op in update.op
|
for op in ops
|
||||||
splitUpdates.push
|
splitUpdates.push
|
||||||
op: op
|
op: op
|
||||||
meta:
|
meta:
|
||||||
|
|
|
@ -233,6 +233,28 @@ describe "Appending doc ops to the history", ->
|
||||||
expect(@updates[0].pack[0].v).to.equal 3
|
expect(@updates[0].pack[0].v).to.equal 3
|
||||||
expect(@updates[0].pack[1].v).to.equal 4
|
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", ->
|
describe "when the project has versioning enabled", ->
|
||||||
before (done) ->
|
before (done) ->
|
||||||
@project_id = ObjectId().toString()
|
@project_id = ObjectId().toString()
|
||||||
|
|
|
@ -54,6 +54,22 @@ describe "UpdateCompressor", ->
|
||||||
v: 42
|
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", ->
|
describe "concatUpdatesWithSameVersion", ->
|
||||||
it "should concat updates with the same version", ->
|
it "should concat updates with the same version", ->
|
||||||
expect(@UpdateCompressor.concatUpdatesWithSameVersion [{
|
expect(@UpdateCompressor.concatUpdatesWithSameVersion [{
|
||||||
|
|
Loading…
Reference in a new issue