Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ContactList.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* global $, APP */
  2. import Avatar from '../../avatar/Avatar';
  3. import UIEvents from '../../../../service/UI/UIEvents';
  4. import UIUtil from '../../util/UIUtil';
  5. let numberOfContacts = 0;
  6. let notificationInterval;
  7. /**
  8. * Updates the number of participants in the contact list button and sets
  9. * the glow
  10. * @param delta indicates whether a new user has joined (1) or someone has
  11. * left(-1)
  12. */
  13. function updateNumberOfParticipants(delta) {
  14. numberOfContacts += delta;
  15. if (numberOfContacts <= 0) {
  16. console.error("Invalid number of participants: " + numberOfContacts);
  17. return;
  18. }
  19. let buttonIndicatorText = (numberOfContacts === 1) ? '' : numberOfContacts;
  20. $("#numberOfParticipants").text(buttonIndicatorText);
  21. $("#contacts_container>div.title").text(
  22. APP.translation.translateString(
  23. "contactlist", {participants: numberOfContacts}
  24. ));
  25. }
  26. /**
  27. * Creates the avatar element.
  28. *
  29. * @return {object} the newly created avatar element
  30. */
  31. function createAvatar(jid) {
  32. let avatar = document.createElement('img');
  33. avatar.className = "icon-avatar avatar";
  34. avatar.src = Avatar.getAvatarUrl(jid);
  35. return avatar;
  36. }
  37. /**
  38. * Creates the display name paragraph.
  39. *
  40. * @param displayName the display name to set
  41. */
  42. function createDisplayNameParagraph(key, displayName) {
  43. let p = document.createElement('p');
  44. if (displayName) {
  45. p.innerHTML = displayName;
  46. } else if(key) {
  47. p.setAttribute("data-i18n",key);
  48. p.innerHTML = APP.translation.translateString(key);
  49. }
  50. return p;
  51. }
  52. function stopGlowing(glower) {
  53. window.clearInterval(notificationInterval);
  54. notificationInterval = false;
  55. glower.removeClass('glowing');
  56. if (!ContactList.isVisible()) {
  57. glower.removeClass('active');
  58. }
  59. }
  60. function getContactEl (id) {
  61. return $(`#contacts>li[id="${id}"]`);
  62. }
  63. function contactElExists (id) {
  64. return getContactEl(id).length > 0;
  65. }
  66. /**
  67. * Contact list.
  68. */
  69. var ContactList = {
  70. init (emitter) {
  71. this.emitter = emitter;
  72. },
  73. /**
  74. * Indicates if the chat is currently visible.
  75. *
  76. * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
  77. * otherwise
  78. */
  79. isVisible () {
  80. return UIUtil.isVisible(document.getElementById("contactlist"));
  81. },
  82. /**
  83. * Adds a contact for the given id.
  84. *
  85. */
  86. addContact (id) {
  87. let contactlist = $('#contacts');
  88. let newContact = document.createElement('li');
  89. newContact.id = id;
  90. newContact.className = "clickable";
  91. newContact.onclick = (event) => {
  92. if (event.currentTarget.className === "clickable") {
  93. this.emitter.emit(UIEvents.CONTACT_CLICKED, id);
  94. }
  95. };
  96. newContact.appendChild(createAvatar(id));
  97. newContact.appendChild(createDisplayNameParagraph("participant"));
  98. if (APP.conference.isLocalId(id)) {
  99. contactlist.prepend(newContact);
  100. } else {
  101. contactlist.append(newContact);
  102. }
  103. updateNumberOfParticipants(1);
  104. },
  105. /**
  106. * Removes a contact for the given id.
  107. *
  108. */
  109. removeContact (id) {
  110. let contact = getContactEl(id);
  111. if (contact.length > 0) {
  112. contact.remove();
  113. updateNumberOfParticipants(-1);
  114. }
  115. },
  116. setClickable (id, isClickable) {
  117. getContactEl(id).toggleClass('clickable', isClickable);
  118. },
  119. onDisplayNameChange (id, displayName) {
  120. if(!displayName)
  121. return;
  122. if (id === 'localVideoContainer') {
  123. id = APP.conference.getMyUserId();
  124. }
  125. let contactName = $(`#contacts #${id}>p`);
  126. if (contactName.text() !== displayName) {
  127. contactName.text(displayName);
  128. }
  129. },
  130. changeUserAvatar (id, avatarUrl) {
  131. // set the avatar in the contact list
  132. let contact = $(`#${id}>img`);
  133. if (contact.length > 0) {
  134. contact.attr('src', avatarUrl);
  135. }
  136. }
  137. };
  138. export default ContactList;