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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. var Settings = require("../../settings/Settings");
  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 jid jid of the user
  8. * @param id email or userID to be used as a hash
  9. */
  10. setUserAvatar: function (jid, id) {
  11. if (id) {
  12. if (users[jid] === id) {
  13. return;
  14. }
  15. users[jid] = id;
  16. }
  17. var thumbUrl = this.getThumbUrl(jid);
  18. var contactListUrl = this.getContactListUrl(jid);
  19. var resourceJid = Strophe.getResourceFromJid(jid);
  20. APP.UI.userAvatarChanged(resourceJid, thumbUrl, contactListUrl);
  21. },
  22. /**
  23. * Returns image URL for the avatar to be displayed on large video area
  24. * where current active speaker is presented.
  25. * @param jid full MUC jid of the user for whom we want to obtain avatar URL
  26. */
  27. getActiveSpeakerUrl: function (jid) {
  28. return this.getGravatarUrl(jid, 100);
  29. },
  30. /**
  31. * Returns image URL for the avatar to be displayed on small video thumbnail
  32. * @param jid full MUC jid of the user for whom we want to obtain avatar URL
  33. */
  34. getThumbUrl: function (jid) {
  35. return this.getGravatarUrl(jid, 100);
  36. },
  37. /**
  38. * Returns the URL for the avatar to be displayed as contactlist item
  39. * @param jid full MUC jid of the user for whom we want to obtain avatar URL
  40. */
  41. getContactListUrl: function (jid) {
  42. return this.getGravatarUrl(jid, 30);
  43. },
  44. getGravatarUrl: function (jid, size) {
  45. if (!jid) {
  46. console.error("Get gravatar - jid is undefined");
  47. return null;
  48. }
  49. var id = users[jid];
  50. if (!id) {
  51. console.warn("No avatar stored yet for " + jid);
  52. return null;
  53. }
  54. return 'https://www.gravatar.com/avatar/' +
  55. MD5.hexdigest(id.trim().toLowerCase()) +
  56. "?d=wavatar&size=" + (size || "30");
  57. }
  58. };
  59. module.exports = Avatar;