Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Avatar.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* global MD5, config, interfaceConfig */
  2. let users = {};
  3. export default {
  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. },
  18. /**
  19. * Returns the URL of the image for the avatar of a particular user,
  20. * identified by its id.
  21. * @param {string} userId user id
  22. */
  23. getAvatarUrl: function (userId) {
  24. if (config.disableThirdPartyRequests) {
  25. return 'images/avatar2.png';
  26. }
  27. if (!userId) {
  28. console.error("Get avatar - id is undefined");
  29. return null;
  30. }
  31. let avatarId = users[userId];
  32. // If the ID looks like an email, we'll use gravatar.
  33. // Otherwise, it's a random avatar, and we'll use the configured
  34. // URL.
  35. let random = !avatarId || avatarId.indexOf('@') < 0;
  36. if (!avatarId) {
  37. console.warn(
  38. `No avatar stored yet for ${userId} - using ID as avatar ID`);
  39. avatarId = userId;
  40. }
  41. avatarId = MD5.hexdigest(avatarId.trim().toLowerCase());
  42. // Default to using gravatar.
  43. let urlPref = 'https://www.gravatar.com/avatar/';
  44. let urlSuf = "?d=wavatar&size=100";
  45. if (random && interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
  46. urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
  47. urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
  48. }
  49. return urlPref + avatarId + urlSuf;
  50. }
  51. };