2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
2017-07-28 21:43:39 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2016-06-02 21:00:57 +08:00
|
|
|
import { withRouter } from 'react-router';
|
2017-06-05 07:20:38 +08:00
|
|
|
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
|
2016-06-29 22:24:27 +08:00
|
|
|
import cx from 'classnames';
|
2017-07-28 21:43:39 +08:00
|
|
|
|
2017-05-05 22:37:01 +08:00
|
|
|
import KEY_CODES from '/imports/utils/keyCodes';
|
2017-07-28 21:43:39 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
|
|
import UserListItem from './user-list-item/component';
|
|
|
|
import ChatListItem from './chat-list-item/component';
|
2016-05-20 02:22:56 +08:00
|
|
|
|
2016-06-29 03:52:03 +08:00
|
|
|
const propTypes = {
|
|
|
|
openChats: PropTypes.array.isRequired,
|
|
|
|
users: PropTypes.array.isRequired,
|
2017-07-28 21:43:39 +08:00
|
|
|
compact: PropTypes.bool,
|
2016-06-29 03:52:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
2017-07-28 21:43:39 +08:00
|
|
|
compact: false,
|
2016-06-29 03:52:03 +08:00
|
|
|
};
|
|
|
|
|
2016-06-28 21:10:20 +08:00
|
|
|
const listTransition = {
|
|
|
|
enter: styles.enter,
|
|
|
|
enterActive: styles.enterActive,
|
|
|
|
appear: styles.appear,
|
|
|
|
appearActive: styles.appearActive,
|
|
|
|
leave: styles.leave,
|
|
|
|
leaveActive: styles.leaveActive,
|
2016-06-29 03:52:03 +08:00
|
|
|
};
|
|
|
|
|
2017-08-05 04:05:18 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
usersTitle: {
|
|
|
|
id: 'app.userlist.usersTitle',
|
|
|
|
description: 'Title for the Header',
|
|
|
|
},
|
|
|
|
messagesTitle: {
|
|
|
|
id: 'app.userlist.messagesTitle',
|
|
|
|
description: 'Title for the messages list',
|
|
|
|
},
|
|
|
|
participantsTitle: {
|
|
|
|
id: 'app.userlist.participantsTitle',
|
|
|
|
description: 'Title for the Users list',
|
|
|
|
},
|
2017-07-28 21:43:39 +08:00
|
|
|
toggleCompactView: {
|
|
|
|
id: 'app.userlist.toggleCompactView.label',
|
|
|
|
description: 'Toggle user list view mode',
|
|
|
|
},
|
2017-08-05 04:05:18 +08:00
|
|
|
ChatLabel: {
|
|
|
|
id: 'app.userlist.menu.chat.label',
|
|
|
|
description: 'Save the changes and close the settings menu',
|
|
|
|
},
|
|
|
|
ClearStatusLabel: {
|
|
|
|
id: 'app.userlist.menu.clearStatus.label',
|
|
|
|
description: 'Clear the emoji status of this user',
|
|
|
|
},
|
|
|
|
MakePresenterLabel: {
|
|
|
|
id: 'app.userlist.menu.makePresenter.label',
|
|
|
|
description: 'Set this user to be the presenter in this meeting',
|
|
|
|
},
|
|
|
|
KickUserLabel: {
|
|
|
|
id: 'app.userlist.menu.kickUser.label',
|
|
|
|
description: 'Forcefully remove this user from the meeting',
|
|
|
|
},
|
|
|
|
MuteUserAudioLabel: {
|
|
|
|
id: 'app.userlist.menu.muteUserAudio.label',
|
|
|
|
description: 'Forcefully mute this user',
|
|
|
|
},
|
|
|
|
UnmuteUserAudioLabel: {
|
|
|
|
id: 'app.userlist.menu.unmuteUserAudio.label',
|
|
|
|
description: 'Forcefully unmute this user',
|
|
|
|
},
|
2017-08-19 02:23:05 +08:00
|
|
|
PromoteUserLabel: {
|
|
|
|
id: 'app.userlist.menu.promoteUser.label',
|
|
|
|
description: 'Forcefully promote this viewer to a moderator',
|
|
|
|
},
|
|
|
|
DemoteUserLabel: {
|
|
|
|
id: 'app.userlist.menu.demoteUser.label',
|
|
|
|
description: 'Forcefully demote this moderator to a viewer',
|
|
|
|
},
|
2017-08-05 04:05:18 +08:00
|
|
|
});
|
2016-06-29 03:52:03 +08:00
|
|
|
|
2016-06-02 21:00:57 +08:00
|
|
|
class UserList extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-08-25 02:56:06 +08:00
|
|
|
this.state = {
|
2016-09-15 01:48:50 +08:00
|
|
|
compact: this.props.compact,
|
2016-08-25 02:56:06 +08:00
|
|
|
};
|
2017-05-05 04:39:53 +08:00
|
|
|
|
2017-07-28 21:43:39 +08:00
|
|
|
this.handleToggleCompactView = this.handleToggleCompactView.bind(this);
|
|
|
|
|
2017-05-05 04:39:53 +08:00
|
|
|
this.rovingIndex = this.rovingIndex.bind(this);
|
2017-05-11 02:10:27 +08:00
|
|
|
this.focusList = this.focusList.bind(this);
|
2017-06-06 01:57:57 +08:00
|
|
|
this.focusedItemIndex = -1;
|
2017-05-05 04:39:53 +08:00
|
|
|
}
|
|
|
|
|
2017-06-06 01:57:57 +08:00
|
|
|
focusList(list) {
|
|
|
|
document.activeElement.tabIndex = -1;
|
|
|
|
this.focusedItemIndex = -1;
|
2017-05-11 02:10:27 +08:00
|
|
|
list.tabIndex = 0;
|
|
|
|
list.focus();
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:29:25 +08:00
|
|
|
rovingIndex(event, listType) {
|
2017-05-13 02:11:42 +08:00
|
|
|
const { users, openChats } = this.props;
|
2017-08-01 21:41:24 +08:00
|
|
|
|
2017-08-05 04:05:18 +08:00
|
|
|
const active = document.activeElement;
|
2017-05-06 03:11:28 +08:00
|
|
|
let list;
|
|
|
|
let items;
|
2017-06-06 01:57:57 +08:00
|
|
|
let numberOfItems;
|
2017-08-01 21:41:24 +08:00
|
|
|
|
2017-06-06 00:35:11 +08:00
|
|
|
const focusElement = () => {
|
|
|
|
active.tabIndex = -1;
|
2017-06-06 01:57:57 +08:00
|
|
|
items.childNodes[this.focusedItemIndex].tabIndex = 0;
|
|
|
|
items.childNodes[this.focusedItemIndex].focus();
|
2017-08-05 04:05:18 +08:00
|
|
|
};
|
2017-08-01 21:41:24 +08:00
|
|
|
|
2017-05-19 01:29:25 +08:00
|
|
|
switch (listType) {
|
2017-05-11 02:10:27 +08:00
|
|
|
case 'users':
|
2017-05-11 22:11:17 +08:00
|
|
|
list = this._usersList;
|
|
|
|
items = this._userItems;
|
2017-06-06 01:57:57 +08:00
|
|
|
numberOfItems = users.length;
|
2017-05-11 02:10:27 +08:00
|
|
|
break;
|
|
|
|
case 'messages':
|
2017-05-11 22:11:17 +08:00
|
|
|
list = this._msgsList;
|
|
|
|
items = this._msgItems;
|
2017-06-06 01:57:57 +08:00
|
|
|
numberOfItems = openChats.length;
|
2017-05-11 02:10:27 +08:00
|
|
|
break;
|
2017-07-28 21:43:39 +08:00
|
|
|
default: break;
|
2017-05-05 05:41:09 +08:00
|
|
|
}
|
2017-05-05 04:39:53 +08:00
|
|
|
|
2017-05-19 01:29:25 +08:00
|
|
|
if (event.keyCode === KEY_CODES.ESCAPE
|
2017-06-06 01:57:57 +08:00
|
|
|
|| this.focusedItemIndex < 0
|
|
|
|
|| this.focusedItemIndex > numberOfItems) {
|
2017-08-01 21:41:24 +08:00
|
|
|
this.focusList(list);
|
2017-05-06 03:11:28 +08:00
|
|
|
}
|
|
|
|
|
2017-06-08 23:33:25 +08:00
|
|
|
if ([KEY_CODES.ARROW_RIGHT, KEY_CODES.ARROW_SPACE].includes(event.keyCode)) {
|
|
|
|
active.firstChild.click();
|
2017-05-05 22:37:01 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:29:25 +08:00
|
|
|
if (event.keyCode === KEY_CODES.ARROW_DOWN) {
|
2017-06-06 01:57:57 +08:00
|
|
|
this.focusedItemIndex += 1;
|
2017-05-23 21:23:26 +08:00
|
|
|
|
2017-07-28 21:43:39 +08:00
|
|
|
if (this.focusedItemIndex === numberOfItems) {
|
2017-06-06 01:57:57 +08:00
|
|
|
this.focusedItemIndex = 0;
|
2017-05-05 04:39:53 +08:00
|
|
|
}
|
2017-06-06 00:35:11 +08:00
|
|
|
focusElement();
|
2017-05-05 04:39:53 +08:00
|
|
|
}
|
|
|
|
|
2017-05-19 01:29:25 +08:00
|
|
|
if (event.keyCode === KEY_CODES.ARROW_UP) {
|
2017-06-06 01:57:57 +08:00
|
|
|
this.focusedItemIndex -= 1;
|
2017-05-23 21:23:26 +08:00
|
|
|
|
2017-06-06 03:08:34 +08:00
|
|
|
if (this.focusedItemIndex < 0) {
|
2017-06-06 01:57:57 +08:00
|
|
|
this.focusedItemIndex = numberOfItems - 1;
|
2017-05-05 04:39:53 +08:00
|
|
|
}
|
2017-05-23 21:23:26 +08:00
|
|
|
|
2017-06-06 00:35:11 +08:00
|
|
|
focusElement();
|
2017-05-05 22:37:01 +08:00
|
|
|
}
|
2017-05-05 04:39:53 +08:00
|
|
|
}
|
|
|
|
|
2017-07-28 21:43:39 +08:00
|
|
|
handleToggleCompactView() {
|
|
|
|
this.setState({ compact: !this.state.compact });
|
|
|
|
}
|
|
|
|
|
2017-05-05 04:39:53 +08:00
|
|
|
componentDidMount() {
|
|
|
|
if (!this.state.compact) {
|
2017-05-23 21:23:26 +08:00
|
|
|
this._msgsList.addEventListener('keydown',
|
2017-08-05 04:05:18 +08:00
|
|
|
event => this.rovingIndex(event, 'messages'));
|
2017-05-05 04:39:53 +08:00
|
|
|
|
2017-05-23 21:23:26 +08:00
|
|
|
this._usersList.addEventListener('keydown',
|
2017-08-05 04:05:18 +08:00
|
|
|
event => this.rovingIndex(event, 'users'));
|
2017-05-05 04:39:53 +08:00
|
|
|
}
|
2016-06-02 21:00:57 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 03:29:22 +08:00
|
|
|
renderHeader() {
|
2017-04-04 02:05:47 +08:00
|
|
|
const { intl } = this.props;
|
|
|
|
|
2016-05-26 03:29:22 +08:00
|
|
|
return (
|
|
|
|
<div className={styles.header}>
|
2016-09-15 01:48:50 +08:00
|
|
|
{
|
|
|
|
!this.state.compact ?
|
2017-06-03 03:25:02 +08:00
|
|
|
<div className={styles.headerTitle} role="banner">
|
|
|
|
{intl.formatMessage(intlMessages.participantsTitle)}
|
|
|
|
</div> : null
|
2016-08-25 02:56:06 +08:00
|
|
|
}
|
2017-08-03 20:06:59 +08:00
|
|
|
{/* <Button
|
2017-07-28 21:43:39 +08:00
|
|
|
label={intl.formatMessage(intlMessages.toggleCompactView)}
|
|
|
|
hideLabel
|
|
|
|
icon={!this.state.compact ? 'left_arrow' : 'right_arrow'}
|
|
|
|
className={styles.btnToggle}
|
|
|
|
onClick={this.handleToggleCompactView}
|
2017-08-03 20:06:59 +08:00
|
|
|
/> */}
|
2016-05-26 03:29:22 +08:00
|
|
|
</div>
|
2016-06-02 21:00:57 +08:00
|
|
|
);
|
2016-05-26 03:29:22 +08:00
|
|
|
}
|
2016-05-20 02:22:56 +08:00
|
|
|
|
2016-05-26 03:29:22 +08:00
|
|
|
renderContent() {
|
|
|
|
return (
|
|
|
|
<div className={styles.content}>
|
|
|
|
{this.renderMessages()}
|
|
|
|
{this.renderParticipants()}
|
2016-05-20 02:22:56 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-05-26 03:29:22 +08:00
|
|
|
|
|
|
|
renderMessages() {
|
2016-06-29 03:52:03 +08:00
|
|
|
const {
|
|
|
|
openChats,
|
2016-06-30 22:45:19 +08:00
|
|
|
openChat,
|
2017-04-04 02:05:47 +08:00
|
|
|
intl,
|
2016-06-29 03:52:03 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2016-05-26 03:29:22 +08:00
|
|
|
return (
|
|
|
|
<div className={styles.messages}>
|
2016-09-15 01:48:50 +08:00
|
|
|
{
|
|
|
|
!this.state.compact ?
|
2017-06-03 03:25:02 +08:00
|
|
|
<div className={styles.smallTitle} role="banner">
|
|
|
|
{intl.formatMessage(intlMessages.messagesTitle)}
|
|
|
|
</div> : <hr className={styles.separator} />
|
2016-08-25 02:56:06 +08:00
|
|
|
}
|
2017-05-11 22:11:17 +08:00
|
|
|
<div
|
|
|
|
tabIndex={0}
|
|
|
|
className={styles.scrollableList}
|
2017-06-07 05:55:46 +08:00
|
|
|
ref={(ref) => { this._msgsList = ref; }}
|
2017-06-03 03:25:02 +08:00
|
|
|
>
|
2017-06-05 07:20:38 +08:00
|
|
|
<CSSTransitionGroup
|
2016-06-28 21:10:20 +08:00
|
|
|
transitionName={listTransition}
|
2017-08-05 04:05:18 +08:00
|
|
|
transitionAppear
|
|
|
|
transitionEnter
|
2016-06-28 21:10:20 +08:00
|
|
|
transitionLeave={false}
|
|
|
|
transitionAppearTimeout={0}
|
|
|
|
transitionEnterTimeout={0}
|
|
|
|
transitionLeaveTimeout={0}
|
2017-05-13 01:45:41 +08:00
|
|
|
component="div"
|
2017-06-03 03:25:02 +08:00
|
|
|
className={cx(styles.chatsList, styles.scrollableList)}
|
|
|
|
>
|
2017-06-07 05:55:46 +08:00
|
|
|
<div ref={(ref) => { this._msgItems = ref; }}>
|
2016-06-29 03:52:03 +08:00
|
|
|
{openChats.map(chat => (
|
2016-06-28 21:10:20 +08:00
|
|
|
<ChatListItem
|
2016-08-25 02:56:06 +08:00
|
|
|
compact={this.state.compact}
|
2016-06-28 21:10:20 +08:00
|
|
|
key={chat.id}
|
2016-06-30 22:45:19 +08:00
|
|
|
openChat={openChat}
|
2017-05-05 04:39:53 +08:00
|
|
|
chat={chat}
|
2017-06-03 03:25:02 +08:00
|
|
|
tabIndex={-1}
|
|
|
|
/>
|
2016-06-28 21:10:20 +08:00
|
|
|
))}
|
2017-05-11 22:11:17 +08:00
|
|
|
</div>
|
2017-06-05 07:20:38 +08:00
|
|
|
</CSSTransitionGroup>
|
2016-06-28 21:10:20 +08:00
|
|
|
</div>
|
2016-05-26 03:29:22 +08:00
|
|
|
</div>
|
2016-06-02 21:00:57 +08:00
|
|
|
);
|
2016-05-26 03:29:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
renderParticipants() {
|
2016-06-29 03:52:03 +08:00
|
|
|
const {
|
|
|
|
users,
|
|
|
|
currentUser,
|
2017-03-16 01:43:03 +08:00
|
|
|
isBreakoutRoom,
|
2017-04-04 02:05:47 +08:00
|
|
|
intl,
|
2017-05-04 00:56:27 +08:00
|
|
|
makeCall,
|
2017-05-16 03:26:03 +08:00
|
|
|
meeting,
|
2017-08-16 22:56:31 +08:00
|
|
|
getAvailableActions,
|
|
|
|
normalizeEmojiName,
|
2016-06-29 03:52:03 +08:00
|
|
|
} = this.props;
|
2016-06-28 21:10:20 +08:00
|
|
|
|
2017-08-22 04:04:38 +08:00
|
|
|
const userActions = (val) => {
|
2017-08-19 02:23:05 +08:00
|
|
|
return {
|
|
|
|
openChat: {
|
|
|
|
label: intl.formatMessage(intlMessages.ChatLabel),
|
|
|
|
handler: (router, user) => router.push(`/users/chat/${user.id}`),
|
|
|
|
icon: 'chat',
|
|
|
|
},
|
|
|
|
clearStatus: {
|
|
|
|
label: intl.formatMessage(intlMessages.ClearStatusLabel),
|
|
|
|
handler: user => makeCall('setEmojiStatus', user.id, 'none'),
|
|
|
|
icon: 'clear_status',
|
|
|
|
},
|
|
|
|
setPresenter: {
|
|
|
|
label: intl.formatMessage(intlMessages.MakePresenterLabel),
|
|
|
|
handler: user => makeCall('assignPresenter', user.id),
|
|
|
|
icon: 'presentation',
|
|
|
|
},
|
|
|
|
kick: {
|
2017-08-22 04:04:38 +08:00
|
|
|
label: intl.formatMessage(intlMessages.KickUserLabel, { 0: val.name }),
|
2017-08-19 02:23:05 +08:00
|
|
|
handler: user => makeCall('kickUser', user.id),
|
|
|
|
icon: 'circle_close',
|
|
|
|
},
|
|
|
|
mute: {
|
|
|
|
label: intl.formatMessage(intlMessages.MuteUserAudioLabel),
|
|
|
|
handler: user => makeCall('toggleVoice', user.id),
|
|
|
|
icon: 'audio_off',
|
|
|
|
},
|
|
|
|
unmute: {
|
|
|
|
label: intl.formatMessage(intlMessages.UnmuteUserAudioLabel),
|
|
|
|
handler: user => makeCall('toggleVoice', user.id),
|
|
|
|
icon: 'audio_on',
|
|
|
|
},
|
|
|
|
promote: {
|
2017-08-22 04:04:38 +08:00
|
|
|
label: intl.formatMessage(intlMessages.PromoteUserLabel, { 0: val.name }),
|
2017-08-19 02:23:05 +08:00
|
|
|
handler: user => makeCall('changeRole', user.id, 'MODERATOR'),
|
|
|
|
icon: 'promote',
|
|
|
|
},
|
|
|
|
demote: {
|
2017-08-22 04:04:38 +08:00
|
|
|
label: intl.formatMessage(intlMessages.DemoteUserLabel, { 0: val.name }),
|
2017-08-19 02:23:05 +08:00
|
|
|
handler: user => makeCall('changeRole', user.id, 'VIEWER'),
|
|
|
|
icon: 'user',
|
|
|
|
},
|
|
|
|
};
|
2017-04-29 02:28:55 +08:00
|
|
|
};
|
|
|
|
|
2016-05-26 03:29:22 +08:00
|
|
|
return (
|
|
|
|
<div className={styles.participants}>
|
2016-09-15 01:48:50 +08:00
|
|
|
{
|
|
|
|
!this.state.compact ?
|
2017-06-03 03:25:02 +08:00
|
|
|
<div className={styles.smallTitle} role="banner">
|
|
|
|
{intl.formatMessage(intlMessages.usersTitle)}
|
2017-08-01 21:41:24 +08:00
|
|
|
({users.length})
|
2017-06-03 03:25:02 +08:00
|
|
|
</div> : <hr className={styles.separator} />
|
2016-08-25 02:56:06 +08:00
|
|
|
}
|
2017-05-11 22:11:17 +08:00
|
|
|
<div
|
|
|
|
className={styles.scrollableList}
|
|
|
|
tabIndex={0}
|
2017-06-07 05:55:46 +08:00
|
|
|
ref={(ref) => { this._usersList = ref; }}
|
2017-06-03 03:25:02 +08:00
|
|
|
>
|
2017-06-05 07:20:38 +08:00
|
|
|
<CSSTransitionGroup
|
2017-05-11 22:11:17 +08:00
|
|
|
transitionName={listTransition}
|
2017-08-05 04:05:18 +08:00
|
|
|
transitionAppear
|
|
|
|
transitionEnter
|
|
|
|
transitionLeave
|
2017-05-11 22:11:17 +08:00
|
|
|
transitionAppearTimeout={0}
|
|
|
|
transitionEnterTimeout={0}
|
|
|
|
transitionLeaveTimeout={0}
|
2017-05-13 01:45:41 +08:00
|
|
|
component="div"
|
2017-06-03 03:25:02 +08:00
|
|
|
className={cx(styles.participantsList, styles.scrollableList)}
|
|
|
|
>
|
2017-06-07 05:55:46 +08:00
|
|
|
<div ref={(ref) => { this._userItems = ref; }}>
|
2017-05-11 22:11:17 +08:00
|
|
|
{
|
|
|
|
users.map(user => (
|
2017-06-03 03:25:02 +08:00
|
|
|
<UserListItem
|
|
|
|
compact={this.state.compact}
|
|
|
|
key={user.id}
|
|
|
|
isBreakoutRoom={isBreakoutRoom}
|
|
|
|
user={user}
|
|
|
|
currentUser={currentUser}
|
2017-08-19 02:23:05 +08:00
|
|
|
userActions={userActions(user)}
|
2017-06-03 03:25:02 +08:00
|
|
|
meeting={meeting}
|
2017-08-16 22:56:31 +08:00
|
|
|
getAvailableActions={getAvailableActions}
|
|
|
|
normalizeEmojiName={normalizeEmojiName}
|
2017-06-06 10:51:20 +08:00
|
|
|
/>
|
|
|
|
))
|
2017-05-11 22:11:17 +08:00
|
|
|
}
|
|
|
|
</div>
|
2017-06-05 07:20:38 +08:00
|
|
|
</CSSTransitionGroup>
|
2017-05-05 04:39:53 +08:00
|
|
|
</div>
|
2016-05-26 03:29:22 +08:00
|
|
|
</div>
|
2016-06-02 21:00:57 +08:00
|
|
|
);
|
2016-05-26 03:29:22 +08:00
|
|
|
}
|
2017-08-16 22:56:31 +08:00
|
|
|
|
2017-07-28 21:43:39 +08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className={styles.userList}>
|
|
|
|
{this.renderHeader()}
|
|
|
|
{this.renderContent()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-05-20 02:22:56 +08:00
|
|
|
}
|
2016-06-02 21:00:57 +08:00
|
|
|
|
2016-06-29 03:52:03 +08:00
|
|
|
UserList.propTypes = propTypes;
|
2017-07-28 21:43:39 +08:00
|
|
|
UserList.defaultProps = defaultProps;
|
|
|
|
|
2017-04-04 02:05:47 +08:00
|
|
|
export default withRouter(injectIntl(UserList));
|