2015-12-11 14:48:16 +00:00
|
|
|
/* global $, APP */
|
|
|
|
import Avatar from '../../avatar/Avatar';
|
2015-12-14 15:40:30 +00:00
|
|
|
import UIEvents from '../../../../service/UI/UIEvents';
|
2016-04-08 15:55:19 +00:00
|
|
|
import UIUtil from '../../util/UIUtil';
|
2015-07-20 17:32:04 +00:00
|
|
|
|
2015-12-14 15:40:30 +00:00
|
|
|
let numberOfContacts = 0;
|
|
|
|
let notificationInterval;
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2014-08-22 15:37:11 +00:00
|
|
|
/**
|
2015-01-07 14:54:03 +00:00
|
|
|
* Updates the number of participants in the contact list button and sets
|
|
|
|
* the glow
|
|
|
|
* @param delta indicates whether a new user has joined (1) or someone has
|
|
|
|
* left(-1)
|
2014-08-22 15:37:11 +00:00
|
|
|
*/
|
2015-01-07 14:54:03 +00:00
|
|
|
function updateNumberOfParticipants(delta) {
|
2015-07-06 10:24:40 +00:00
|
|
|
numberOfContacts += delta;
|
|
|
|
if (numberOfContacts === 1) {
|
|
|
|
// when the user is alone we don't show the number of participants
|
2015-01-07 14:54:03 +00:00
|
|
|
$("#numberOfParticipants").text('');
|
2015-07-06 10:24:40 +00:00
|
|
|
ContactList.setVisualNotification(false);
|
|
|
|
} else if (numberOfContacts > 1) {
|
|
|
|
ContactList.setVisualNotification(!ContactList.isVisible());
|
2015-01-07 14:54:03 +00:00
|
|
|
$("#numberOfParticipants").text(numberOfContacts);
|
2015-07-06 10:24:40 +00:00
|
|
|
} else {
|
|
|
|
console.error("Invalid number of participants: " + numberOfContacts);
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-02 09:30:46 +00:00
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
/**
|
|
|
|
* Creates the avatar element.
|
|
|
|
*
|
2015-07-28 21:52:32 +00:00
|
|
|
* @return {object} the newly created avatar element
|
2015-01-07 14:54:03 +00:00
|
|
|
*/
|
2015-07-20 17:32:04 +00:00
|
|
|
function createAvatar(jid) {
|
2015-12-14 15:40:30 +00:00
|
|
|
let avatar = document.createElement('img');
|
2015-01-07 14:54:03 +00:00
|
|
|
avatar.className = "icon-avatar avatar";
|
2016-01-19 23:10:44 +00:00
|
|
|
avatar.src = Avatar.getAvatarUrl(jid);
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
return avatar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the display name paragraph.
|
|
|
|
*
|
|
|
|
* @param displayName the display name to set
|
|
|
|
*/
|
2015-03-09 15:50:13 +00:00
|
|
|
function createDisplayNameParagraph(key, displayName) {
|
2015-12-14 15:40:30 +00:00
|
|
|
let p = document.createElement('p');
|
2015-12-11 14:48:16 +00:00
|
|
|
if (displayName) {
|
2016-01-14 22:34:22 +00:00
|
|
|
p.innerHTML = displayName;
|
2015-12-11 14:48:16 +00:00
|
|
|
} else if(key) {
|
2015-03-09 15:50:13 +00:00
|
|
|
p.setAttribute("data-i18n",key);
|
2016-01-14 22:34:22 +00:00
|
|
|
p.innerHTML = APP.translation.translateString(key);
|
2015-03-09 15:50:13 +00:00
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function stopGlowing(glower) {
|
|
|
|
window.clearInterval(notificationInterval);
|
|
|
|
notificationInterval = false;
|
|
|
|
glower.removeClass('glowing');
|
|
|
|
if (!ContactList.isVisible()) {
|
|
|
|
glower.removeClass('active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 14:48:16 +00:00
|
|
|
function getContactEl (id) {
|
|
|
|
return $(`#contacts>li[id="${id}"]`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function contactElExists (id) {
|
|
|
|
return getContactEl(id).length > 0;
|
|
|
|
}
|
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
/**
|
|
|
|
* Contact list.
|
|
|
|
*/
|
|
|
|
var ContactList = {
|
2015-12-14 15:40:30 +00:00
|
|
|
init (emitter) {
|
|
|
|
this.emitter = emitter;
|
|
|
|
},
|
2014-08-22 15:37:11 +00:00
|
|
|
/**
|
|
|
|
* Indicates if the chat is currently visible.
|
|
|
|
*
|
|
|
|
* @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
|
|
|
|
* otherwise
|
|
|
|
*/
|
2015-12-14 15:40:30 +00:00
|
|
|
isVisible () {
|
2016-04-08 15:55:19 +00:00
|
|
|
return UIUtil.isVisible(document.getElementById("contactlist"));
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
2014-08-22 15:37:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-11 14:48:16 +00:00
|
|
|
* Adds a contact for the given id.
|
2014-08-22 15:37:11 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-12-14 15:40:30 +00:00
|
|
|
addContact (id) {
|
|
|
|
let contactlist = $('#contacts');
|
2014-08-22 15:37:11 +00:00
|
|
|
|
2015-12-14 15:40:30 +00:00
|
|
|
let newContact = document.createElement('li');
|
2015-12-11 14:48:16 +00:00
|
|
|
newContact.id = id;
|
2014-10-06 10:29:48 +00:00
|
|
|
newContact.className = "clickable";
|
2015-12-14 15:40:30 +00:00
|
|
|
newContact.onclick = (event) => {
|
2015-01-07 14:54:03 +00:00
|
|
|
if (event.currentTarget.className === "clickable") {
|
2015-12-14 15:40:30 +00:00
|
|
|
this.emitter.emit(UIEvents.CONTACT_CLICKED, id);
|
2014-10-06 10:29:48 +00:00
|
|
|
}
|
|
|
|
};
|
2014-08-22 15:37:11 +00:00
|
|
|
|
2015-12-11 14:48:16 +00:00
|
|
|
newContact.appendChild(createAvatar(id));
|
2015-03-09 15:50:13 +00:00
|
|
|
newContact.appendChild(createDisplayNameParagraph("participant"));
|
2014-08-22 15:37:11 +00:00
|
|
|
|
2015-12-11 14:48:16 +00:00
|
|
|
if (APP.conference.isLocalId(id)) {
|
2015-06-19 13:45:39 +00:00
|
|
|
contactlist.prepend(newContact);
|
2015-12-11 14:48:16 +00:00
|
|
|
} else {
|
2015-06-19 13:45:39 +00:00
|
|
|
contactlist.append(newContact);
|
2014-08-22 15:37:11 +00:00
|
|
|
}
|
2014-10-02 09:30:46 +00:00
|
|
|
updateNumberOfParticipants(1);
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
2014-08-22 15:37:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-11 14:48:16 +00:00
|
|
|
* Removes a contact for the given id.
|
2014-08-22 15:37:11 +00:00
|
|
|
*
|
|
|
|
*/
|
2015-12-14 15:40:30 +00:00
|
|
|
removeContact (id) {
|
2015-12-11 14:48:16 +00:00
|
|
|
let contact = getContactEl(id);
|
2014-10-02 09:30:46 +00:00
|
|
|
|
2015-12-11 14:48:16 +00:00
|
|
|
if (contact.length > 0) {
|
|
|
|
contact.remove();
|
2014-10-02 09:30:46 +00:00
|
|
|
updateNumberOfParticipants(-1);
|
2014-08-22 15:37:11 +00:00
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
2014-08-22 15:37:11 +00:00
|
|
|
|
2015-12-14 15:40:30 +00:00
|
|
|
setVisualNotification (show, stopGlowingIn) {
|
|
|
|
let glower = $('#contactListButton');
|
2014-10-02 09:30:46 +00:00
|
|
|
|
2014-10-31 11:47:12 +00:00
|
|
|
if (show && !notificationInterval) {
|
|
|
|
notificationInterval = window.setInterval(function () {
|
|
|
|
glower.toggleClass('active glowing');
|
|
|
|
}, 800);
|
2015-12-14 15:40:30 +00:00
|
|
|
} else if (!show && notificationInterval) {
|
2015-01-07 14:54:03 +00:00
|
|
|
stopGlowing(glower);
|
2014-10-02 09:30:46 +00:00
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
if (stopGlowingIn) {
|
|
|
|
setTimeout(function () {
|
|
|
|
stopGlowing(glower);
|
|
|
|
}, stopGlowingIn);
|
2014-08-22 15:37:11 +00:00
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
},
|
2014-08-22 15:37:11 +00:00
|
|
|
|
2015-12-14 15:40:30 +00:00
|
|
|
setClickable (id, isClickable) {
|
2015-12-11 14:48:16 +00:00
|
|
|
getContactEl(id).toggleClass('clickable', isClickable);
|
2015-01-19 09:20:00 +00:00
|
|
|
},
|
|
|
|
|
2015-12-14 15:40:30 +00:00
|
|
|
onDisplayNameChange (id, displayName) {
|
2016-04-09 17:04:01 +00:00
|
|
|
if(!displayName)
|
|
|
|
return;
|
2015-12-01 13:41:58 +00:00
|
|
|
if (id === 'localVideoContainer') {
|
2016-07-08 01:44:04 +00:00
|
|
|
id = APP.conference.getMyUserId();
|
2015-12-01 13:41:58 +00:00
|
|
|
}
|
2015-12-14 15:40:30 +00:00
|
|
|
let contactName = $(`#contacts #${id}>p`);
|
2015-01-19 09:20:00 +00:00
|
|
|
|
2016-04-09 17:04:01 +00:00
|
|
|
if (contactName.text() !== displayName) {
|
2016-02-12 12:48:57 +00:00
|
|
|
contactName.text(displayName);
|
2015-12-01 13:41:58 +00:00
|
|
|
}
|
2015-06-29 14:24:21 +00:00
|
|
|
},
|
|
|
|
|
2016-01-19 23:10:44 +00:00
|
|
|
changeUserAvatar (id, avatarUrl) {
|
2015-06-29 14:24:21 +00:00
|
|
|
// set the avatar in the contact list
|
2015-12-14 15:40:30 +00:00
|
|
|
let contact = $(`#${id}>img`);
|
2015-12-11 14:48:16 +00:00
|
|
|
if (contact.length > 0) {
|
2016-01-19 23:10:44 +00:00
|
|
|
contact.attr('src', avatarUrl);
|
2015-06-29 14:24:21 +00:00
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
};
|
2014-10-06 10:29:48 +00:00
|
|
|
|
2015-12-14 15:40:30 +00:00
|
|
|
export default ContactList;
|