2022-10-09 03:55:09 +02:00
import PropTypes from 'prop-types' ;
2024-01-28 14:53:08 +01:00
import { useRef , useCallback , useEffect } from 'react' ;
2023-05-28 16:38:10 +02:00
2024-01-28 14:53:08 +01:00
import { defineMessages , useIntl , FormattedMessage } from 'react-intl' ;
2023-05-28 16:38:10 +02:00
import { Helmet } from 'react-helmet' ;
2024-01-28 14:53:08 +01:00
import { useDispatch , useSelector } from 'react-redux' ;
2023-10-24 19:45:08 +02:00
2024-01-16 11:27:26 +01:00
import MailIcon from '@/material-icons/400-24px/mail.svg?react' ;
2022-10-09 03:55:09 +02: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 08:26:40 +01:00
import Column from 'flavours/glitch/components/column' ;
import ColumnHeader from 'flavours/glitch/components/column_header' ;
2022-10-09 03:55:09 +02:00
import StatusListContainer from 'flavours/glitch/features/ui/containers/status_list_container' ;
2023-05-28 16:38:10 +02:00
2024-01-28 14:53:08 +01:00
import { ConversationsList } from './components/conversations_list' ;
2017-10-16 06:02:39 +02:00
import ColumnSettingsContainer from './containers/column_settings_container' ;
const messages = defineMessages ( {
2023-06-11 13:33:45 +02:00
title : { id : 'column.direct' , defaultMessage : 'Private mentions' } ,
2017-10-16 06:02:39 +02:00
} ) ;
2024-01-28 14:53:08 +01:00
const DirectTimeline = ( { columnId , multiColumn } ) => {
const columnRef = useRef ( ) ;
const intl = useIntl ( ) ;
const dispatch = useDispatch ( ) ;
const pinned = ! ! columnId ;
2017-10-16 06:02:39 +02:00
2024-01-28 14:53:08 +01:00
// glitch-soc additions
const hasUnread = useSelector ( state => state . getIn ( [ 'timelines' , 'direct' , 'unread' ] ) > 0 ) ;
const conversationsMode = useSelector ( state => state . getIn ( [ 'settings' , 'direct' , 'conversations' ] ) ) ;
2017-10-16 06:02:39 +02:00
2024-01-28 14:53:08 +01:00
const handlePin = useCallback ( ( ) => {
2017-10-16 06:02:39 +02:00
if ( columnId ) {
dispatch ( removeColumn ( columnId ) ) ;
} else {
dispatch ( addColumn ( 'DIRECT' , { } ) ) ;
}
2024-01-28 14:53:08 +01:00
} , [ dispatch , columnId ] ) ;
2017-10-16 06:02:39 +02:00
2024-01-28 14:53:08 +01:00
const handleMove = useCallback ( ( dir ) => {
2017-10-16 06:02:39 +02:00
dispatch ( moveColumn ( columnId , dir ) ) ;
2024-01-28 14:53:08 +01:00
} , [ dispatch , columnId ] ) ;
2017-10-16 06:02:39 +02:00
2024-01-28 14:53:08 +01:00
const handleHeaderClick = useCallback ( ( ) => {
columnRef . current . scrollTop ( ) ;
} , [ columnRef ] ) ;
2017-10-16 06:02:39 +02:00
2024-01-28 14:53:08 +01:00
const handleLoadMoreTimeline = useCallback ( maxId => {
dispatch ( expandDirectTimeline ( { maxId } ) ) ;
} , [ dispatch ] ) ;
2019-06-09 12:07:23 +02:00
2024-01-28 14:53:08 +01:00
useEffect ( ( ) => {
2019-06-09 12:07:23 +02:00
dispatch ( mountConversations ( ) ) ;
if ( conversationsMode ) {
dispatch ( expandConversations ( ) ) ;
} else {
dispatch ( expandDirectTimeline ( ) ) ;
}
2017-10-16 06:02:39 +02:00
2024-01-28 14:53:08 +01:00
const disconnect = dispatch ( connectDirectStream ( ) ) ;
return ( ) => {
dispatch ( unmountConversations ( ) ) ;
disconnect ( ) ;
} ;
} , [ dispatch , conversationsMode ] ) ;
return (
< Column bindToDocument = { ! multiColumn } ref = { columnRef } label = { intl . formatMessage ( messages . title ) } >
< ColumnHeader
icon = 'envelope'
iconComponent = { MailIcon }
active = { hasUnread }
title = { intl . formatMessage ( messages . title ) }
onPin = { handlePin }
onMove = { handleMove }
onClick = { handleHeaderClick }
pinned = { pinned }
multiColumn = { multiColumn }
>
< ColumnSettingsContainer / >
< / ColumnHeader >
{ conversationsMode ? (
< ConversationsList
2019-06-09 12:07:23 +02:00
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
2024-01-28 14:53:08 +01: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." / > }
2023-04-07 15:44:31 +02:00
bindToDocument = { ! multiColumn }
2022-05-03 10:59:23 +02: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 15:44:31 +02:00
alwaysPrepend
2019-06-09 12:07:23 +02:00
/ >
2024-01-28 14:53:08 +01:00
) : (
2019-06-09 12:07:23 +02:00
< StatusListContainer
trackScroll = { ! pinned }
scrollKey = { ` direct_timeline- ${ columnId } ` }
timelineId = 'direct'
2023-04-07 15:44:31 +02:00
bindToDocument = { ! multiColumn }
2024-01-28 14:53:08 +01:00
onLoadMore = { handleLoadMoreTimeline }
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 15:44:31 +02:00
alwaysPrepend
2023-06-11 13:33:45 +02: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 12:07:23 +02:00
/ >
2024-01-28 14:53:08 +01:00
) }
< 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 ;