Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ContactListView.js 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* global $, APP, interfaceConfig */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import { openInviteDialog } from '../../../../react/features/invite';
  4. import Avatar from '../../avatar/Avatar';
  5. import UIEvents from '../../../../service/UI/UIEvents';
  6. import UIUtil from '../../util/UIUtil';
  7. let numberOfContacts = 0;
  8. const sidePanelsContainerId = 'sideToolbarContainer';
  9. const htmlStr = `
  10. <div id="contacts_container" class="sideToolbarContainer__inner">
  11. <div class="title" data-i18n="contactlist"
  12. data-i18n-options='{"pcount":"1"}'></div>
  13. <ul id="contacts"></ul>
  14. </div>`;
  15. function initHTML() {
  16. $(`#${sidePanelsContainerId}`)
  17. .append(htmlStr);
  18. }
  19. /**
  20. * Updates the number of participants in the contact list button and sets
  21. * the glow
  22. * @param delta indicates whether a new user has joined (1) or someone has
  23. * left(-1)
  24. */
  25. function updateNumberOfParticipants(delta) {
  26. numberOfContacts += delta;
  27. if (numberOfContacts <= 0) {
  28. logger.error("Invalid number of participants: " + numberOfContacts);
  29. return;
  30. }
  31. $("#numberOfParticipants").text(numberOfContacts);
  32. APP.translation.translateElement(
  33. $("#contacts_container>div.title"), {pcount: numberOfContacts});
  34. }
  35. /**
  36. * Creates the avatar element.
  37. *
  38. * @return {object} the newly created avatar element
  39. */
  40. function createAvatar(jid) {
  41. let avatar = document.createElement('img');
  42. avatar.className = "icon-avatar avatar";
  43. avatar.src = Avatar.getAvatarUrl(jid);
  44. return avatar;
  45. }
  46. /**
  47. * Creates the display name paragraph.
  48. *
  49. * @param displayName the display name to set
  50. */
  51. function createDisplayNameParagraph(key, displayName) {
  52. let p = document.createElement('p');
  53. if (displayName) {
  54. p.innerHTML = displayName;
  55. } else if(key) {
  56. p.setAttribute("data-i18n",key);
  57. }
  58. return p;
  59. }
  60. /**
  61. * Getter for current contact element
  62. * @param id
  63. * @returns {JQuery}
  64. */
  65. function getContactEl (id) {
  66. return $(`#contacts>li[id="${id}"]`);
  67. }
  68. /**
  69. * Contact list.
  70. */
  71. var ContactListView = {
  72. init () {
  73. initHTML();
  74. this.lockKey = 'roomLocked';
  75. this.unlockKey = 'roomUnlocked';
  76. },
  77. /**
  78. * setup ContactList Model into ContactList View
  79. *
  80. * @param model
  81. */
  82. setup (model) {
  83. this.model = model;
  84. this.addInviteButton();
  85. this.registerListeners();
  86. this.setLockDisplay(false);
  87. },
  88. /**
  89. * Adds layout for invite button
  90. */
  91. addInviteButton() {
  92. let container = document.getElementById('contacts_container');
  93. container.firstElementChild // this is the title
  94. .insertAdjacentHTML('afterend', this.getInviteButtonLayout());
  95. APP.translation.translateElement($(container));
  96. $(document).on('click', '#addParticipantsBtn', () => {
  97. APP.store.dispatch(openInviteDialog());
  98. });
  99. },
  100. /**
  101. * Returns layout for invite button
  102. */
  103. getInviteButtonLayout() {
  104. let classes = 'button-control button-control_primary';
  105. classes += ' button-control_full-width';
  106. let key = 'addParticipants';
  107. let lockedHtml = this.getLockDescriptionLayout(this.lockKey);
  108. let unlockedHtml = this.getLockDescriptionLayout(this.unlockKey);
  109. return (
  110. `<div class="sideToolbarBlock first">
  111. <button id="addParticipantsBtn"
  112. data-i18n="${key}"
  113. class="${classes}"></button>
  114. <div>
  115. ${lockedHtml}
  116. ${unlockedHtml}
  117. </div>
  118. </div>`);
  119. },
  120. /**
  121. * Adds layout for lock description
  122. */
  123. getLockDescriptionLayout(key) {
  124. let classes = "form-control__hint form-control_full-width";
  125. let padlockSuffix = '';
  126. if (key === this.lockKey) {
  127. padlockSuffix = '-locked';
  128. }
  129. return `<p id="contactList${key}" class="${classes}">
  130. <span class="icon-security${padlockSuffix}"></span>
  131. <span data-i18n="${key}"></span>
  132. </p>`;
  133. },
  134. /**
  135. * Setup listeners
  136. */
  137. registerListeners() {
  138. let removeContact = this.onRemoveContact.bind(this);
  139. let changeAvatar = this.changeUserAvatar.bind(this);
  140. let displayNameChange = this.onDisplayNameChange.bind(this);
  141. APP.UI.addListener( UIEvents.TOGGLE_ROOM_LOCK,
  142. this.setLockDisplay.bind(this));
  143. APP.UI.addListener( UIEvents.CONTACT_ADDED,
  144. this.onAddContact.bind(this));
  145. APP.UI.addListener(UIEvents.CONTACT_REMOVED, removeContact);
  146. APP.UI.addListener(UIEvents.USER_AVATAR_CHANGED, changeAvatar);
  147. APP.UI.addListener(UIEvents.DISPLAY_NAME_CHANGED, displayNameChange);
  148. },
  149. /**
  150. * Updates the view according to the passed in lock state.
  151. *
  152. * @param {boolean} isLocked - True if the locked UI state should display.
  153. */
  154. setLockDisplay(isLocked) {
  155. const showKey = isLocked ? this.lockKey : this.unlockKey;
  156. const hideKey = !isLocked ? this.lockKey : this.unlockKey;
  157. const showId = `contactList${showKey}`;
  158. const hideId = `contactList${hideKey}`;
  159. $(`#${showId}`).show();
  160. $(`#${hideId}`).hide();
  161. },
  162. /**
  163. * Indicates if the chat is currently visible.
  164. *
  165. * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
  166. * otherwise
  167. */
  168. isVisible () {
  169. return UIUtil.isVisible(document.getElementById("contactlist"));
  170. },
  171. /**
  172. * Handler for Adding a contact for the given id.
  173. * @param isLocal is an id for the local user.
  174. */
  175. onAddContact (data) {
  176. let { id, isLocal } = data;
  177. let contactlist = $('#contacts');
  178. let newContact = document.createElement('li');
  179. newContact.id = id;
  180. newContact.className = "clickable";
  181. newContact.onclick = (event) => {
  182. if (event.currentTarget.className === "clickable") {
  183. APP.UI.emitEvent(UIEvents.CONTACT_CLICKED, id);
  184. }
  185. };
  186. if (interfaceConfig.SHOW_CONTACTLIST_AVATARS)
  187. newContact.appendChild(createAvatar(id));
  188. newContact.appendChild(
  189. createDisplayNameParagraph(
  190. isLocal ? interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME : null,
  191. isLocal ? null : interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME));
  192. APP.translation.translateElement($(newContact));
  193. if (APP.conference.isLocalId(id)) {
  194. contactlist.prepend(newContact);
  195. } else {
  196. contactlist.append(newContact);
  197. }
  198. updateNumberOfParticipants(1);
  199. },
  200. /**
  201. * Handler for removing
  202. * a contact for the given id.
  203. */
  204. onRemoveContact (data) {
  205. let { id } = data;
  206. let contact = getContactEl(id);
  207. if (contact.length > 0) {
  208. contact.remove();
  209. updateNumberOfParticipants(-1);
  210. }
  211. },
  212. setClickable (id, isClickable) {
  213. getContactEl(id).toggleClass('clickable', isClickable);
  214. },
  215. /**
  216. * Changes display name of the user
  217. * defined by its id
  218. * @param data
  219. */
  220. onDisplayNameChange (data) {
  221. let { id, name } = data;
  222. if(!name)
  223. return;
  224. if (id === 'localVideoContainer') {
  225. id = APP.conference.getMyUserId();
  226. }
  227. let contactName = $(`#contacts #${id}>p`);
  228. if (contactName.text() !== name) {
  229. contactName.text(name);
  230. }
  231. },
  232. /**
  233. * Changes user avatar
  234. * @param data
  235. */
  236. changeUserAvatar (data) {
  237. let { id, avatar } = data;
  238. // set the avatar in the contact list
  239. let contact = $(`#${id}>img`);
  240. if (contact.length > 0) {
  241. contact.attr('src', avatar);
  242. }
  243. }
  244. };
  245. export default ContactListView;