2018-04-18 11:09:06 +00: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-10 23:31:03 +00:00
import { mountConversations , unmountConversations , expandConversations } from '../../actions/conversations' ;
2018-04-18 11:09:06 +00:00
import { addColumn , removeColumn , moveColumn } from '../../actions/columns' ;
2018-10-08 12:43:38 +00:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2018-04-18 11:09:06 +00:00
import { connectDirectStream } from '../../actions/streaming' ;
2018-10-07 21:44:58 +00:00
import ConversationsListContainer from './containers/conversations_list_container' ;
2018-04-18 11:09:06 +00:00
const messages = defineMessages ( {
2022-04-28 22:24:31 +00:00
title : { id : 'column.conversations' , defaultMessage : 'Conversations' } ,
2018-04-18 11:09:06 +00:00
} ) ;
2018-10-07 21:44:58 +00:00
export default @ connect ( )
2018-04-18 11:09:06 +00:00
@ injectIntl
2018-09-14 15:59:48 +00:00
class DirectTimeline extends React . PureComponent {
2018-04-18 11:09:06 +00:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
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-10 23:31:03 +00:00
dispatch ( mountConversations ( ) ) ;
2018-10-07 21:44:58 +00:00
dispatch ( expandConversations ( ) ) ;
2018-04-18 11:09:06 +00:00
this . disconnect = dispatch ( connectDirectStream ( ) ) ;
}
componentWillUnmount ( ) {
2018-10-10 23:31:03 +00:00
this . props . dispatch ( unmountConversations ( ) ) ;
2018-04-18 11:09:06 +00:00
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
setRef = c => {
this . column = c ;
}
handleLoadMore = maxId => {
2018-10-07 21:44:58 +00:00
this . props . dispatch ( expandConversations ( { maxId } ) ) ;
2018-04-18 11:09:06 +00:00
}
render ( ) {
2021-07-13 13:45:17 +00:00
const { intl , hasUnread , columnId , multiColumn } = this . props ;
2018-04-18 11:09:06 +00:00
const pinned = ! ! columnId ;
return (
2019-08-01 17:17:17 +00:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } label = { intl . formatMessage ( messages . title ) } >
2018-04-18 11:09:06 +00:00
< ColumnHeader
2022-04-28 22:24:31 +00:00
icon = 'at'
2018-04-18 11:09:06 +00:00
active = { hasUnread }
title = { intl . formatMessage ( messages . title ) }
onPin = { this . handlePin }
onMove = { this . handleMove }
onClick = { this . handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
2018-06-29 13:34:36 +00:00
/ >
2018-04-18 11:09:06 +00:00
2018-10-08 12:43:38 +00:00
< ConversationsListContainer
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
timelineId = 'direct'
onLoadMore = { this . handleLoadMore }
2022-04-28 22:24:31 +00:00
emptyMessage = { < FormattedMessage id = 'empty_column.conversations' defaultMessage = "Once you send or receive a post that's only visible to people mentioned in it, it will show up here." / > }
2018-10-08 12:43:38 +00:00
/ >
2018-04-18 11:09:06 +00:00
< / C o l u m n >
) ;
}
}