overleaf/services/chat/app/coffee/Features/Users/UserFormatter.coffee

20 lines
511 B
CoffeeScript
Raw Normal View History

2014-08-15 05:50:36 -04:00
crypto = require "crypto"
module.exports = UserFormatter =
formatUserForClientSide: (user) ->
return null if !user?
2014-08-15 05:50:36 -04:00
if user._id?
user.id = user._id.toString()
delete user._id
return {
id: user.id
first_name: user.first_name
last_name: user.last_name
email: user.email
gravatar_url: @_getGravatarUrlForEmail(user.email)
}
_getGravatarUrlForEmail: (email) ->
hash = crypto.createHash("md5").update(email.toLowerCase()).digest("hex")
return "//www.gravatar.com/avatar/#{hash}"