Merge branch 'restrict-unauthenticated' into 'main'
Hide unauth features if they're restricted by the backend See merge request soapbox-pub/soapbox!2753
This commit is contained in:
commit
f0f2f6fa41
4 changed files with 62 additions and 25 deletions
|
@ -2,12 +2,16 @@ import { useTimelineStream } from './useTimelineStream';
|
||||||
|
|
||||||
interface UseCommunityStreamOpts {
|
interface UseCommunityStreamOpts {
|
||||||
onlyMedia?: boolean
|
onlyMedia?: boolean
|
||||||
|
enabled?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function useCommunityStream({ onlyMedia }: UseCommunityStreamOpts = {}) {
|
function useCommunityStream({ onlyMedia, enabled }: UseCommunityStreamOpts = {}) {
|
||||||
return useTimelineStream(
|
return useTimelineStream(
|
||||||
`community${onlyMedia ? ':media' : ''}`,
|
`community${onlyMedia ? ':media' : ''}`,
|
||||||
`public:local${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 { Stack } from 'soapbox/components/ui';
|
||||||
import { useStatContext } from 'soapbox/contexts/stat-context';
|
import { useStatContext } from 'soapbox/contexts/stat-context';
|
||||||
import ComposeButton from 'soapbox/features/ui/components/compose-button';
|
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 DropdownMenu, { Menu } from './dropdown-menu';
|
||||||
import SidebarNavigationLink from './sidebar-navigation-link';
|
import SidebarNavigationLink from './sidebar-navigation-link';
|
||||||
|
@ -22,6 +22,7 @@ const SidebarNavigation = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const { unreadChatsCount } = useStatContext();
|
const { unreadChatsCount } = useStatContext();
|
||||||
|
|
||||||
|
const instance = useInstance();
|
||||||
const features = useFeatures();
|
const features = useFeatures();
|
||||||
const settings = useSettings();
|
const settings = useSettings();
|
||||||
const { account } = useOwnAccount();
|
const { account } = useOwnAccount();
|
||||||
|
@ -31,6 +32,8 @@ const SidebarNavigation = () => {
|
||||||
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
|
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
|
||||||
const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count());
|
const dashboardCount = useAppSelector((state) => state.admin.openReports.count() + state.admin.awaitingApproval.count());
|
||||||
|
|
||||||
|
const restrictUnauth = instance.pleroma.metadata.restrict_unauthenticated;
|
||||||
|
|
||||||
const makeMenu = (): Menu => {
|
const makeMenu = (): Menu => {
|
||||||
const menu: Menu = [];
|
const menu: Menu = [];
|
||||||
|
|
||||||
|
@ -166,15 +169,17 @@ const SidebarNavigation = () => {
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{features.publicTimeline && (
|
{(features.publicTimeline) && (
|
||||||
<>
|
<>
|
||||||
|
{(account || !restrictUnauth.timelines.local) && (
|
||||||
<SidebarNavigationLink
|
<SidebarNavigationLink
|
||||||
to='/timeline/local'
|
to='/timeline/local'
|
||||||
icon={features.federating ? require('@tabler/icons/affiliate.svg') : require('@tabler/icons/world.svg')}
|
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' />}
|
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
|
<SidebarNavigationLink
|
||||||
to='/timeline/fediverse'
|
to='/timeline/fediverse'
|
||||||
icon={require('@tabler/icons/topology-star-ring-3.svg')}
|
icon={require('@tabler/icons/topology-star-ring-3.svg')}
|
||||||
|
|
|
@ -5,30 +5,40 @@ import { expandCommunityTimeline } from 'soapbox/actions/timelines';
|
||||||
import { useCommunityStream } from 'soapbox/api/hooks';
|
import { useCommunityStream } from 'soapbox/api/hooks';
|
||||||
import PullToRefresh from 'soapbox/components/pull-to-refresh';
|
import PullToRefresh from 'soapbox/components/pull-to-refresh';
|
||||||
import { Column } from 'soapbox/components/ui';
|
import { Column } from 'soapbox/components/ui';
|
||||||
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
|
import { useAppSelector, useAppDispatch, useInstance } from 'soapbox/hooks';
|
||||||
|
|
||||||
|
import AboutPage from '../about';
|
||||||
import Timeline from '../ui/components/timeline';
|
import Timeline from '../ui/components/timeline';
|
||||||
|
|
||||||
import { SiteBanner } from './components/site-banner';
|
import { SiteBanner } from './components/site-banner';
|
||||||
|
|
||||||
const LandingTimeline = () => {
|
const LandingTimeline = () => {
|
||||||
const dispatch = useAppDispatch();
|
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 next = useAppSelector(state => state.timelines.get('community')?.next);
|
||||||
|
|
||||||
const timelineId = 'community';
|
const timelineId = 'community';
|
||||||
|
|
||||||
const handleLoadMore = (maxId: string) => {
|
const handleLoadMore = (maxId: string) => {
|
||||||
|
if (timelineEnabled) {
|
||||||
dispatch(expandCommunityTimeline({ url: next, maxId }));
|
dispatch(expandCommunityTimeline({ url: next, maxId }));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRefresh = () => {
|
const handleRefresh = async () => {
|
||||||
|
if (timelineEnabled) {
|
||||||
return dispatch(expandCommunityTimeline());
|
return dispatch(expandCommunityTimeline());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useCommunityStream();
|
useCommunityStream({ enabled: timelineEnabled });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (timelineEnabled) {
|
||||||
dispatch(expandCommunityTimeline());
|
dispatch(expandCommunityTimeline());
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -37,6 +47,7 @@ const LandingTimeline = () => {
|
||||||
<SiteBanner />
|
<SiteBanner />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{timelineEnabled ? (
|
||||||
<PullToRefresh onRefresh={handleRefresh}>
|
<PullToRefresh onRefresh={handleRefresh}>
|
||||||
<Timeline
|
<Timeline
|
||||||
scrollKey={`${timelineId}_timeline`}
|
scrollKey={`${timelineId}_timeline`}
|
||||||
|
@ -47,6 +58,9 @@ const LandingTimeline = () => {
|
||||||
divideType='space'
|
divideType='space'
|
||||||
/>
|
/>
|
||||||
</PullToRefresh>
|
</PullToRefresh>
|
||||||
|
) : (
|
||||||
|
<AboutPage />
|
||||||
|
)}
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -53,6 +53,20 @@ const pleromaSchema = coerceObject({
|
||||||
}),
|
}),
|
||||||
fields_limits: z.any(),
|
fields_limits: z.any(),
|
||||||
migration_cooldown_period: z.number().optional().catch(undefined),
|
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({
|
translation: coerceObject({
|
||||||
allow_remote: z.boolean().catch(true),
|
allow_remote: z.boolean().catch(true),
|
||||||
allow_unauthenticated: z.boolean().catch(false),
|
allow_unauthenticated: z.boolean().catch(false),
|
||||||
|
|
Loading…
Reference in a new issue