diff --git a/services/track-changes/app/coffee/DiffGenerator.coffee b/services/track-changes/app/coffee/DiffGenerator.coffee index 996c936612..c8229b96dc 100644 --- a/services/track-changes/app/coffee/DiffGenerator.coffee +++ b/services/track-changes/app/coffee/DiffGenerator.coffee @@ -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 diff --git a/services/track-changes/test/unit/coffee/DiffGenerator/DiffGeneratorTests.coffee b/services/track-changes/test/unit/coffee/DiffGenerator/DiffGeneratorTests.coffee index 43c86cfb5d..848086dc2e 100644 --- a/services/track-changes/test/unit/coffee/DiffGenerator/DiffGeneratorTests.coffee +++ b/services/track-changes/test/unit/coffee/DiffGenerator/DiffGeneratorTests.coffee @@ -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)