bigbuffet-rw/app/soapbox/features/federation-restrictions/components/instance-restrictions.tsx

163 lines
4.6 KiB
TypeScript
Raw Normal View History

'use strict';
import React from 'react';
import { FormattedMessage } from 'react-intl';
import Icon from 'soapbox/components/icon';
2022-11-26 11:18:11 -08:00
import { HStack, Stack, Text } from 'soapbox/components/ui';
2022-11-26 08:38:16 -08:00
import { useInstance } from 'soapbox/hooks';
2022-11-03 13:18:31 -07:00
import type { Map as ImmutableMap } from 'immutable';
const hasRestrictions = (remoteInstance: ImmutableMap<string, any>): boolean => {
return remoteInstance
.get('federation')
.deleteAll(['accept', 'reject_deletes', 'report_removal'])
2022-11-03 13:18:31 -07:00
.reduce((acc: boolean, value: boolean) => acc || value, false);
};
2022-11-26 11:18:11 -08:00
interface IRestriction {
icon: string
children: React.ReactNode
2022-11-26 11:18:11 -08:00
}
const Restriction: React.FC<IRestriction> = ({ icon, children }) => {
return (
<HStack space={3}>
2023-02-01 14:13:42 -08:00
<Icon className='h-5 w-5 flex-none' src={icon} />
2022-11-26 11:18:11 -08:00
<Text theme='muted'>
{children}
</Text>
</HStack>
);
};
2022-11-03 13:18:31 -07:00
interface IInstanceRestrictions {
remoteInstance: ImmutableMap<string, any>
2022-11-03 13:18:31 -07:00
}
2022-11-03 13:18:31 -07:00
const InstanceRestrictions: React.FC<IInstanceRestrictions> = ({ remoteInstance }) => {
2022-11-26 08:38:16 -08:00
const instance = useInstance();
2022-11-03 13:18:31 -07:00
const renderRestrictions = () => {
const items = [];
const {
avatar_removal,
banner_removal,
federated_timeline_removal,
followers_only,
media_nsfw,
media_removal,
} = remoteInstance.get('federation').toJS();
const fullMediaRemoval = media_removal && avatar_removal && banner_removal;
const partialMediaRemoval = media_removal || avatar_removal || banner_removal;
if (followers_only) {
items.push((
2022-11-26 11:18:11 -08:00
<Restriction key='followersOnly' icon={require('@tabler/icons/lock.svg')}>
<FormattedMessage
id='federation_restriction.followers_only'
defaultMessage='Hidden except to followers'
/>
2022-11-26 11:18:11 -08:00
</Restriction>
));
} else if (federated_timeline_removal) {
items.push((
2022-11-26 11:18:11 -08:00
<Restriction key='federatedTimelineRemoval' icon={require('@tabler/icons/lock-open.svg')}>
<FormattedMessage
id='federation_restriction.federated_timeline_removal'
defaultMessage='Fediverse timeline removal'
/>
2022-11-26 11:18:11 -08:00
</Restriction>
));
}
if (fullMediaRemoval) {
items.push((
2022-11-26 11:18:11 -08:00
<Restriction key='fullMediaRemoval' icon={require('@tabler/icons/photo-off.svg')}>
<FormattedMessage
id='federation_restriction.full_media_removal'
defaultMessage='Full media removal'
/>
2022-11-26 11:18:11 -08:00
</Restriction>
));
} else if (partialMediaRemoval) {
items.push((
2022-11-26 11:18:11 -08:00
<Restriction key='partialMediaRemoval' icon={require('@tabler/icons/photo-off.svg')}>
<FormattedMessage
id='federation_restriction.partial_media_removal'
defaultMessage='Partial media removal'
/>
2022-11-26 11:18:11 -08:00
</Restriction>
));
}
if (!fullMediaRemoval && media_nsfw) {
items.push((
2022-11-26 11:18:11 -08:00
<Restriction key='mediaNsfw' icon={require('@tabler/icons/eye-off.svg')}>
<FormattedMessage
id='federation_restriction.media_nsfw'
defaultMessage='Attachments marked NSFW'
/>
2022-11-26 11:18:11 -08:00
</Restriction>
));
}
return items;
2022-11-03 13:18:31 -07:00
};
2022-11-03 13:18:31 -07:00
const renderContent = () => {
if (!instance || !remoteInstance) return null;
const host = remoteInstance.get('host');
const siteTitle = instance.get('title');
if (remoteInstance.getIn(['federation', 'reject']) === true) {
return (
2022-11-26 11:18:11 -08:00
<Restriction icon={require('@tabler/icons/shield-x.svg')}>
<FormattedMessage
id='remote_instance.federation_panel.restricted_message'
defaultMessage='{siteTitle} blocks all activities from {host}.'
values={{ host, siteTitle }}
/>
2022-11-26 11:18:11 -08:00
</Restriction>
);
} else if (hasRestrictions(remoteInstance)) {
2022-11-26 11:18:11 -08:00
return (
<>
<Restriction icon={require('@tabler/icons/shield-lock.svg')}>
<FormattedMessage
id='remote_instance.federation_panel.some_restrictions_message'
defaultMessage='{siteTitle} has placed some restrictions on {host}.'
values={{ host, siteTitle }}
/>
2022-11-26 11:18:11 -08:00
</Restriction>
{renderRestrictions()}
</>
);
} else {
return (
2022-11-26 11:18:11 -08:00
<Restriction icon={require('@tabler/icons/shield-check.svg')}>
<FormattedMessage
id='remote_instance.federation_panel.no_restrictions_message'
defaultMessage='{siteTitle} has placed no restrictions on {host}.'
values={{ host, siteTitle }}
/>
2022-11-26 11:18:11 -08:00
</Restriction>
);
}
2022-11-03 13:18:31 -07:00
};
2022-11-03 13:18:31 -07:00
return (
2022-11-26 11:18:11 -08:00
<Stack space={3}>
2022-11-03 13:18:31 -07:00
{renderContent()}
2022-11-26 11:18:11 -08:00
</Stack>
2022-11-03 13:18:31 -07:00
);
};
2022-11-03 13:18:31 -07:00
export default InstanceRestrictions;