2016-10-12 00:08:24 +00:00
|
|
|
/* global APP */
|
2016-09-08 18:16:23 +00:00
|
|
|
|
2016-10-12 00:08:24 +00:00
|
|
|
import UIEvents from '../../../../service/UI/UIEvents';
|
|
|
|
import ContactListView from './ContactListView';
|
|
|
|
import Contact from './Contact';
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
/**
|
2016-10-12 00:08:24 +00:00
|
|
|
* Model for the Contact list.
|
2015-01-07 14:54:03 +00:00
|
|
|
*
|
2016-10-12 00:08:24 +00:00
|
|
|
* @class ContactList
|
2015-01-07 14:54:03 +00:00
|
|
|
*/
|
2016-10-12 00:08:24 +00:00
|
|
|
class ContactList {
|
|
|
|
constructor(conference) {
|
|
|
|
this.conference = conference;
|
|
|
|
this.contacts = [];
|
|
|
|
this.roomLocked = false;
|
2016-10-25 13:16:15 +00:00
|
|
|
//setup ContactList Model into ContactList View
|
|
|
|
ContactListView.setup(this);
|
2015-03-09 15:50:13 +00:00
|
|
|
}
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2014-08-22 15:37:11 +00:00
|
|
|
/**
|
2017-04-13 00:23:43 +00:00
|
|
|
* Returns true if the current conference is locked.
|
2014-08-22 15:37:11 +00:00
|
|
|
*
|
2016-10-12 00:08:24 +00:00
|
|
|
* @returns {Boolean}
|
2014-08-22 15:37:11 +00:00
|
|
|
*/
|
2016-10-12 00:08:24 +00:00
|
|
|
isLocked() {
|
2017-04-18 21:49:52 +00:00
|
|
|
return APP.store.getState()['features/base/conference'].locked;
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
2014-08-22 15:37:11 +00:00
|
|
|
|
|
|
|
/**
|
2016-10-12 00:08:24 +00:00
|
|
|
* Adding new participant.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param isLocal
|
2014-08-22 15:37:11 +00:00
|
|
|
*/
|
2016-10-12 00:08:24 +00:00
|
|
|
addContact(id, isLocal) {
|
2017-04-18 21:49:52 +00:00
|
|
|
const exists = this.contacts.some(el => el.id === id);
|
2014-08-22 15:37:11 +00:00
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
if (!exists) {
|
2016-10-12 00:08:24 +00:00
|
|
|
let newContact = new Contact({ id, isLocal });
|
|
|
|
this.contacts.push(newContact);
|
|
|
|
APP.UI.emitEvent(UIEvents.CONTACT_ADDED, { id, isLocal });
|
2014-08-22 15:37:11 +00:00
|
|
|
}
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
2014-08-22 15:37:11 +00:00
|
|
|
|
|
|
|
/**
|
2016-10-12 00:08:24 +00:00
|
|
|
* Removing participant.
|
2014-08-22 15:37:11 +00:00
|
|
|
*
|
2016-10-12 00:08:24 +00:00
|
|
|
* @param id
|
|
|
|
* @returns {Array|*}
|
2014-08-22 15:37:11 +00:00
|
|
|
*/
|
2016-10-12 00:08:24 +00:00
|
|
|
removeContact(id) {
|
|
|
|
this.contacts = this.contacts.filter((el) => el.id !== id);
|
|
|
|
APP.UI.emitEvent(UIEvents.CONTACT_REMOVED, { id });
|
|
|
|
return this.contacts;
|
|
|
|
}
|
2015-01-19 09:20:00 +00:00
|
|
|
|
2016-10-12 00:08:24 +00:00
|
|
|
/**
|
|
|
|
* Changing the display name.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param name
|
|
|
|
*/
|
|
|
|
onDisplayNameChange (id, name) {
|
|
|
|
if(!name)
|
2016-04-09 17:04:01 +00:00
|
|
|
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-01-19 09:20:00 +00:00
|
|
|
|
2016-10-12 00:08:24 +00:00
|
|
|
let contacts = this.contacts.filter((el) => el.id === id);
|
|
|
|
contacts.forEach((el) => {
|
|
|
|
el.name = name;
|
|
|
|
});
|
|
|
|
APP.UI.emitEvent(UIEvents.DISPLAY_NAME_CHANGED, { id, name });
|
|
|
|
}
|
2015-06-29 14:24:21 +00:00
|
|
|
|
2016-10-12 00:08:24 +00:00
|
|
|
/**
|
|
|
|
* Changing the avatar.
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param avatar
|
|
|
|
*/
|
|
|
|
changeUserAvatar (id, avatar) {
|
|
|
|
let contacts = this.contacts.filter((el) => el.id === id);
|
|
|
|
contacts.forEach((el) => {
|
|
|
|
el.avatar = avatar;
|
|
|
|
});
|
|
|
|
APP.UI.emitEvent(UIEvents.USER_AVATAR_CHANGED, { id, avatar });
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
2016-10-12 00:08:24 +00:00
|
|
|
}
|
2014-10-06 10:29:48 +00:00
|
|
|
|
2017-04-18 21:49:52 +00:00
|
|
|
export default ContactList;
|