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

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