Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

contact_list.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * Contact list.
  3. */
  4. var ContactList = (function (my) {
  5. var numberOfContacts = 0;
  6. var notificationInterval;
  7. /**
  8. * Indicates if the chat is currently visible.
  9. *
  10. * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
  11. * otherwise
  12. */
  13. my.isVisible = function () {
  14. return $('#contactlist').is(":visible");
  15. };
  16. /**
  17. * Adds a contact for the given peerJid if such doesn't yet exist.
  18. *
  19. * @param peerJid the peerJid corresponding to the contact
  20. * @param id the user's email or userId used to get the user's avatar
  21. */
  22. my.ensureAddContact = function(peerJid, id) {
  23. var resourceJid = Strophe.getResourceFromJid(peerJid);
  24. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  25. if (!contact || contact.length <= 0)
  26. ContactList.addContact(peerJid,id);
  27. };
  28. /**
  29. * Adds a contact for the given peer jid.
  30. *
  31. * @param peerJid the jid of the contact to add
  32. * @param id the email or userId of the user
  33. */
  34. my.addContact = function(peerJid, id) {
  35. var resourceJid = Strophe.getResourceFromJid(peerJid);
  36. var contactlist = $('#contactlist>ul');
  37. var newContact = document.createElement('li');
  38. // XXX(gp) contact click event handling is now in videolayout.js. Is the
  39. // following statement (newContact.id = resourceJid) still relevant?
  40. newContact.id = resourceJid;
  41. newContact.className = "clickable";
  42. newContact.onclick = function(event) {
  43. if(event.currentTarget.className === "clickable") {
  44. $(ContactList).trigger('contactclicked', [peerJid]);
  45. }
  46. };
  47. newContact.appendChild(createAvatar(id));
  48. newContact.appendChild(createDisplayNameParagraph("Participant"));
  49. var clElement = contactlist.get(0);
  50. if (resourceJid === Strophe.getResourceFromJid(connection.emuc.myroomjid)
  51. && $('#contactlist>ul .title')[0].nextSibling.nextSibling)
  52. {
  53. clElement.insertBefore(newContact,
  54. $('#contactlist>ul .title')[0].nextSibling.nextSibling);
  55. }
  56. else {
  57. clElement.appendChild(newContact);
  58. }
  59. updateNumberOfParticipants(1);
  60. };
  61. /**
  62. * Removes a contact for the given peer jid.
  63. *
  64. * @param peerJid the peerJid corresponding to the contact to remove
  65. */
  66. my.removeContact = function(peerJid) {
  67. var resourceJid = Strophe.getResourceFromJid(peerJid);
  68. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  69. if (contact && contact.length > 0) {
  70. var contactlist = $('#contactlist>ul');
  71. contactlist.get(0).removeChild(contact.get(0));
  72. updateNumberOfParticipants(-1);
  73. }
  74. };
  75. my.setVisualNotification = function(show, stopGlowingIn) {
  76. var glower = $('#contactListButton');
  77. function stopGlowing() {
  78. window.clearInterval(notificationInterval);
  79. notificationInterval = false;
  80. glower.removeClass('glowing');
  81. if(!ContactList.isVisible()) {
  82. glower.removeClass('active');
  83. }
  84. }
  85. if (show && !notificationInterval) {
  86. notificationInterval = window.setInterval(function () {
  87. glower.toggleClass('active glowing');
  88. }, 800);
  89. }
  90. else if (!show && notificationInterval) {
  91. stopGlowing();
  92. }
  93. if(stopGlowingIn) {
  94. setTimeout(stopGlowing, stopGlowingIn);
  95. }
  96. };
  97. /**
  98. * Updates the number of participants in the contact list button and sets
  99. * the glow
  100. * @param delta indicates whether a new user has joined (1) or someone has
  101. * left(-1)
  102. */
  103. function updateNumberOfParticipants(delta) {
  104. //when the user is alone we don't show the number of participants
  105. if(numberOfContacts === 0) {
  106. $("#numberOfParticipants").text('');
  107. numberOfContacts += delta;
  108. } else if(numberOfContacts !== 0 && !ContactList.isVisible()) {
  109. ContactList.setVisualNotification(true);
  110. numberOfContacts += delta;
  111. $("#numberOfParticipants").text(numberOfContacts);
  112. }
  113. }
  114. /**
  115. * Creates the avatar element.
  116. *
  117. * @return the newly created avatar element
  118. */
  119. function createAvatar(id) {
  120. var avatar = document.createElement('img');
  121. avatar.className = "icon-avatar avatar";
  122. avatar.src = "https://www.gravatar.com/avatar/" + id + "?d=retro&size=30";
  123. return avatar;
  124. }
  125. /**
  126. * Creates the display name paragraph.
  127. *
  128. * @param displayName the display name to set
  129. */
  130. function createDisplayNameParagraph(displayName) {
  131. var p = document.createElement('p');
  132. p.innerText = displayName;
  133. return p;
  134. }
  135. /**
  136. * Indicates that the display name has changed.
  137. */
  138. $(document).bind( 'displaynamechanged',
  139. function (event, peerJid, displayName) {
  140. if (peerJid === 'localVideoContainer')
  141. peerJid = connection.emuc.myroomjid;
  142. var resourceJid = Strophe.getResourceFromJid(peerJid);
  143. var contactName = $('#contactlist #' + resourceJid + '>p');
  144. if (contactName && displayName && displayName.length > 0)
  145. contactName.text(displayName);
  146. });
  147. my.setClickable = function(resourceJid, isClickable) {
  148. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  149. if(isClickable) {
  150. contact.addClass('clickable');
  151. } else {
  152. contact.removeClass('clickable');
  153. }
  154. };
  155. return my;
  156. }(ContactList || {}));