import React, { Fragment } from 'react'; import { connect } from 'react-redux'; import ImmutablePropTypes from 'react-immutable-proptypes'; import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import Avatar from './avatar'; import DisplayName from './display_name'; import Permalink from './permalink'; import Icon from './icon'; import IconButton from './icon_button'; import RelativeTimestamp from './relative_timestamp'; import { defineMessages, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import classNames from 'classnames'; import emojify from 'soapbox/features/emoji/emoji'; const messages = defineMessages({ follow: { id: 'account.follow', defaultMessage: 'Follow' }, unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' }, requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' }, unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' }, unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' }, mute_notifications: { id: 'account.mute_notifications', defaultMessage: 'Mute notifications from @{name}' }, unmute_notifications: { id: 'account.unmute_notifications', defaultMessage: 'Unmute notifications from @{name}' }, }); const mapStateToProps = state => { return { me: state.get('me'), }; }; export default @connect(mapStateToProps) @injectIntl class Account extends ImmutablePureComponent { static propTypes = { account: ImmutablePropTypes.map.isRequired, onFollow: PropTypes.func.isRequired, onBlock: PropTypes.func.isRequired, onMute: PropTypes.func.isRequired, onMuteNotifications: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, hidden: PropTypes.bool, actionIcon: PropTypes.string, actionTitle: PropTypes.string, onActionClick: PropTypes.func, withDate: PropTypes.bool, withRelationship: PropTypes.bool, reaction: PropTypes.string, }; static defaultProps = { withDate: false, withRelationship: true, } handleFollow = () => { this.props.onFollow(this.props.account); } handleBlock = () => { this.props.onBlock(this.props.account); } handleMute = () => { this.props.onMute(this.props.account); } handleMuteNotifications = () => { this.props.onMuteNotifications(this.props.account, true); } handleUnmuteNotifications = () => { this.props.onMuteNotifications(this.props.account, false); } handleAction = () => { this.props.onActionClick(this.props.account); } render() { const { account, intl, hidden, onActionClick, actionIcon, actionTitle, me, withDate, withRelationship, reaction } = this.props; if (!account) { return
; } if (hidden) { return ( {account.get('display_name')} {account.get('username')} ); } let buttons; let followedBy; let emoji; if (onActionClick && actionIcon) { buttons = ; } else if (account.get('id') !== me && account.get('relationship', null) !== null) { const following = account.getIn(['relationship', 'following']); const requested = account.getIn(['relationship', 'requested']); const blocking = account.getIn(['relationship', 'blocking']); const muting = account.getIn(['relationship', 'muting']); followedBy = account.getIn(['relationship', 'followed_by']); if (requested) { buttons = ; } else if (blocking) { buttons = ; } else if (muting) { let hidingNotificationsButton; if (account.getIn(['relationship', 'muting_notifications'])) { hidingNotificationsButton = ; } else { hidingNotificationsButton = ; } buttons = ( {hidingNotificationsButton} ); } else if (!account.get('moved') || following) { buttons = ; } } if (reaction) { emoji = ( ); } const createdAt = account.get('created_at'); const joinedAt = createdAt ? (
) : null; return (
{emoji}
{withRelationship ? (<> {followedBy && }
{buttons}
) : withDate && joinedAt}
); } }