2022-10-08 21:55:09 -04:00
import PropTypes from 'prop-types' ;
2023-05-28 08:18:23 -04:00
import { PureComponent } from 'react' ;
2023-05-28 10:38:10 -04:00
2022-10-08 21:55:09 -04:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2023-05-28 10:38:10 -04:00
import { Helmet } from 'react-helmet' ;
2017-10-16 00:02:39 -04:00
import { connect } from 'react-redux' ;
2023-05-28 10:38:10 -04:00
2023-10-24 13:45:08 -04:00
2022-10-08 21:55:09 -04:00
import { addColumn , removeColumn , moveColumn } from 'flavours/glitch/actions/columns' ;
import { mountConversations , unmountConversations , expandConversations } from 'flavours/glitch/actions/conversations' ;
import { connectDirectStream } from 'flavours/glitch/actions/streaming' ;
import { expandDirectTimeline } from 'flavours/glitch/actions/timelines' ;
2017-12-04 02:26:40 -05:00
import Column from 'flavours/glitch/components/column' ;
import ColumnHeader from 'flavours/glitch/components/column_header' ;
2022-10-08 21:55:09 -04:00
import StatusListContainer from 'flavours/glitch/features/ui/containers/status_list_container' ;
2024-01-12 15:16:48 -05:00
import MailIcon from 'mastodon/../material-icons/400-24px/mail.svg?react' ;
2023-05-28 10:38:10 -04:00
2017-10-16 00:02:39 -04:00
import ColumnSettingsContainer from './containers/column_settings_container' ;
2019-06-09 06:07:23 -04:00
import ConversationsListContainer from './containers/conversations_list_container' ;
2017-10-16 00:02:39 -04:00
const messages = defineMessages ( {
2023-06-11 07:33:45 -04:00
title : { id : 'column.direct' , defaultMessage : 'Private mentions' } ,
2017-10-16 00:02:39 -04:00
} ) ;
const mapStateToProps = state => ( {
hasUnread : state . getIn ( [ 'timelines' , 'direct' , 'unread' ] ) > 0 ,
2019-06-09 06:07:23 -04:00
conversationsMode : state . getIn ( [ 'settings' , 'direct' , 'conversations' ] ) ,
2017-10-16 00:02:39 -04:00
} ) ;
2023-05-28 08:18:23 -04:00
class DirectTimeline extends PureComponent {
2017-10-16 00:02:39 -04:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
columnId : PropTypes . string ,
intl : PropTypes . object . isRequired ,
hasUnread : PropTypes . bool ,
multiColumn : PropTypes . bool ,
2019-06-09 06:07:23 -04:00
conversationsMode : PropTypes . bool ,
2017-10-16 00:02:39 -04:00
} ;
handlePin = ( ) => {
const { columnId , dispatch } = this . props ;
if ( columnId ) {
dispatch ( removeColumn ( columnId ) ) ;
} else {
dispatch ( addColumn ( 'DIRECT' , { } ) ) ;
}
2023-02-03 14:52:07 -05:00
} ;
2017-10-16 00:02:39 -04:00
handleMove = ( dir ) => {
const { columnId , dispatch } = this . props ;
dispatch ( moveColumn ( columnId , dir ) ) ;
2023-02-03 14:52:07 -05:00
} ;
2017-10-16 00:02:39 -04:00
handleHeaderClick = ( ) => {
this . column . scrollTop ( ) ;
2023-02-03 14:52:07 -05:00
} ;
2017-10-16 00:02:39 -04:00
componentDidMount ( ) {
2019-06-09 06:07:23 -04:00
const { dispatch , conversationsMode } = this . props ;
dispatch ( mountConversations ( ) ) ;
if ( conversationsMode ) {
dispatch ( expandConversations ( ) ) ;
} else {
dispatch ( expandDirectTimeline ( ) ) ;
}
2017-10-16 00:02:39 -04:00
this . disconnect = dispatch ( connectDirectStream ( ) ) ;
}
2019-06-09 06:07:23 -04:00
componentDidUpdate ( prevProps ) {
const { dispatch , conversationsMode } = this . props ;
if ( prevProps . conversationsMode && ! conversationsMode ) {
dispatch ( expandDirectTimeline ( ) ) ;
} else if ( ! prevProps . conversationsMode && conversationsMode ) {
dispatch ( expandConversations ( ) ) ;
}
}
2017-10-16 00:02:39 -04:00
componentWillUnmount ( ) {
2019-06-09 06:07:23 -04:00
this . props . dispatch ( unmountConversations ( ) ) ;
2017-10-16 00:02:39 -04:00
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
setRef = c => {
this . column = c ;
2023-02-03 14:52:07 -05:00
} ;
2017-10-16 00:02:39 -04:00
2019-06-09 06:07:23 -04:00
handleLoadMoreTimeline = maxId => {
2018-05-31 08:13:35 -04:00
this . props . dispatch ( expandDirectTimeline ( { maxId } ) ) ;
2023-02-03 14:52:07 -05:00
} ;
2017-10-16 00:02:39 -04:00
2019-06-09 06:07:23 -04:00
handleLoadMoreConversations = maxId => {
this . props . dispatch ( expandConversations ( { maxId } ) ) ;
2023-02-03 14:52:07 -05:00
} ;
2019-06-09 06:07:23 -04:00
2017-10-16 00:02:39 -04:00
render ( ) {
2019-06-09 06:07:23 -04:00
const { intl , hasUnread , columnId , multiColumn , conversationsMode } = this . props ;
2017-10-16 00:02:39 -04:00
const pinned = ! ! columnId ;
2019-06-09 06:07:23 -04:00
let contents ;
if ( conversationsMode ) {
contents = (
< ConversationsListContainer
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
timelineId = 'direct'
2023-04-07 09:44:31 -04:00
bindToDocument = { ! multiColumn }
2019-06-09 06:07:23 -04:00
onLoadMore = { this . handleLoadMore }
2022-05-03 04:59:23 -04: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 09:44:31 -04:00
alwaysPrepend
2023-06-11 07:33:45 -04: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." / > }
2019-06-09 06:07:23 -04:00
/ >
) ;
} else {
contents = (
< StatusListContainer
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
timelineId = 'direct'
2023-04-07 09:44:31 -04:00
bindToDocument = { ! multiColumn }
2019-06-09 06:07:23 -04:00
onLoadMore = { this . handleLoadMoreTimeline }
2022-05-03 05:38:17 -04: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 09:44:31 -04:00
alwaysPrepend
2023-06-11 07:33:45 -04: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." / > }
2019-06-09 06:07:23 -04:00
/ >
) ;
}
2017-10-16 00:02:39 -04:00
return (
2019-08-01 13:17:17 -04:00
< Column bindToDocument = { ! multiColumn } ref = { this . setRef } label = { intl . formatMessage ( messages . title ) } >
2017-10-16 00:02:39 -04:00
< ColumnHeader
icon = 'envelope'
2023-10-24 13:45:08 -04:00
iconComponent = { MailIcon }
2017-10-16 00:02:39 -04:00
active = { hasUnread }
title = { intl . formatMessage ( messages . title ) }
onPin = { this . handlePin }
onMove = { this . handleMove }
onClick = { this . handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
>
< ColumnSettingsContainer / >
< / ColumnHeader >
2019-06-09 06:07:23 -04:00
{ contents }
2022-10-08 21:55:09 -04:00
< Helmet >
< title > { intl . formatMessage ( messages . title ) } < / title >
2022-10-20 08:35:29 -04:00
< meta name = 'robots' content = 'noindex' / >
2022-10-08 21:55:09 -04:00
< / Helmet >
2017-10-16 00:02:39 -04:00
< / Column >
) ;
}
}
2023-03-24 18:15:25 -04:00
export default connect ( mapStateToProps ) ( injectIntl ( DirectTimeline ) ) ;