Przeglądaj źródła

Support new comment op format

James Allen 9 lat temu
rodzic
commit
5e730b33b2

+ 2 - 2
services/docstore/app/coffee/RangeManager.coffee

@@ -26,8 +26,8 @@ module.exports = RangeManager =
 				change.metadata.user_id = @_safeObjectId(change.metadata.user_id)
 		for comment in ranges.comments or []
 			comment.id = @_safeObjectId(comment.id)
-			if comment.metadata?.ts?
-				comment.metadata.ts = new Date(comment.metadata.ts)
+			if comment.op?.t?
+				comment.op.t = @_safeObjectId(comment.op.t)
 		return ranges
 	
 	_safeObjectId: (data) ->

+ 10 - 20
services/docstore/test/unit/coffee/RangeManagerTests.coffee

@@ -17,6 +17,7 @@ describe "RangeManager", ->
 			change_id = ObjectId().toString()
 			comment_id = ObjectId().toString()
 			user_id = ObjectId().toString()
+			thread_id = ObjectId().toString()
 			ts = new Date().toJSON()
 			@RangeManager.jsonRangesToMongo({
 				changes: [{
@@ -28,10 +29,7 @@ describe "RangeManager", ->
 				}]
 				comments: [{
 					id: comment_id
-					offset: 42
-					length: 5
-					metadata:
-						ts: ts
+					op: { c: "foo", p: 3, t: thread_id }
 				}]
 			}).should.deep.equal {
 				changes: [{
@@ -43,10 +41,7 @@ describe "RangeManager", ->
 				}]
 				comments: [{
 					id: ObjectId(comment_id)
-					offset: 42
-					length: 5
-					metadata:
-						ts: new Date(ts)
+					op: { c: "foo", p: 3, t: ObjectId(thread_id) }
 				}]
 			}
 		
@@ -78,6 +73,7 @@ describe "RangeManager", ->
 			change_id = ObjectId().toString()
 			comment_id = ObjectId().toString()
 			user_id = ObjectId().toString()
+			thread_id = ObjectId().toString()
 			ts = new Date().toJSON()
 			ranges1 = {
 				changes: [{
@@ -89,10 +85,7 @@ describe "RangeManager", ->
 				}]
 				comments: [{
 					id: comment_id
-					offset: 42
-					length: 5
-					metadata:
-						ts: ts
+					op: { c: "foo", p: 3, t: thread_id }
 				}]
 			}
 			ranges1_copy = JSON.parse(JSON.stringify(ranges1)) # jsonRangesToMongo modifies in place
@@ -111,10 +104,7 @@ describe "RangeManager", ->
 				}]
 				comments: [{
 					id: ObjectId()
-					offset: 42
-					length: 5
-					metadata:
-						ts: new Date()
+					op: { c: "foo", p: 3, t: ObjectId() }
 				}]
 			}
 			@ranges_copy = @RangeManager.jsonRangesToMongo(JSON.parse(JSON.stringify(@ranges)))
@@ -153,10 +143,10 @@ describe "RangeManager", ->
 				@ranges_copy.comments[0].id = ObjectId()
 				@RangeManager.shouldUpdateRanges(@ranges, @ranges_copy).should.equal true
 
-			it "should return true when the comment ts changes", ->
-				@ranges_copy.comments[0].metadata.ts = new Date(Date.now() + 1000)
+			it "should return true when the comment offset changes", ->
+				@ranges_copy.comments[0].op.p = 17
 				@RangeManager.shouldUpdateRanges(@ranges, @ranges_copy).should.equal true
 
-			it "should return true when the comment offset changes", ->
-				@ranges_copy.comments[0].offset = 17
+			it "should return true when the comment content changes", ->
+				@ranges_copy.comments[0].op.c = "bar"
 				@RangeManager.shouldUpdateRanges(@ranges, @ranges_copy).should.equal true