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.

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