'use strict'; import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import Icon from 'soapbox/components/icon'; const hasRestrictions = remoteInstance => { return remoteInstance .get('federation') .deleteAll(['accept', 'reject_deletes', 'report_removal']) .reduce((acc, value) => acc || value, false); }; const mapStateToProps = state => { return { instance: state.get('instance'), }; }; export default @connect(mapStateToProps) class InstanceRestrictions extends ImmutablePureComponent { static propTypes = { intl: PropTypes.object.isRequired, remoteInstance: ImmutablePropTypes.map.isRequired, instance: ImmutablePropTypes.map, }; renderRestrictions = () => { const { remoteInstance } = this.props; 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; } renderContent = () => { const { instance, remoteInstance } = this.props; 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 [ (
), this.renderRestrictions(), ]; } else { return (
); } } render() { return
{this.renderContent()}
; } }