2020-03-27 13:59:38 -07:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import PropTypes from 'prop-types' ;
2020-08-15 21:37:50 -07:00
import StatusListContainer from '../ui/containers/status_list_container' ;
2020-03-27 13:59:38 -07:00
import Column from '../../components/column' ;
import ColumnHeader from '../../components/column_header' ;
2020-08-15 21:37:50 -07:00
import { expandDirectTimeline } from '../../actions/timelines' ;
2020-03-27 13:59:38 -07:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
import { connectDirectStream } from '../../actions/streaming' ;
const messages = defineMessages ( {
title : { id : 'column.direct' , defaultMessage : 'Direct messages' } ,
} ) ;
2020-08-15 21:37:50 -07:00
const mapStateToProps = state => ( {
hasUnread : state . getIn ( [ 'timelines' , 'direct' , 'unread' ] ) > 0 ,
} ) ;
export default @ connect ( mapStateToProps )
2020-03-27 13:59:38 -07:00
@ injectIntl
class DirectTimeline extends React . PureComponent {
static propTypes = {
dispatch : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
hasUnread : PropTypes . bool ,
} ;
2020-04-14 14:47:35 -07:00
componentDidMount ( ) {
2020-03-27 13:59:38 -07:00
const { dispatch } = this . props ;
2020-08-15 21:37:50 -07:00
dispatch ( expandDirectTimeline ( ) ) ;
2020-03-27 13:59:38 -07:00
this . disconnect = dispatch ( connectDirectStream ( ) ) ;
}
2020-04-14 14:47:35 -07:00
componentWillUnmount ( ) {
2020-03-27 13:59:38 -07:00
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
handleLoadMore = maxId => {
2020-08-15 21:37:50 -07:00
this . props . dispatch ( expandDirectTimeline ( { maxId } ) ) ;
2020-03-27 13:59:38 -07:00
}
2020-04-14 14:47:35 -07:00
render ( ) {
2020-03-27 13:59:38 -07:00
const { intl , hasUnread } = this . props ;
return (
< Column label = { intl . formatMessage ( messages . title ) } >
2020-08-15 21:37:50 -07:00
< ColumnHeader
icon = 'envelope'
active = { hasUnread }
title = { intl . formatMessage ( messages . title ) }
onPin = { this . handlePin }
/ >
2020-03-27 13:59:38 -07:00
2020-08-15 21:37:50 -07:00
< StatusListContainer
2020-03-27 13:59:38 -07:00
scrollKey = 'direct_timeline'
timelineId = 'direct'
onLoadMore = { this . handleLoadMore }
emptyMessage = { < FormattedMessage id = 'empty_column.direct' defaultMessage = "You don't have any direct messages yet. When you send or receive one, it will show up here." / > }
/ >
< / C o l u m n >
) ;
}
}