Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Avatar.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Adorable Avatars service used at the end of this file is released under the
  3. * terms of the MIT License.
  4. *
  5. * Copyright (c) 2014 Adorable IO LLC
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. /* global MD5, config, interfaceConfig, APP */
  24. const logger = require("jitsi-meet-logger").getLogger(__filename);
  25. let users = {};
  26. export default {
  27. /**
  28. * Sets prop in users object.
  29. * @param id {string} user id
  30. * @param prop {string} name of the prop
  31. * @param val {string} value to be set
  32. */
  33. _setUserProp: function (id, prop, val) {
  34. // FIXME: Fixes the issue with not be able to return avatar for the
  35. // local user when the conference has been left. Maybe there is beter
  36. // way to solve it.
  37. if(APP.conference.isLocalId(id)) {
  38. id = "local";
  39. }
  40. if(!val || (users[id] && users[id][prop] === val))
  41. return;
  42. if(!users[id])
  43. users[id] = {};
  44. users[id][prop] = val;
  45. },
  46. /**
  47. * Sets the user's avatar in the settings menu(if local user), contact list
  48. * and thumbnail
  49. * @param id id of the user
  50. * @param email email or nickname to be used as a hash
  51. */
  52. setUserEmail: function (id, email) {
  53. this._setUserProp(id, "email", email);
  54. },
  55. /**
  56. * Sets the user's avatar in the settings menu(if local user), contact list
  57. * and thumbnail
  58. * @param id id of the user
  59. * @param url the url for the avatar
  60. */
  61. setUserAvatarUrl: function (id, url) {
  62. this._setUserProp(id, "url", url);
  63. },
  64. /**
  65. * Sets the user's avatar id.
  66. * @param id id of the user
  67. * @param avatarId an id to be used for the avatar
  68. */
  69. setUserAvatarID: function (id, avatarId) {
  70. this._setUserProp(id, "avatarId", avatarId);
  71. },
  72. /**
  73. * Returns the URL of the image for the avatar of a particular user,
  74. * identified by its id.
  75. * @param {string} userId user id
  76. */
  77. getAvatarUrl: function (userId) {
  78. if (config.disableThirdPartyRequests) {
  79. return 'images/avatar2.png';
  80. }
  81. if (!userId || APP.conference.isLocalId(userId)) {
  82. userId = "local";
  83. }
  84. let avatarId = null;
  85. const user = users[userId];
  86. // The priority is url, email and lowest is avatarId
  87. if(user) {
  88. if(user.url)
  89. return user.url;
  90. if (user.email)
  91. avatarId = user.email;
  92. else {
  93. avatarId = user.avatarId;
  94. }
  95. }
  96. // If the ID looks like an email, we'll use gravatar.
  97. // Otherwise, it's a random avatar, and we'll use the configured
  98. // URL.
  99. let random = !avatarId || avatarId.indexOf('@') < 0;
  100. if (!avatarId) {
  101. logger.warn(
  102. `No avatar stored yet for ${userId} - using ID as avatar ID`);
  103. avatarId = userId;
  104. }
  105. avatarId = MD5.hexdigest(avatarId.trim().toLowerCase());
  106. let urlPref = null;
  107. let urlSuf = null;
  108. if (!random) {
  109. urlPref = 'https://www.gravatar.com/avatar/';
  110. urlSuf = "?d=wavatar&size=200";
  111. }
  112. else if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
  113. urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
  114. urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
  115. }
  116. else {
  117. urlPref = 'https://api.adorable.io/avatars/200/';
  118. urlSuf = ".png";
  119. }
  120. return urlPref + avatarId + urlSuf;
  121. }
  122. };