Hide unauth features if they're restricted by the backend

environments/review-restrict-u-4cwit0/deployments/4043
Alex Gleason 1 year ago
parent aabaaee8b8
commit 8500e7bb9a
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -2,12 +2,16 @@ import { useTimelineStream } from './useTimelineStream';
interface UseCommunityStreamOpts {
onlyMedia?: boolean
enabled?: boolean
}
function useCommunityStream({ onlyMedia }: UseCommunityStreamOpts = {}) {
function useCommunityStream({ onlyMedia, enabled }: UseCommunityStreamOpts = {}) {
return useTimelineStream(
`community${onlyMedia ? ':media' : ''}`,
`public:local${onlyMedia ? ':media' : ''}`,
undefined,
undefined,
{ enabled },
);
}

@ -4,7 +4,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { Stack } from 'soapbox/components/ui';
import { useStatContext } from 'soapbox/contexts/stat-context';
import ComposeButton from 'soapbox/features/ui/components/compose-button';
import { useAppSelector, useGroupsPath, useFeatures, useOwnAccount, useSettings } from 'soapbox/hooks';
import { useAppSelector, useGroupsPath, useFeatures, useOwnAccount, useSettings, useInstance } from 'soapbox/hooks';
import DropdownMenu, { Menu } from './dropdown-menu';
import SidebarNavigationLink from './sidebar-navigation-link';
@ -22,6 +22,7 @@ const SidebarNavigation = () => {
const intl = useIntl();
const { unreadChatsCount } = useStatContext();
const instance = useInstance();
const features = useFeatures();
const settings = useSettings();
const { account } = useOwnAccount();
@ -31,6 +32,8 @@ const SidebarNavigation = () => {
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count());
const restrictUnauth = instance.pleroma.metadata.restrict_unauthenticated;
const makeMenu = (): Menu => {
const menu: Menu = [];
@ -166,15 +169,17 @@ const SidebarNavigation = () => {
</>
)}
{features.publicTimeline && (
{(features.publicTimeline) && (
<>
<SidebarNavigationLink
to='/timeline/local'
icon={features.federating ? require('@tabler/icons/affiliate.svg') : require('@tabler/icons/world.svg')}
text={features.federating ? <FormattedMessage id='tabs_bar.local' defaultMessage='Local' /> : <FormattedMessage id='tabs_bar.all' defaultMessage='All' />}
/>
{(account || !restrictUnauth.timelines.local) && (
<SidebarNavigationLink
to='/timeline/local'
icon={features.federating ? require('@tabler/icons/affiliate.svg') : require('@tabler/icons/world.svg')}
text={features.federating ? <FormattedMessage id='tabs_bar.local' defaultMessage='Local' /> : <FormattedMessage id='tabs_bar.all' defaultMessage='All' />}
/>
)}
{features.federating && (
{(features.federating && (account || !restrictUnauth.timelines.federated)) && (
<SidebarNavigationLink
to='/timeline/fediverse'
icon={require('@tabler/icons/topology-star-ring-3.svg')}

@ -5,7 +5,7 @@ import { expandCommunityTimeline } from 'soapbox/actions/timelines';
import { useCommunityStream } from 'soapbox/api/hooks';
import PullToRefresh from 'soapbox/components/pull-to-refresh';
import { Column } from 'soapbox/components/ui';
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
import { useAppSelector, useAppDispatch, useInstance } from 'soapbox/hooks';
import Timeline from '../ui/components/timeline';
@ -13,22 +13,31 @@ import { SiteBanner } from './components/site-banner';
const LandingTimeline = () => {
const dispatch = useAppDispatch();
const instance = useInstance();
const timelineEnabled = !instance.pleroma.metadata.restrict_unauthenticated.timelines.local;
const next = useAppSelector(state => state.timelines.get('community')?.next);
const timelineId = 'community';
const handleLoadMore = (maxId: string) => {
dispatch(expandCommunityTimeline({ url: next, maxId }));
if (timelineEnabled) {
dispatch(expandCommunityTimeline({ url: next, maxId }));
}
};
const handleRefresh = () => {
return dispatch(expandCommunityTimeline());
const handleRefresh = async () => {
if (timelineEnabled) {
return dispatch(expandCommunityTimeline());
}
};
useCommunityStream();
useCommunityStream({ enabled: timelineEnabled });
useEffect(() => {
dispatch(expandCommunityTimeline());
if (timelineEnabled) {
dispatch(expandCommunityTimeline());
}
}, []);
return (
@ -37,16 +46,18 @@ const LandingTimeline = () => {
<SiteBanner />
</div>
<PullToRefresh onRefresh={handleRefresh}>
<Timeline
scrollKey={`${timelineId}_timeline`}
timelineId={timelineId}
prefix='home'
onLoadMore={handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}
divideType='space'
/>
</PullToRefresh>
{timelineEnabled && (
<PullToRefresh onRefresh={handleRefresh}>
<Timeline
scrollKey={`${timelineId}_timeline`}
timelineId={timelineId}
prefix='home'
onLoadMore={handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.community' defaultMessage='The local timeline is empty. Write something publicly to get the ball rolling!' />}
divideType='space'
/>
</PullToRefresh>
)}
</Column>
);
};

@ -53,6 +53,20 @@ const pleromaSchema = coerceObject({
}),
fields_limits: z.any(),
migration_cooldown_period: z.number().optional().catch(undefined),
restrict_unauthenticated: coerceObject({
activities: coerceObject({
local: z.boolean().catch(false),
remote: z.boolean().catch(false),
}),
profiles: coerceObject({
local: z.boolean().catch(false),
remote: z.boolean().catch(false),
}),
timelines: coerceObject({
federated: z.boolean().catch(false),
local: z.boolean().catch(false),
}),
}),
translation: coerceObject({
allow_remote: z.boolean().catch(true),
allow_unauthenticated: z.boolean().catch(false),

Loading…
Cancel
Save