選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ContactList.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* global $, APP, interfaceConfig */
  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. * @param isLocal is an id for the local user.
  85. */
  86. addContact (id, isLocal) {
  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. if (interfaceConfig.SHOW_CONTACTLIST_AVATARS)
  97. newContact.appendChild(createAvatar(id));
  98. newContact.appendChild(
  99. createDisplayNameParagraph(
  100. isLocal ? interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME : null,
  101. isLocal ? null : interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME));
  102. if (APP.conference.isLocalId(id)) {
  103. contactlist.prepend(newContact);
  104. } else {
  105. contactlist.append(newContact);
  106. }
  107. updateNumberOfParticipants(1);
  108. },
  109. /**
  110. * Removes a contact for the given id.
  111. *
  112. */
  113. removeContact (id) {
  114. let contact = getContactEl(id);
  115. if (contact.length > 0) {
  116. contact.remove();
  117. updateNumberOfParticipants(-1);
  118. }
  119. },
  120. setClickable (id, isClickable) {
  121. getContactEl(id).toggleClass('clickable', isClickable);
  122. },
  123. onDisplayNameChange (id, displayName) {
  124. if(!displayName)
  125. return;
  126. if (id === 'localVideoContainer') {
  127. id = APP.conference.getMyUserId();
  128. }
  129. let contactName = $(`#contacts #${id}>p`);
  130. if (contactName.text() !== displayName) {
  131. contactName.text(displayName);
  132. }
  133. },
  134. changeUserAvatar (id, avatarUrl) {
  135. // set the avatar in the contact list
  136. let contact = $(`#${id}>img`);
  137. if (contact.length > 0) {
  138. contact.attr('src', avatarUrl);
  139. }
  140. }
  141. };
  142. export default ContactList;