Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Avatar.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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(
  52. "No avatar stored yet for " + jid + " - using JID as ID");
  53. id = jid;
  54. }
  55. return 'https://www.gravatar.com/avatar/' +
  56. MD5.hexdigest(id.trim().toLowerCase()) +
  57. "?d=wavatar&size=" + (size || "30");
  58. }
  59. };
  60. module.exports = Avatar;