'use strict'; import React from 'react'; import { FormattedMessage } from 'react-intl'; import Icon from 'soapbox/components/icon'; import { HStack, Stack, Text } from 'soapbox/components/ui'; import { useInstance } from 'soapbox/hooks'; import type { Map as ImmutableMap } from 'immutable'; const hasRestrictions = (remoteInstance: ImmutableMap): boolean => { return remoteInstance .get('federation') .deleteAll(['accept', 'reject_deletes', 'report_removal']) .reduce((acc: boolean, value: boolean) => acc || value, false); }; interface IRestriction { icon: string, children: React.ReactNode, } const Restriction: React.FC = ({ icon, children }) => { return ( {children} ); }; interface IInstanceRestrictions { remoteInstance: ImmutableMap, } const InstanceRestrictions: React.FC = ({ remoteInstance }) => { const instance = useInstance(); 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(( )); } else if (federated_timeline_removal) { items.push(( )); } if (fullMediaRemoval) { items.push(( )); } else if (partialMediaRemoval) { items.push(( )); } if (!fullMediaRemoval && media_nsfw) { items.push(( )); } return items; }; const renderContent = () => { if (!instance || !remoteInstance) return null; const host = remoteInstance.get('host'); const siteTitle = instance.get('title'); if (remoteInstance.getIn(['federation', 'reject']) === true) { return ( ); } else if (hasRestrictions(remoteInstance)) { return ( <> {renderRestrictions()} ); } else { return ( ); } }; return ( {renderContent()} ); }; export default InstanceRestrictions;