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 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Adorable Avatars service used at the end of this file is released under the
  3. * terms of the MIT License.
  4. *
  5. * Copyright (c) 2014 Adorable IO LLC
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. /* global APP */
  24. import { getAvatarURL } from '../../../react/features/base/participants';
  25. let users = {};
  26. export default {
  27. /**
  28. * Sets prop in users object.
  29. * @param id {string} user id or undefined for the local user.
  30. * @param prop {string} name of the prop
  31. * @param val {string} value to be set
  32. */
  33. _setUserProp: function (id, prop, val) {
  34. // FIXME: Fixes the issue with not be able to return avatar for the
  35. // local user when the conference has been left. Maybe there is beter
  36. // way to solve it.
  37. if(!id || APP.conference.isLocalId(id)) {
  38. id = "local";
  39. }
  40. if(!val || (users[id] && users[id][prop] === val))
  41. return;
  42. if(!users[id])
  43. users[id] = {};
  44. users[id][prop] = val;
  45. },
  46. /**
  47. * Sets the user's avatar in the settings menu(if local user), contact list
  48. * and thumbnail
  49. * @param id id of the user
  50. * @param email email or nickname to be used as a hash
  51. */
  52. setUserEmail: function (id, email) {
  53. this._setUserProp(id, "email", email);
  54. },
  55. /**
  56. * Sets the user's avatar in the settings menu(if local user), contact list
  57. * and thumbnail
  58. * @param id id of the user
  59. * @param url the url for the avatar
  60. */
  61. setUserAvatarUrl: function (id, url) {
  62. this._setUserProp(id, "avatarUrl", url);
  63. },
  64. /**
  65. * Sets the user's avatar id.
  66. * @param id id of the user
  67. * @param avatarId an id to be used for the avatar
  68. */
  69. setUserAvatarID: function (id, avatarId) {
  70. this._setUserProp(id, "avatarId", avatarId);
  71. },
  72. /**
  73. * Returns the URL of the image for the avatar of a particular user,
  74. * identified by its id.
  75. * @param {string} userId user id
  76. */
  77. getAvatarUrl: function (userId) {
  78. let user;
  79. if (!userId || APP.conference.isLocalId(userId)) {
  80. user = users.local;
  81. userId = APP.conference.getMyUserId();
  82. } else {
  83. user = users[userId];
  84. }
  85. return getAvatarURL({
  86. avatarID: user ? user.avatarId : undefined,
  87. avatarURL: user ? user.avatarUrl : undefined,
  88. email: user ? user.email : undefined,
  89. id: userId
  90. });
  91. }
  92. };