Send an empty string for every nameless user

This commit is contained in:
Chrystal Griffiths 2019-02-08 15:39:51 +00:00
parent 0a98eb436b
commit cb12e1c6f6
2 changed files with 44 additions and 26 deletions

View file

@ -145,13 +145,14 @@ module.exports = WebsocketController =
cursorData.id = client.id
cursorData.user_id = user_id if user_id?
cursorData.email = email if email?
if first_name or last_name
cursorData.name = if first_name && last_name
"#{first_name} #{last_name}"
else if first_name
first_name
else if last_name
last_name
else
""
ConnectedUsersManager.updateUserPosition(project_id, client.id, {
first_name: first_name,
last_name: last_name,
@ -162,9 +163,6 @@ module.exports = WebsocketController =
column: cursorData.column,
doc_id: cursorData.doc_id
}, callback)
else
cursorData.name = "Anonymous"
callback()
WebsocketLoadBalancer.emitToRoom(project_id, "clientTracking.clientUpdated", cursorData)
getConnectedUsers: (client, callback = (error, users) ->) ->

View file

@ -509,6 +509,30 @@ describe 'WebsocketController', ->
it "should increment the update-client-position metric at 0.1 frequency", ->
@metrics.inc.calledWith("editor.update-client-position", 0.1).should.equal true
describe "with a logged in user who has no names set", ->
beforeEach ->
@clientParams = {
project_id: @project_id
first_name: undefined
last_name: undefined
email: @email = "joe@example.com"
user_id: @user_id = "user-id-123"
}
@client.get = (param, callback) => callback null, @clientParams[param]
@WebsocketController.updateClientPosition @client, @update
it "should send the update to the project name with no name", ->
@WebsocketLoadBalancer.emitToRoom
.calledWith(@project_id, "clientTracking.clientUpdated", {
doc_id: @doc_id,
id: @client.id,
user_id: @user_id,
name: "",
row: @row,
column: @column,
email: @email
})
.should.equal true
describe "with an anonymous user", ->
@ -519,21 +543,17 @@ describe 'WebsocketController', ->
@client.get = (param, callback) => callback null, @clientParams[param]
@WebsocketController.updateClientPosition @client, @update
it "should send the update to the project room with an anonymous name", ->
it "should send the update to the project room with no name", ->
@WebsocketLoadBalancer.emitToRoom
.calledWith(@project_id, "clientTracking.clientUpdated", {
doc_id: @doc_id,
id: @client.id
name: "Anonymous"
name: ""
row: @row
column: @column
})
.should.equal true
it "should not send cursor data to the connected user manager", (done)->
@ConnectedUsersManager.updateUserPosition.called.should.equal false
done()
describe "applyOtUpdate", ->
beforeEach ->
@update = {op: {p: 12, t: "foo"}}