import PropTypes from "prop-types"; import { defineMessages, injectIntl, FormattedMessage } from "react-intl"; import classNames from "classnames"; import { Link } from "react-router-dom"; import ImmutablePropTypes from "react-immutable-proptypes"; import ImmutablePureComponent from "react-immutable-pure-component"; import { EmptyAccount } from "mastodon/components/empty_account"; import { ShortNumber } from "mastodon/components/short_number"; import { VerifiedBadge } from "mastodon/components/verified_badge"; import { me } from "../initial_state"; import { Avatar } from "./avatar"; import Button from "./button"; import { FollowersCounter } from "./counters"; import { DisplayName } from "./display_name"; import { IconButton } from "./icon_button"; import { RelativeTimestamp } from "./relative_timestamp"; const messages = defineMessages({ follow: { id: "account.follow", defaultMessage: "Follow" }, unfollow: { id: "account.unfollow", defaultMessage: "Unfollow" }, cancel_follow_request: { id: "account.cancel_follow_request", defaultMessage: "Withdraw follow request" }, unblock: { id: "account.unblock_short", defaultMessage: "Unblock" }, unmute: { id: "account.unmute_short", defaultMessage: "Unmute" }, mute_notifications: { id: "account.mute_notifications_short", defaultMessage: "Mute notifications" }, unmute_notifications: { id: "account.unmute_notifications_short", defaultMessage: "Unmute notifications" }, mute: { id: "account.mute_short", defaultMessage: "Mute" }, block: { id: "account.block_short", defaultMessage: "Block" }, }); class Account extends ImmutablePureComponent { static propTypes = { size: PropTypes.number, account: ImmutablePropTypes.map, onFollow: PropTypes.func.isRequired, onBlock: PropTypes.func.isRequired, onMute: PropTypes.func.isRequired, onMuteNotifications: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, hidden: PropTypes.bool, minimal: PropTypes.bool, actionIcon: PropTypes.string, actionTitle: PropTypes.string, defaultAction: PropTypes.string, onActionClick: PropTypes.func, withBio: PropTypes.bool, }; static defaultProps = { size: 46, }; 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, withBio, onActionClick, actionIcon, actionTitle, defaultAction, size, minimal } = this.props; if (!account) { return ; } if (hidden) { return ( <> {account.get("display_name")} {account.get("username")} ); } let buttons; if (actionIcon && onActionClick) { buttons = ; } else if (!actionIcon && 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"]); if (requested) { buttons =