2015-10-08 12:27:09 -04:00
|
|
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
2015-06-14 23:53:32 -08:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
import {Modal} from 'react-bootstrap';
|
2016-02-25 11:25:16 -05:00
|
|
|
import FilteredUserList from './filtered_user_list.jsx';
|
2016-03-14 08:50:46 -04:00
|
|
|
import UserStore from 'stores/user_store.jsx';
|
2016-05-04 06:31:42 -07:00
|
|
|
import TeamStore from 'stores/team_store.jsx';
|
2016-03-14 08:50:46 -04:00
|
|
|
import * as Utils from 'utils/utils.jsx';
|
2016-05-26 09:46:18 -04:00
|
|
|
import * as GlobalActions from 'actions/global_actions.jsx';
|
2015-06-14 23:53:32 -08:00
|
|
|
|
2016-03-14 08:50:46 -04:00
|
|
|
import {FormattedMessage} from 'react-intl';
|
2016-04-04 11:09:59 -04:00
|
|
|
import {browserHistory} from 'react-router';
|
2016-03-22 10:03:17 -04:00
|
|
|
import SpinnerButton from 'components/spinner_button.jsx';
|
2016-05-04 06:31:42 -07:00
|
|
|
import LoadingScreen from 'components/loading_screen.jsx';
|
2016-03-14 08:50:46 -04:00
|
|
|
|
|
|
|
|
import React from 'react';
|
2016-01-31 22:03:30 -03:00
|
|
|
|
2016-02-25 11:25:16 -05:00
|
|
|
export default class MoreDirectChannels extends React.Component {
|
2015-09-01 17:06:31 -07:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
this.handleHide = this.handleHide.bind(this);
|
2016-05-04 06:31:42 -07:00
|
|
|
this.handleOnEnter = this.handleOnEnter.bind(this);
|
2015-10-14 16:57:03 -04:00
|
|
|
this.handleShowDirectChannel = this.handleShowDirectChannel.bind(this);
|
|
|
|
|
this.handleUserChange = this.handleUserChange.bind(this);
|
2016-05-04 06:31:42 -07:00
|
|
|
this.onTeamChange = this.onTeamChange.bind(this);
|
2016-02-25 11:25:16 -05:00
|
|
|
this.createJoinDirectChannelButton = this.createJoinDirectChannelButton.bind(this);
|
2015-10-14 16:57:03 -04:00
|
|
|
|
|
|
|
|
this.state = {
|
2016-05-04 06:31:42 -07:00
|
|
|
users: null,
|
|
|
|
|
teamMembers: null,
|
2015-10-14 16:57:03 -04:00
|
|
|
loadingDMChannel: -1
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 17:06:31 -07:00
|
|
|
componentDidMount() {
|
2016-05-04 06:31:42 -07:00
|
|
|
UserStore.addDmListChangeListener(this.handleUserChange);
|
|
|
|
|
TeamStore.addChangeListener(this.onTeamChange);
|
2015-09-01 17:06:31 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
componentWillUnmount() {
|
2016-05-04 06:31:42 -07:00
|
|
|
UserStore.removeDmListChangeListener(this.handleUserChange);
|
|
|
|
|
TeamStore.removeChangeListener(this.onTeamChange);
|
2015-10-02 14:25:55 -04:00
|
|
|
}
|
|
|
|
|
|
2016-04-29 08:40:06 -04:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
|
if (nextProps.show !== this.props.show) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nextProps.onModalDismissed.toString() !== this.props.onModalDismissed.toString()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nextState.loadingDMChannel !== this.state.loadingDMChannel) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Utils.areObjectsEqual(nextState.users, this.state.users)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-05 15:32:56 -04:00
|
|
|
if (!Utils.areObjectsEqual(nextState.teamMembers, this.state.teamMembers)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-29 08:40:06 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
handleHide() {
|
|
|
|
|
if (this.props.onModalDismissed) {
|
|
|
|
|
this.props.onModalDismissed();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 06:31:42 -07:00
|
|
|
handleOnEnter() {
|
|
|
|
|
this.setState({
|
|
|
|
|
users: null,
|
|
|
|
|
teamMembers: null
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleOnEntered() {
|
|
|
|
|
GlobalActions.emitProfilesForDmList();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
handleShowDirectChannel(teammate, e) {
|
2015-10-26 23:29:55 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
if (this.state.loadingDMChannel !== -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 23:29:55 +01:00
|
|
|
this.setState({loadingDMChannel: teammate.id});
|
|
|
|
|
Utils.openDirectChannelToUser(
|
|
|
|
|
teammate,
|
|
|
|
|
(channel) => {
|
2016-04-04 11:09:59 -04:00
|
|
|
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
|
2015-10-26 23:29:55 +01:00
|
|
|
this.setState({loadingDMChannel: -1});
|
|
|
|
|
this.handleHide();
|
|
|
|
|
},
|
|
|
|
|
() => {
|
|
|
|
|
this.setState({loadingDMChannel: -1});
|
|
|
|
|
}
|
|
|
|
|
);
|
2015-10-14 16:57:03 -04:00
|
|
|
}
|
2015-10-07 13:07:59 -04:00
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
handleUserChange() {
|
2016-05-04 06:31:42 -07:00
|
|
|
this.setState({
|
|
|
|
|
users: UserStore.getProfilesForDmList()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onTeamChange() {
|
|
|
|
|
this.setState({
|
|
|
|
|
teamMembers: TeamStore.getMembersForTeam()
|
|
|
|
|
});
|
2015-10-14 16:57:03 -04:00
|
|
|
}
|
|
|
|
|
|
2016-02-25 11:25:16 -05:00
|
|
|
createJoinDirectChannelButton({user}) {
|
2015-06-14 23:53:32 -08:00
|
|
|
return (
|
2016-03-22 10:03:17 -04:00
|
|
|
<SpinnerButton
|
2016-03-28 09:41:03 -04:00
|
|
|
className='btn btm-sm btn-primary'
|
2016-03-22 10:03:17 -04:00
|
|
|
spinning={this.state.loadingDMChannel === user.id}
|
2016-02-25 11:25:16 -05:00
|
|
|
onClick={this.handleShowDirectChannel.bind(this, user)}
|
|
|
|
|
>
|
|
|
|
|
<FormattedMessage
|
|
|
|
|
id='more_direct_channels.message'
|
|
|
|
|
defaultMessage='Message'
|
|
|
|
|
/>
|
2016-03-22 10:03:17 -04:00
|
|
|
</SpinnerButton>
|
2015-10-14 16:57:03 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2016-03-02 16:10:14 -05:00
|
|
|
let maxHeight = 1000;
|
|
|
|
|
if (Utils.windowHeight() <= 1200) {
|
|
|
|
|
maxHeight = Utils.windowHeight() - 300;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 06:31:42 -07:00
|
|
|
var body = null;
|
|
|
|
|
if (this.state.users == null || this.state.teamMembers == null) {
|
|
|
|
|
body = (<LoadingScreen/>);
|
|
|
|
|
} else {
|
|
|
|
|
var showTeamToggle = false;
|
|
|
|
|
if (global.window.mm_config.RestrictDirectMessage === 'any') {
|
|
|
|
|
showTeamToggle = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body = (
|
|
|
|
|
<FilteredUserList
|
|
|
|
|
style={{maxHeight}}
|
|
|
|
|
users={this.state.users}
|
|
|
|
|
teamMembers={this.state.teamMembers}
|
|
|
|
|
actions={[this.createJoinDirectChannelButton]}
|
|
|
|
|
showTeamToggle={showTeamToggle}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 16:57:03 -04:00
|
|
|
return (
|
|
|
|
|
<Modal
|
2016-02-25 11:25:16 -05:00
|
|
|
dialogClassName='more-modal more-direct-channels'
|
2015-10-14 16:57:03 -04:00
|
|
|
show={this.props.show}
|
|
|
|
|
onHide={this.handleHide}
|
2016-05-04 06:31:42 -07:00
|
|
|
onEnter={this.handleOnEnter}
|
|
|
|
|
onEntered={this.handleOnEntered}
|
2015-10-14 16:57:03 -04:00
|
|
|
>
|
|
|
|
|
<Modal.Header closeButton={true}>
|
2016-01-31 22:03:30 -03:00
|
|
|
<Modal.Title>
|
|
|
|
|
<FormattedMessage
|
|
|
|
|
id='more_direct_channels.title'
|
|
|
|
|
defaultMessage='Direct Messages'
|
|
|
|
|
/>
|
|
|
|
|
</Modal.Title>
|
2015-10-14 16:57:03 -04:00
|
|
|
</Modal.Header>
|
2016-02-25 11:25:16 -05:00
|
|
|
<Modal.Body>
|
2016-05-04 06:31:42 -07:00
|
|
|
{body}
|
2015-10-14 16:57:03 -04:00
|
|
|
</Modal.Body>
|
|
|
|
|
<Modal.Footer>
|
|
|
|
|
<button
|
|
|
|
|
type='button'
|
|
|
|
|
className='btn btn-default'
|
|
|
|
|
onClick={this.handleHide}
|
|
|
|
|
>
|
2016-01-31 22:03:30 -03:00
|
|
|
<FormattedMessage
|
|
|
|
|
id='more_direct_channels.close'
|
|
|
|
|
defaultMessage='Close'
|
|
|
|
|
/>
|
2015-10-14 16:57:03 -04:00
|
|
|
</button>
|
|
|
|
|
</Modal.Footer>
|
|
|
|
|
</Modal>
|
2015-06-14 23:53:32 -08:00
|
|
|
);
|
|
|
|
|
}
|
2015-09-01 17:06:31 -07:00
|
|
|
}
|
2015-10-14 16:57:03 -04:00
|
|
|
|
|
|
|
|
MoreDirectChannels.propTypes = {
|
|
|
|
|
show: React.PropTypes.bool.isRequired,
|
|
|
|
|
onModalDismissed: React.PropTypes.func
|
|
|
|
|
};
|