2018-04-18 21:09:06 +10:00
import PropTypes from 'prop-types' ;
2022-10-09 12:55:09 +11:00
import React from 'react' ;
import { Helmet } from 'react-helmet' ;
2018-10-08 23:43:38 +11:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2022-10-09 12:55:09 +11:00
import { connect } from 'react-redux' ;
import { addColumn , removeColumn , moveColumn } from 'mastodon/actions/columns' ;
import { mountConversations , unmountConversations , expandConversations } from 'mastodon/actions/conversations' ;
import { connectDirectStream } from 'mastodon/actions/streaming' ;
import Column from 'mastodon/components/column' ;
import ColumnHeader from 'mastodon/components/column_header' ;
2018-10-08 08:44:58 +11:00
import ConversationsListContainer from './containers/conversations_list_container' ;
2018-04-18 21:09:06 +10:00
const messages = defineMessages ( {
2022-05-03 17:09:09 +10:00
title : { id : 'column.direct' , defaultMessage : 'Direct messages' } ,
2018-04-18 21:09:06 +10:00
} ) ;
2018-10-08 08:44:58 +11:00
export default @ connect ( )
2018-04-18 21:09:06 +10:00
@ injectIntl
2018-09-15 01:59:48 +10:00
class DirectTimeline extends React . PureComponent {
2018-04-18 21:09:06 +10: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-11 10:31:03 +11:00
dispatch ( mountConversations ( ) ) ;
2018-10-08 08:44:58 +11:00
dispatch ( expandConversations ( ) ) ;
2018-04-18 21:09:06 +10:00
this . disconnect = dispatch ( connectDirectStream ( ) ) ;
}
componentWillUnmount ( ) {
2018-10-11 10:31:03 +11:00
this . props . dispatch ( unmountConversations ( ) ) ;
2018-04-18 21:09:06 +10:00
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
setRef = c => {
this . column = c ;
}
handleLoadMore = maxId => {
2018-10-08 08:44:58 +11:00
this . props . dispatch ( expandConversations ( { maxId } ) ) ;
2018-04-18 21:09:06 +10:00
}
render ( ) {
2021-07-13 23:45:17 +10:00
const { intl , hasUnread , columnId , multiColumn } = this . props ;
2018-04-18 21:09:06 +10:00
const pinned = ! ! columnId ;
return (
2019-08-02 03:17:17 +10:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } label = { intl . formatMessage ( messages . title ) } >
2018-04-18 21:09:06 +10:00
< ColumnHeader
2022-04-29 08:24:31 +10:00
icon = 'at'
2018-04-18 21:09:06 +10:00
active = { hasUnread }
title = { intl . formatMessage ( messages . title ) }
onPin = { this . handlePin }
onMove = { this . handleMove }
onClick = { this . handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
2018-06-29 23:34:36 +10:00
/ >
2018-04-18 21:09:06 +10:00
2018-10-08 23:43:38 +11:00
< ConversationsListContainer
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
timelineId = 'direct'
onLoadMore = { this . handleLoadMore }
2022-05-03 17:09:09 +10:00
prepend = { < div className = 'follow_requests-unlocked_explanation' > < span > < FormattedMessage id = 'compose_form.encryption_warning' defaultMessage = 'Posts on Mastodon are not end-to-end encrypted. Do not share any dangerous information over Mastodon.' / > < a href = '/terms' target = '_blank' > < FormattedMessage id = 'compose_form.direct_message_warning_learn_more' defaultMessage = 'Learn more' / > < / a > < / s p a n > < / d i v > }
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." / > }
2018-10-08 23:43:38 +11:00
/ >
2022-10-09 12:55:09 +11:00
< Helmet >
< title > { intl . formatMessage ( messages . title ) } < / t i t l e >
2022-10-20 23:35:29 +11:00
< meta name = 'robots' content = 'noindex' / >
2022-10-09 12:55:09 +11:00
< / H e l m e t >
2018-04-18 21:09:06 +10:00
< / C o l u m n >
) ;
}
}