displayNameForUser.js 903 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. define([], function() {
  15. let displayNameForUser
  16. return (displayNameForUser = function(user) {
  17. if (user == null) {
  18. return 'Anonymous'
  19. }
  20. if (user.id === window.user.id) {
  21. return 'you'
  22. }
  23. if (user.name != null) {
  24. return user.name
  25. }
  26. let name = [user.first_name, user.last_name]
  27. .filter(n => n != null)
  28. .join(' ')
  29. .trim()
  30. if (name === '') {
  31. name = user.email.split('@')[0]
  32. }
  33. if (name == null || name === '') {
  34. return '?'
  35. }
  36. return name
  37. })
  38. })