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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. const 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(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';// eslint-disable-line no-param-reassign
  39. }
  40. if (!val || (users[id] && users[id][prop] === val)) {
  41. return;
  42. }
  43. if (!users[id]) {
  44. users[id] = {};
  45. }
  46. users[id][prop] = val;
  47. },
  48. /**
  49. * Sets the user's avatar in the settings menu(if local user), contact list
  50. * and thumbnail
  51. * @param id id of the user
  52. * @param email email or nickname to be used as a hash
  53. */
  54. setUserEmail(id, email) {
  55. this._setUserProp(id, 'email', email);
  56. },
  57. /**
  58. * Sets the user's avatar in the settings menu(if local user), contact list
  59. * and thumbnail
  60. * @param id id of the user
  61. * @param url the url for the avatar
  62. */
  63. setUserAvatarUrl(id, url) {
  64. this._setUserProp(id, 'avatarUrl', url);
  65. },
  66. /**
  67. * Sets the user's avatar id.
  68. * @param id id of the user
  69. * @param avatarId an id to be used for the avatar
  70. */
  71. setUserAvatarID(id, avatarId) {
  72. this._setUserProp(id, 'avatarId', avatarId);
  73. },
  74. /**
  75. * Returns the URL of the image for the avatar of a particular user,
  76. * identified by its id.
  77. * @param {string} userId user id
  78. */
  79. getAvatarUrl(userId) {
  80. let user;
  81. if (!userId || APP.conference.isLocalId(userId)) {
  82. user = users.local;
  83. // eslint-disable-next-line no-param-reassign
  84. userId = APP.conference.getMyUserId();
  85. } else {
  86. user = users[userId];
  87. }
  88. return getAvatarURL({
  89. avatarID: user ? user.avatarId : undefined,
  90. avatarURL: user ? user.avatarUrl : undefined,
  91. email: user ? user.email : undefined,
  92. id: userId
  93. });
  94. }
  95. };