2020-08-15 21:18:53 -07:00
import PropTypes from 'prop-types' ;
2022-01-10 14:17:52 -08:00
import React from 'react' ;
2022-04-30 09:45:58 -07:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2022-01-10 14:17:52 -08:00
import { connect } from 'react-redux' ;
2022-01-10 14:25:06 -08:00
2022-01-10 14:01:24 -08:00
import { directComposeById } from 'soapbox/actions/compose' ;
2022-04-30 09:45:58 -07:00
import AccountSearch from 'soapbox/components/account_search' ;
2022-01-10 14:25:06 -08:00
2020-08-15 21:18:53 -07:00
import { mountConversations , unmountConversations , expandConversations } from '../../actions/conversations' ;
import { connectDirectStream } from '../../actions/streaming' ;
2022-04-30 09:45:58 -07:00
import { Column } from '../../components/ui' ;
import ConversationsListContainer from './containers/conversations_list_container' ;
2020-08-15 21:18:53 -07:00
const messages = defineMessages ( {
title : { id : 'column.direct' , defaultMessage : 'Direct messages' } ,
2021-10-14 10:25:51 -07:00
searchPlaceholder : { id : 'direct.search_placeholder' , defaultMessage : 'Send a message to…' } ,
2020-08-15 21:18:53 -07:00
} ) ;
export default @ connect ( )
@ injectIntl
class ConversationsTimeline extends React . PureComponent {
static propTypes = {
dispatch : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
hasUnread : PropTypes . bool ,
} ;
componentDidMount ( ) {
const { dispatch } = this . props ;
dispatch ( mountConversations ( ) ) ;
dispatch ( expandConversations ( ) ) ;
this . disconnect = dispatch ( connectDirectStream ( ) ) ;
}
componentWillUnmount ( ) {
this . props . dispatch ( unmountConversations ( ) ) ;
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
2021-10-14 09:52:12 -07:00
handleSuggestion = accountId => {
this . props . dispatch ( directComposeById ( accountId ) ) ;
}
2020-08-15 21:18:53 -07:00
handleLoadMore = maxId => {
this . props . dispatch ( expandConversations ( { maxId } ) ) ;
}
render ( ) {
2022-03-21 11:09:01 -07:00
const { intl } = this . props ;
2020-08-15 21:18:53 -07:00
return (
2022-04-30 09:45:58 -07:00
< Column label = { intl . formatMessage ( messages . title ) } >
< AccountSearch
placeholder = { intl . formatMessage ( messages . searchPlaceholder ) }
onSelected = { this . handleSuggestion }
/ >
< ConversationsListContainer
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." / > }
/ >
2020-08-15 21:18:53 -07:00
< / C o l u m n >
) ;
}
}