2023-07-01 22:05:10 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useRef, useCallback, useEffect } from 'react';
|
|
|
|
|
|
|
|
import { useIntl, defineMessages, FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
import { Helmet } from 'react-helmet';
|
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
|
2024-01-12 20:16:48 +00:00
|
|
|
import PublicIcon from 'mastodon/../material-icons/400-24px/public.svg?react';
|
2023-07-01 22:05:10 +00:00
|
|
|
import { addColumn } from 'mastodon/actions/columns';
|
|
|
|
import { changeSetting } from 'mastodon/actions/settings';
|
|
|
|
import { connectPublicStream, connectCommunityStream } from 'mastodon/actions/streaming';
|
|
|
|
import { expandPublicTimeline, expandCommunityTimeline } from 'mastodon/actions/timelines';
|
2023-07-08 09:12:20 +00:00
|
|
|
import { DismissableBanner } from 'mastodon/components/dismissable_banner';
|
2023-07-01 22:05:10 +00:00
|
|
|
import initialState, { domain } from 'mastodon/initial_state';
|
|
|
|
import { useAppDispatch, useAppSelector } from 'mastodon/store';
|
|
|
|
|
|
|
|
import Column from '../../components/column';
|
|
|
|
import ColumnHeader from '../../components/column_header';
|
|
|
|
import SettingToggle from '../notifications/components/setting_toggle';
|
|
|
|
import StatusListContainer from '../ui/containers/status_list_container';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
title: { id: 'column.firehose', defaultMessage: 'Live feeds' },
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: use a proper React context later on
|
|
|
|
const useIdentity = () => ({
|
|
|
|
signedIn: !!initialState.meta.me,
|
|
|
|
accountId: initialState.meta.me,
|
|
|
|
disabledAccountId: initialState.meta.disabled_account_id,
|
|
|
|
accessToken: initialState.meta.access_token,
|
|
|
|
permissions: initialState.role ? initialState.role.permissions : 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
const ColumnSettings = () => {
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
const settings = useAppSelector((state) => state.getIn(['settings', 'firehose']));
|
|
|
|
const onChange = useCallback(
|
|
|
|
(key, checked) => dispatch(changeSetting(['firehose', ...key], checked)),
|
|
|
|
[dispatch],
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className='column-settings__row'>
|
|
|
|
<SettingToggle
|
|
|
|
settings={settings}
|
|
|
|
settingPath={['onlyMedia']}
|
|
|
|
onChange={onChange}
|
|
|
|
label={<FormattedMessage id='community.column_settings.media_only' defaultMessage='Media only' />}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const Firehose = ({ feedType, multiColumn }) => {
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
const intl = useIntl();
|
|
|
|
const { signedIn } = useIdentity();
|
|
|
|
const columnRef = useRef(null);
|
|
|
|
|
|
|
|
const onlyMedia = useAppSelector((state) => state.getIn(['settings', 'firehose', 'onlyMedia'], false));
|
|
|
|
const hasUnread = useAppSelector((state) => state.getIn(['timelines', `${feedType}${onlyMedia ? ':media' : ''}`, 'unread'], 0) > 0);
|
|
|
|
|
|
|
|
const handlePin = useCallback(
|
|
|
|
() => {
|
|
|
|
switch(feedType) {
|
|
|
|
case 'community':
|
|
|
|
dispatch(addColumn('COMMUNITY', { other: { onlyMedia } }));
|
|
|
|
break;
|
|
|
|
case 'public':
|
|
|
|
dispatch(addColumn('PUBLIC', { other: { onlyMedia } }));
|
|
|
|
break;
|
|
|
|
case 'public:remote':
|
|
|
|
dispatch(addColumn('REMOTE', { other: { onlyMedia, onlyRemote: true } }));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[dispatch, onlyMedia, feedType],
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleLoadMore = useCallback(
|
|
|
|
(maxId) => {
|
|
|
|
switch(feedType) {
|
|
|
|
case 'community':
|
2023-07-03 22:37:57 +00:00
|
|
|
dispatch(expandCommunityTimeline({ maxId, onlyMedia }));
|
2023-07-01 22:05:10 +00:00
|
|
|
break;
|
|
|
|
case 'public':
|
|
|
|
dispatch(expandPublicTimeline({ maxId, onlyMedia }));
|
|
|
|
break;
|
|
|
|
case 'public:remote':
|
|
|
|
dispatch(expandPublicTimeline({ maxId, onlyMedia, onlyRemote: true }));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[dispatch, onlyMedia, feedType],
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleHeaderClick = useCallback(() => columnRef.current?.scrollTop(), []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
let disconnect;
|
|
|
|
|
|
|
|
switch(feedType) {
|
|
|
|
case 'community':
|
|
|
|
dispatch(expandCommunityTimeline({ onlyMedia }));
|
|
|
|
if (signedIn) {
|
|
|
|
disconnect = dispatch(connectCommunityStream({ onlyMedia }));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'public':
|
|
|
|
dispatch(expandPublicTimeline({ onlyMedia }));
|
|
|
|
if (signedIn) {
|
|
|
|
disconnect = dispatch(connectPublicStream({ onlyMedia }));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'public:remote':
|
|
|
|
dispatch(expandPublicTimeline({ onlyMedia, onlyRemote: true }));
|
|
|
|
if (signedIn) {
|
|
|
|
disconnect = dispatch(connectPublicStream({ onlyMedia, onlyRemote: true }));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return () => disconnect?.();
|
|
|
|
}, [dispatch, signedIn, feedType, onlyMedia]);
|
|
|
|
|
|
|
|
const prependBanner = feedType === 'community' ? (
|
|
|
|
<DismissableBanner id='community_timeline'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='dismissable_banner.community_timeline'
|
|
|
|
defaultMessage='These are the most recent public posts from people whose accounts are hosted by {domain}.'
|
|
|
|
values={{ domain }}
|
|
|
|
/>
|
|
|
|
</DismissableBanner>
|
|
|
|
) : (
|
2023-07-03 20:57:18 +00:00
|
|
|
<DismissableBanner id='public_timeline'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='dismissable_banner.public_timeline'
|
|
|
|
defaultMessage='These are the most recent public posts from people on the social web that people on {domain} follow.'
|
|
|
|
values={{ domain }}
|
|
|
|
/>
|
|
|
|
</DismissableBanner>
|
2023-07-01 22:05:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const emptyMessage = feedType === 'community' ? (
|
|
|
|
<FormattedMessage
|
|
|
|
id='empty_column.community'
|
|
|
|
defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!'
|
|
|
|
/>
|
|
|
|
) : (
|
2023-07-03 20:57:18 +00:00
|
|
|
<FormattedMessage
|
|
|
|
id='empty_column.public'
|
|
|
|
defaultMessage='There is nothing here! Write something publicly, or manually follow users from other servers to fill it up'
|
|
|
|
/>
|
2023-07-01 22:05:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Column bindToDocument={!multiColumn} ref={columnRef} label={intl.formatMessage(messages.title)}>
|
|
|
|
<ColumnHeader
|
|
|
|
icon='globe'
|
2023-10-24 17:45:08 +00:00
|
|
|
iconComponent={PublicIcon}
|
2023-07-01 22:05:10 +00:00
|
|
|
active={hasUnread}
|
|
|
|
title={intl.formatMessage(messages.title)}
|
|
|
|
onPin={handlePin}
|
|
|
|
onClick={handleHeaderClick}
|
|
|
|
multiColumn={multiColumn}
|
|
|
|
>
|
|
|
|
<ColumnSettings />
|
|
|
|
</ColumnHeader>
|
|
|
|
|
2023-10-03 11:12:39 +00:00
|
|
|
<div className='account__section-headline'>
|
|
|
|
<NavLink exact to='/public/local'>
|
|
|
|
<FormattedMessage tagName='div' id='firehose.local' defaultMessage='This server' />
|
|
|
|
</NavLink>
|
|
|
|
|
|
|
|
<NavLink exact to='/public/remote'>
|
|
|
|
<FormattedMessage tagName='div' id='firehose.remote' defaultMessage='Other servers' />
|
|
|
|
</NavLink>
|
|
|
|
|
|
|
|
<NavLink exact to='/public'>
|
|
|
|
<FormattedMessage tagName='div' id='firehose.all' defaultMessage='All' />
|
|
|
|
</NavLink>
|
2023-07-01 22:05:10 +00:00
|
|
|
</div>
|
|
|
|
|
2023-10-03 11:12:39 +00:00
|
|
|
<StatusListContainer
|
|
|
|
prepend={prependBanner}
|
|
|
|
timelineId={`${feedType}${onlyMedia ? ':media' : ''}`}
|
|
|
|
onLoadMore={handleLoadMore}
|
|
|
|
trackScroll
|
|
|
|
scrollKey='firehose'
|
|
|
|
emptyMessage={emptyMessage}
|
|
|
|
bindToDocument={!multiColumn}
|
|
|
|
/>
|
|
|
|
|
2023-07-01 22:05:10 +00:00
|
|
|
<Helmet>
|
|
|
|
<title>{intl.formatMessage(messages.title)}</title>
|
|
|
|
<meta name='robots' content='noindex' />
|
|
|
|
</Helmet>
|
|
|
|
</Column>
|
|
|
|
);
|
2023-10-09 11:38:29 +00:00
|
|
|
};
|
2023-07-01 22:05:10 +00:00
|
|
|
|
|
|
|
Firehose.propTypes = {
|
|
|
|
multiColumn: PropTypes.bool,
|
|
|
|
feedType: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Firehose;
|