2018-04-18 20:09:06 +09:00
import PropTypes from 'prop-types' ;
2024-01-25 23:34:26 +09:00
import { useRef , useCallback , useEffect } from 'react' ;
2023-05-24 00:15:17 +09:00
2024-01-25 23:34:26 +09:00
import { defineMessages , useIntl , FormattedMessage } from 'react-intl' ;
2023-05-24 00:15:17 +09:00
import { Helmet } from 'react-helmet' ;
2024-01-25 23:34:26 +09:00
import { useDispatch } from 'react-redux' ;
2023-05-24 00:15:17 +09:00
2024-01-16 19:27:26 +09:00
import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?react' ;
2022-10-09 10:55:09 +09: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-24 00:15:17 +09:00
2024-01-25 23:34:26 +09:00
import { ConversationsList } from './components/conversations_list' ;
2018-04-18 20:09:06 +09:00
const messages = defineMessages ( {
2023-03-30 22:16:20 +09:00
title : { id : 'column.direct' , defaultMessage : 'Private mentions' } ,
2018-04-18 20:09:06 +09:00
} ) ;
2024-01-25 23:34:26 +09:00
const DirectTimeline = ( { columnId , multiColumn } ) => {
const columnRef = useRef ( ) ;
const intl = useIntl ( ) ;
const dispatch = useDispatch ( ) ;
const pinned = ! ! columnId ;
2018-04-18 20:09:06 +09:00
2024-01-25 23:34:26 +09:00
const handlePin = useCallback ( ( ) => {
2018-04-18 20:09:06 +09:00
if ( columnId ) {
dispatch ( removeColumn ( columnId ) ) ;
} else {
dispatch ( addColumn ( 'DIRECT' , { } ) ) ;
}
2024-01-25 23:34:26 +09:00
} , [ dispatch , columnId ] ) ;
2018-04-18 20:09:06 +09:00
2024-01-25 23:34:26 +09:00
const handleMove = useCallback ( ( dir ) => {
2018-04-18 20:09:06 +09:00
dispatch ( moveColumn ( columnId , dir ) ) ;
2024-01-25 23:34:26 +09:00
} , [ dispatch , columnId ] ) ;
2018-04-18 20:09:06 +09:00
2024-01-25 23:34:26 +09:00
const handleHeaderClick = useCallback ( ( ) => {
columnRef . current . scrollTop ( ) ;
} , [ columnRef ] ) ;
2018-04-18 20:09:06 +09:00
2024-01-25 23:34:26 +09:00
useEffect ( ( ) => {
2018-10-11 08:31:03 +09:00
dispatch ( mountConversations ( ) ) ;
2018-10-08 06:44:58 +09:00
dispatch ( expandConversations ( ) ) ;
2018-04-18 20:09:06 +09:00
2024-01-25 23:34:26 +09:00
const disconnect = dispatch ( connectDirectStream ( ) ) ;
return ( ) => {
dispatch ( unmountConversations ( ) ) ;
disconnect ( ) ;
} ;
} , [ dispatch ] ) ;
return (
< Column bindToDocument = { ! multiColumn } ref = { columnRef } label = { intl . formatMessage ( messages . title ) } >
< ColumnHeader
icon = 'at'
iconComponent = { AlternateEmailIcon }
title = { intl . formatMessage ( messages . title ) }
onPin = { handlePin }
onMove = { handleMove }
onClick = { handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
/ >
< ConversationsList
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
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." / > }
bindToDocument = { ! multiColumn }
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 > }
alwaysPrepend
/ >
< Helmet >
< title > { intl . formatMessage ( messages . title ) } < / title >
< meta name = 'robots' content = 'noindex' / >
< / Helmet >
< / Column >
) ;
} ;
DirectTimeline . propTypes = {
columnId : PropTypes . string ,
multiColumn : PropTypes . bool ,
} ;
export default DirectTimeline ;