Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Avatar.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* global MD5, config, interfaceConfig, APP */
  2. let users = {};
  3. export default {
  4. /**
  5. * Sets prop in users object.
  6. * @param id {string} user id
  7. * @param prop {string} name of the prop
  8. * @param val {string} value to be set
  9. */
  10. _setUserProp: function (id, prop, val) {
  11. // FIXME: Fixes the issue with not be able to return avatar for the
  12. // local user when the conference has been left. Maybe there is beter
  13. // way to solve it.
  14. if(APP.conference.isLocalId(id)) {
  15. id = "local";
  16. }
  17. if(!val || (users[id] && users[id][prop] === val))
  18. return;
  19. if(!users[id])
  20. users[id] = {};
  21. users[id][prop] = val;
  22. },
  23. /**
  24. * Sets the user's avatar in the settings menu(if local user), contact list
  25. * and thumbnail
  26. * @param id id of the user
  27. * @param email email or nickname to be used as a hash
  28. */
  29. setUserEmail: function (id, email) {
  30. this._setUserProp(id, "email", email);
  31. },
  32. /**
  33. * Sets the user's avatar in the settings menu(if local user), contact list
  34. * and thumbnail
  35. * @param id id of the user
  36. * @param url the url for the avatar
  37. */
  38. setUserAvatarUrl: function (id, url) {
  39. this._setUserProp(id, "url", url);
  40. },
  41. /**
  42. * Sets the user's avatar id.
  43. * @param id id of the user
  44. * @param avatarId an id to be used for the avatar
  45. */
  46. setUserAvatarID: function (id, avatarId) {
  47. this._setUserProp(id, "avatarId", avatarId);
  48. },
  49. /**
  50. * Returns the URL of the image for the avatar of a particular user,
  51. * identified by its id.
  52. * @param {string} userId user id
  53. */
  54. getAvatarUrl: function (userId) {
  55. if (config.disableThirdPartyRequests) {
  56. return 'images/avatar2.png';
  57. }
  58. if (!userId || APP.conference.isLocalId(userId)) {
  59. userId = "local";
  60. }
  61. let avatarId = null;
  62. const user = users[userId];
  63. // The priority is url, email and lowest is avatarId
  64. if(user) {
  65. if(user.url)
  66. return user.url;
  67. if (user.email)
  68. avatarId = user.email;
  69. else {
  70. avatarId = user.avatarId;
  71. }
  72. }
  73. // If the ID looks like an email, we'll use gravatar.
  74. // Otherwise, it's a random avatar, and we'll use the configured
  75. // URL.
  76. let random = !avatarId || avatarId.indexOf('@') < 0;
  77. if (!avatarId) {
  78. console.warn(
  79. `No avatar stored yet for ${userId} - using ID as avatar ID`);
  80. avatarId = userId;
  81. }
  82. avatarId = MD5.hexdigest(avatarId.trim().toLowerCase());
  83. let urlPref = null;
  84. let urlSuf = null;
  85. if (!random) {
  86. urlPref = 'https://www.gravatar.com/avatar/';
  87. urlSuf = "?d=wavatar&size=200";
  88. }
  89. else if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
  90. urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
  91. urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
  92. }
  93. else {
  94. urlPref = 'https://robohash.org/';
  95. urlSuf = ".png?size=200x200";
  96. }
  97. return urlPref + avatarId + urlSuf;
  98. }
  99. };