mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Compare diffs with user.id, not user_id
This commit is contained in:
parent
575afae048
commit
9977a418c3
2 changed files with 21 additions and 18 deletions
|
@ -42,14 +42,17 @@ module.exports = DiffGenerator =
|
|||
newDiff = []
|
||||
for part in diff
|
||||
lastPart = newDiff[newDiff.length - 1]
|
||||
if lastPart? and lastPart.i? and part.i? and lastPart.meta.user_id == part.meta.user_id
|
||||
lastPart.i += part.i
|
||||
lastPart.meta.start_ts = Math.min(lastPart.meta.start_ts, part.meta.start_ts)
|
||||
lastPart.meta.end_ts = Math.max(lastPart.meta.end_ts, part.meta.end_ts)
|
||||
else if lastPart? and lastPart.d? and part.d? and lastPart.meta.user_id == part.meta.user_id
|
||||
lastPart.d += part.d
|
||||
lastPart.meta.start_ts = Math.min(lastPart.meta.start_ts, part.meta.start_ts)
|
||||
lastPart.meta.end_ts = Math.max(lastPart.meta.end_ts, part.meta.end_ts)
|
||||
if lastPart? and lastPart.meta?.user? and part.meta?.user?
|
||||
if lastPart.i? and part.i? and lastPart.meta.user.id == part.meta.user.id
|
||||
lastPart.i += part.i
|
||||
lastPart.meta.start_ts = Math.min(lastPart.meta.start_ts, part.meta.start_ts)
|
||||
lastPart.meta.end_ts = Math.max(lastPart.meta.end_ts, part.meta.end_ts)
|
||||
else if lastPart.d? and part.d? and lastPart.meta.user.id == part.meta.user.id
|
||||
lastPart.d += part.d
|
||||
lastPart.meta.start_ts = Math.min(lastPart.meta.start_ts, part.meta.start_ts)
|
||||
lastPart.meta.end_ts = Math.max(lastPart.meta.end_ts, part.meta.end_ts)
|
||||
else
|
||||
newDiff.push part
|
||||
else
|
||||
newDiff.push part
|
||||
return newDiff
|
||||
|
|
|
@ -91,18 +91,18 @@ describe "DiffGenerator", ->
|
|||
describe "with adjacent inserts with the same user_id", ->
|
||||
it "should create one update with combined meta data and min/max timestamps", ->
|
||||
diff = @DiffGenerator.compressDiff([
|
||||
{ i: "foo", meta: { start_ts: 10, end_ts: 20, user_id: @user_id }}
|
||||
{ i: "bar", meta: { start_ts: 5, end_ts: 15, user_id: @user_id }}
|
||||
{ i: "foo", meta: { start_ts: 10, end_ts: 20, user: { id: @user_id } }}
|
||||
{ i: "bar", meta: { start_ts: 5, end_ts: 15, user: { id: @user_id } }}
|
||||
])
|
||||
expect(diff).to.deep.equal([
|
||||
{ i: "foobar", meta: { start_ts: 5, end_ts: 20, user_id: @user_id }}
|
||||
{ i: "foobar", meta: { start_ts: 5, end_ts: 20, user: { id: @user_id } }}
|
||||
])
|
||||
|
||||
describe "with adjacent inserts with different user_ids", ->
|
||||
it "should leave the inserts unchanged", ->
|
||||
input = [
|
||||
{ i: "foo", meta: { start_ts: 10, end_ts: 20, user_id: @user_id }}
|
||||
{ i: "bar", meta: { start_ts: 5, end_ts: 15, user_id: @user_id_2 }}
|
||||
{ i: "foo", meta: { start_ts: 10, end_ts: 20, user: { id: @user_id } }}
|
||||
{ i: "bar", meta: { start_ts: 5, end_ts: 15, user: { id: @user_id_2 } }}
|
||||
]
|
||||
output = @DiffGenerator.compressDiff(input)
|
||||
expect(output).to.deep.equal(input)
|
||||
|
@ -110,18 +110,18 @@ describe "DiffGenerator", ->
|
|||
describe "with adjacent deletes with the same user_id", ->
|
||||
it "should create one update with combined meta data and min/max timestamps", ->
|
||||
diff = @DiffGenerator.compressDiff([
|
||||
{ d: "foo", meta: { start_ts: 10, end_ts: 20, user_id: @user_id }}
|
||||
{ d: "bar", meta: { start_ts: 5, end_ts: 15, user_id: @user_id }}
|
||||
{ d: "foo", meta: { start_ts: 10, end_ts: 20, user: { id: @user_id } }}
|
||||
{ d: "bar", meta: { start_ts: 5, end_ts: 15, user: { id: @user_id } }}
|
||||
])
|
||||
expect(diff).to.deep.equal([
|
||||
{ d: "foobar", meta: { start_ts: 5, end_ts: 20, user_id: @user_id }}
|
||||
{ d: "foobar", meta: { start_ts: 5, end_ts: 20, user: { id: @user_id } }}
|
||||
])
|
||||
|
||||
describe "with adjacent deletes with different user_ids", ->
|
||||
it "should leave the deletes unchanged", ->
|
||||
input = [
|
||||
{ d: "foo", meta: { start_ts: 10, end_ts: 20, user_id: @user_id }}
|
||||
{ d: "bar", meta: { start_ts: 5, end_ts: 15, user_id: @user_id_2 }}
|
||||
{ d: "foo", meta: { start_ts: 10, end_ts: 20, user: { id: @user_id } }}
|
||||
{ d: "bar", meta: { start_ts: 5, end_ts: 15, user: { id: @user_id_2 } }}
|
||||
]
|
||||
output = @DiffGenerator.compressDiff(input)
|
||||
expect(output).to.deep.equal(input)
|
||||
|
|
Loading…
Reference in a new issue