You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Avatar.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* global Strophe, APP, MD5, config, interfaceConfig */
  2. var users = {};
  3. var Avatar = {
  4. /**
  5. * Sets the user's avatar in the settings menu(if local user), contact list
  6. * and thumbnail
  7. * @param id id of the user
  8. * @param email email or nickname to be used as a hash
  9. */
  10. setUserAvatar: function (id, email) {
  11. if (email) {
  12. if (users[id] === email) {
  13. return;
  14. }
  15. users[id] = email;
  16. }
  17. var thumbUrl = this.getThumbUrl(id);
  18. var contactListUrl = this.getContactListUrl(id);
  19. },
  20. /**
  21. * Returns image URL for the avatar to be displayed on large video area
  22. * where current dominant speaker is presented.
  23. * @param id id of the user for whom we want to obtain avatar URL
  24. */
  25. getDominantSpeakerUrl: function (id) {
  26. return this.getGravatarUrl(id, 100);
  27. },
  28. /**
  29. * Returns image URL for the avatar to be displayed on small video thumbnail
  30. * @param id id of the user for whom we want to obtain avatar URL
  31. */
  32. getThumbUrl: function (id) {
  33. return this.getGravatarUrl(id, 100);
  34. },
  35. /**
  36. * Returns the URL for the avatar to be displayed as contactlist item
  37. * @param id id of the user for whom we want to obtain avatar URL
  38. */
  39. getContactListUrl: function (id) {
  40. return this.getGravatarUrl(id, 30);
  41. },
  42. getGravatarUrl: function (id, size) {
  43. if (!id) {
  44. console.error("Get gravatar - id is undefined");
  45. return null;
  46. }
  47. // Default to using gravatar.
  48. var urlPref = 'https://www.gravatar.com/avatar/';
  49. var urlSuf = "?d=wavatar&size=" + (size || "30");
  50. // If we have a real email we will use it for the gravatar and we'll
  51. // use the pre-configured URL if any. Otherwise, it's a random avatar.
  52. var email = users[id];
  53. if (email && email.indexOf('@')) {
  54. id = email;
  55. if (interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
  56. urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
  57. urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
  58. }
  59. }
  60. if (!config.disableThirdPartyRequests) {
  61. return urlPref +
  62. MD5.hexdigest(id.trim().toLowerCase()) +
  63. urlSuf;
  64. } else {
  65. return 'images/avatar2.png';
  66. }
  67. }
  68. };
  69. module.exports = Avatar;