Преглед изворни кода

Still send cursorData for logged in users

Chrystal Griffiths пре 7 година
родитељ
комит
bb06f82e04

+ 11 - 8
services/real-time/app/coffee/WebsocketController.coffee

@@ -52,6 +52,10 @@ module.exports = WebsocketController =
 		metrics.inc "editor.leave-project"
 		metrics.inc "editor.leave-project"
 		Utils.getClientAttributes client, ["project_id", "user_id"], (error, {project_id, user_id}) ->
 		Utils.getClientAttributes client, ["project_id", "user_id"], (error, {project_id, user_id}) ->
 			return callback(error) if error?
 			return callback(error) if error?
+
+			logger.log {project_id, user_id, client_id: client.id}, "client leaving project"
+			WebsocketLoadBalancer.emitToRoom project_id, "clientTracking.clientDisconnected", client.id
+			
 			# bail out if the client had not managed to authenticate or join
 			# bail out if the client had not managed to authenticate or join
 			# the project.  Prevents downstream errors in docupdater from
 			# the project.  Prevents downstream errors in docupdater from
 			# flushProjectToMongoAndDelete with null project_id.
 			# flushProjectToMongoAndDelete with null project_id.
@@ -61,9 +65,6 @@ module.exports = WebsocketController =
 			if not project_id?
 			if not project_id?
 				logger.log {user_id: user_id, client_id: client.id}, "client leaving, not in project"
 				logger.log {user_id: user_id, client_id: client.id}, "client leaving, not in project"
 				return callback()
 				return callback()
-
-			logger.log {project_id, user_id, client_id: client.id}, "client leaving project"
-			WebsocketLoadBalancer.emitToRoom project_id, "clientTracking.clientDisconnected", client.id
 		
 		
 			# We can do this in the background
 			# We can do this in the background
 			ConnectedUsersManager.markUserAsDisconnected project_id, client.id, (err) ->
 			ConnectedUsersManager.markUserAsDisconnected project_id, client.id, (err) ->
@@ -144,13 +145,18 @@ module.exports = WebsocketController =
 				cursorData.id      = client.id
 				cursorData.id      = client.id
 				cursorData.user_id = user_id if user_id?
 				cursorData.user_id = user_id if user_id?
 				cursorData.email   = email   if email?
 				cursorData.email   = email   if email?
-				if first_name or last_name
+				if !user_id or user_id == 'anonymous-user'
+					cursorData.name = ""
+					callback()
+				else 
 					cursorData.name = if first_name && last_name
 					cursorData.name = if first_name && last_name
 						"#{first_name} #{last_name}"
 						"#{first_name} #{last_name}"
 					else if first_name
 					else if first_name
 						first_name
 						first_name
 					else if last_name
 					else if last_name
 						last_name
 						last_name
+					else
+						""
 					ConnectedUsersManager.updateUserPosition(project_id, client.id, {
 					ConnectedUsersManager.updateUserPosition(project_id, client.id, {
 						first_name: first_name,
 						first_name: first_name,
 						last_name:  last_name,
 						last_name:  last_name,
@@ -160,10 +166,7 @@ module.exports = WebsocketController =
 						row:    cursorData.row,
 						row:    cursorData.row,
 						column: cursorData.column,
 						column: cursorData.column,
 						doc_id: cursorData.doc_id
 						doc_id: cursorData.doc_id
-					}, callback)
-				else
-					cursorData.name = ""
-					callback()
+					}, callback)					
 				WebsocketLoadBalancer.emitToRoom(project_id, "clientTracking.clientUpdated", cursorData)
 				WebsocketLoadBalancer.emitToRoom(project_id, "clientTracking.clientUpdated", cursorData)
 
 
 	getConnectedUsers: (client, callback = (error, users) ->) ->
 	getConnectedUsers: (client, callback = (error, users) ->) ->

+ 4 - 0
services/real-time/test/unit/coffee/WebsocketControllerTests.coffee

@@ -554,6 +554,10 @@ describe 'WebsocketController', ->
 					})
 					})
 					.should.equal true
 					.should.equal true
 
 
+			it "should not send cursor data to the connected user manager", (done)->
+				@ConnectedUsersManager.updateUserPosition.called.should.equal false
+				done()
+
 	describe "applyOtUpdate", ->
 	describe "applyOtUpdate", ->
 		beforeEach ->
 		beforeEach ->
 			@update = {op: {p: 12, t: "foo"}}
 			@update = {op: {p: 12, t: "foo"}}