2018-04-18 14:09:06 +03:00
import PropTypes from 'prop-types' ;
2023-05-23 11:52:27 +03:00
import { PureComponent } from 'react' ;
2023-05-23 18:15:17 +03:00
2018-10-08 15:43:38 +03:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2023-05-23 18:15:17 +03:00
import { Helmet } from 'react-helmet' ;
2022-10-09 04:55:09 +03:00
import { connect } from 'react-redux' ;
2023-05-23 18:15:17 +03:00
2023-10-24 20:45:08 +03:00
import { ReactComponent as AlternateEmailIcon } from '@material-symbols/svg-600/outlined/alternate_email.svg' ;
2022-10-09 04:55:09 +03:00
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' ;
2023-05-23 18:15:17 +03:00
2018-10-08 00:44:58 +03:00
import ConversationsListContainer from './containers/conversations_list_container' ;
2018-04-18 14:09:06 +03:00
const messages = defineMessages ( {
2023-03-30 16:16:20 +03:00
title : { id : 'column.direct' , defaultMessage : 'Private mentions' } ,
2018-04-18 14:09:06 +03:00
} ) ;
2023-05-23 11:52:27 +03:00
class DirectTimeline extends PureComponent {
2018-04-18 14:09:06 +03: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' , { } ) ) ;
}
2023-01-30 02:45:35 +02:00
} ;
2018-04-18 14:09:06 +03:00
handleMove = ( dir ) => {
const { columnId , dispatch } = this . props ;
dispatch ( moveColumn ( columnId , dir ) ) ;
2023-01-30 02:45:35 +02:00
} ;
2018-04-18 14:09:06 +03:00
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
2023-01-30 02:45:35 +02:00
} ;
2018-04-18 14:09:06 +03:00
componentDidMount ( ) {
const { dispatch } = this . props ;
2018-10-11 02:31:03 +03:00
dispatch ( mountConversations ( ) ) ;
2018-10-08 00:44:58 +03:00
dispatch ( expandConversations ( ) ) ;
2018-04-18 14:09:06 +03:00
this . disconnect = dispatch ( connectDirectStream ( ) ) ;
}
componentWillUnmount ( ) {
2018-10-11 02:31:03 +03:00
this . props . dispatch ( unmountConversations ( ) ) ;
2018-04-18 14:09:06 +03:00
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
setRef = c => {
this . column = c ;
2023-01-30 02:45:35 +02:00
} ;
2018-04-18 14:09:06 +03:00
handleLoadMore = maxId => {
2018-10-08 00:44:58 +03:00
this . props . dispatch ( expandConversations ( { maxId } ) ) ;
2023-01-30 02:45:35 +02:00
} ;
2018-04-18 14:09:06 +03:00
render ( ) {
2021-07-13 16:45:17 +03:00
const { intl , hasUnread , columnId , multiColumn } = this . props ;
2018-04-18 14:09:06 +03:00
const pinned = ! ! columnId ;
return (
2019-08-01 20:17:17 +03:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } label = { intl . formatMessage ( messages . title ) } >
2018-04-18 14:09:06 +03:00
< ColumnHeader
2022-04-29 01:24:31 +03:00
icon = 'at'
2023-10-24 20:45:08 +03:00
iconComponent = { AlternateEmailIcon }
2018-04-18 14:09:06 +03:00
active = { hasUnread }
title = { intl . formatMessage ( messages . title ) }
onPin = { this . handlePin }
onMove = { this . handleMove }
onClick = { this . handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
2018-06-29 16:34:36 +03:00
/ >
2018-04-18 14:09:06 +03:00
2018-10-08 15:43:38 +03:00
< ConversationsListContainer
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
timelineId = 'direct'
2023-04-07 16:44:31 +03:00
bindToDocument = { ! multiColumn }
2018-10-08 15:43:38 +03:00
onLoadMore = { this . handleLoadMore }
2022-05-03 10:09:09 +03: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 > < / span > < / div > }
2023-04-07 16:44:31 +03:00
alwaysPrepend
2023-03-30 16:16:20 +03:00
emptyMessage = { < FormattedMessage id = 'empty_column.direct' defaultMessage = "You don't have any private mentions yet. When you send or receive one, it will show up here." / > }
2018-10-08 15:43:38 +03:00
/ >
2022-10-09 04:55:09 +03:00
< Helmet >
< title > { intl . formatMessage ( messages . title ) } < / title >
2022-10-20 15:35:29 +03:00
< meta name = 'robots' content = 'noindex' / >
2022-10-09 04:55:09 +03:00
< / Helmet >
2018-04-18 14:09:06 +03:00
< / Column >
) ;
}
}
2023-03-24 04:17:53 +02:00
export default connect ( ) ( injectIntl ( DirectTimeline ) ) ;