2018-04-18 12:09:06 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Column from '../../components/column';
|
|
|
|
import ColumnHeader from '../../components/column_header';
|
2018-10-07 22:44:58 +01:00
|
|
|
import { expandConversations } from '../../actions/conversations';
|
2018-04-18 12:09:06 +01:00
|
|
|
import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
|
2018-10-07 22:44:58 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2018-04-18 12:09:06 +01:00
|
|
|
import { connectDirectStream } from '../../actions/streaming';
|
2018-10-07 22:44:58 +01:00
|
|
|
import ConversationsListContainer from './containers/conversations_list_container';
|
2018-04-18 12:09:06 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
title: { id: 'column.direct', defaultMessage: 'Direct messages' },
|
|
|
|
});
|
|
|
|
|
2018-10-07 22:44:58 +01:00
|
|
|
export default @connect()
|
2018-04-18 12:09:06 +01:00
|
|
|
@injectIntl
|
2018-09-14 16:59:48 +01:00
|
|
|
class DirectTimeline extends React.PureComponent {
|
2018-04-18 12:09:06 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2018-07-29 15:52:06 +01:00
|
|
|
shouldUpdateScroll: PropTypes.func,
|
2018-04-18 12:09:06 +01:00
|
|
|
columnId: PropTypes.string,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
hasUnread: PropTypes.bool,
|
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
handlePin = () => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (columnId) {
|
|
|
|
dispatch(removeColumn(columnId));
|
|
|
|
} else {
|
|
|
|
dispatch(addColumn('DIRECT', {}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMove = (dir) => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
dispatch(moveColumn(columnId, dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
2018-10-07 22:44:58 +01:00
|
|
|
dispatch(expandConversations());
|
2018-04-18 12:09:06 +01:00
|
|
|
this.disconnect = dispatch(connectDirectStream());
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
if (this.disconnect) {
|
|
|
|
this.disconnect();
|
|
|
|
this.disconnect = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.column = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = maxId => {
|
2018-10-07 22:44:58 +01:00
|
|
|
this.props.dispatch(expandConversations({ maxId }));
|
2018-04-18 12:09:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-10-07 22:44:58 +01:00
|
|
|
const { intl, hasUnread, columnId, multiColumn, shouldUpdateScroll } = this.props;
|
2018-04-18 12:09:06 +01:00
|
|
|
const pinned = !!columnId;
|
|
|
|
|
|
|
|
return (
|
2018-08-23 16:26:21 +01:00
|
|
|
<Column ref={this.setRef} label={intl.formatMessage(messages.title)}>
|
2018-04-18 12:09:06 +01:00
|
|
|
<ColumnHeader
|
|
|
|
icon='envelope'
|
|
|
|
active={hasUnread}
|
|
|
|
title={intl.formatMessage(messages.title)}
|
|
|
|
onPin={this.handlePin}
|
|
|
|
onMove={this.handleMove}
|
|
|
|
onClick={this.handleHeaderClick}
|
|
|
|
pinned={pinned}
|
|
|
|
multiColumn={multiColumn}
|
2018-06-29 14:34:36 +01:00
|
|
|
/>
|
2018-04-18 12:09:06 +01:00
|
|
|
|
2018-10-07 22:44:58 +01:00
|
|
|
<ConversationsListContainer shouldUpdateScroll={shouldUpdateScroll} />
|
2018-04-18 12:09:06 +01:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|