2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2016-11-18 23:36:16 +09:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
|
|
|
import classNames from 'classnames';
|
2022-11-14 05:10:20 +09:00
|
|
|
import { Link } from 'react-router-dom';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2023-03-25 16:46:32 +09:00
|
|
|
import { counterRenderer } from 'mastodon/components/common_counter';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { EmptyAccount } from 'mastodon/components/empty_account';
|
2023-03-25 16:46:32 +09:00
|
|
|
import ShortNumber from 'mastodon/components/short_number';
|
2023-05-09 10:11:56 +09:00
|
|
|
import { VerifiedBadge } from 'mastodon/components/verified_badge';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
|
|
|
import { me } from '../initial_state';
|
|
|
|
|
|
|
|
import { Avatar } from './avatar';
|
2023-06-06 11:14:28 +09:00
|
|
|
import Button from './button';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { DisplayName } from './display_name';
|
|
|
|
import { IconButton } from './icon_button';
|
|
|
|
import { RelativeTimestamp } from './relative_timestamp';
|
2016-11-18 23:36:16 +09:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2016-12-12 07:13:05 +09:00
|
|
|
follow: { id: 'account.follow', defaultMessage: 'Follow' },
|
2017-01-17 03:36:32 +09:00
|
|
|
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
|
2023-06-06 11:14:28 +09:00
|
|
|
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' },
|
2016-11-18 23:36:16 +09:00
|
|
|
});
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2018-09-15 00:59:48 +09:00
|
|
|
class Account extends ImmutablePureComponent {
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
2022-10-31 21:06:17 +09:00
|
|
|
size: PropTypes.number,
|
2022-10-05 10:47:56 +09:00
|
|
|
account: ImmutablePropTypes.map,
|
2017-05-12 21:44:10 +09:00
|
|
|
onFollow: PropTypes.func.isRequired,
|
|
|
|
onBlock: PropTypes.func.isRequired,
|
|
|
|
onMute: PropTypes.func.isRequired,
|
2017-12-24 17:18:45 +09:00
|
|
|
onMuteNotifications: PropTypes.func.isRequired,
|
2017-05-21 00:31:47 +09:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-08-29 05:23:44 +09:00
|
|
|
hidden: PropTypes.bool,
|
2023-04-01 16:27:23 +09:00
|
|
|
minimal: PropTypes.bool,
|
2018-10-23 07:08:39 +09:00
|
|
|
actionIcon: PropTypes.string,
|
|
|
|
actionTitle: PropTypes.string,
|
2022-05-10 06:20:19 +09:00
|
|
|
defaultAction: PropTypes.string,
|
2018-10-23 07:08:39 +09:00
|
|
|
onActionClick: PropTypes.func,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
|
|
|
|
2022-10-31 21:06:17 +09:00
|
|
|
static defaultProps = {
|
|
|
|
size: 46,
|
|
|
|
};
|
|
|
|
|
2017-05-25 00:55:16 +09:00
|
|
|
handleFollow = () => {
|
2016-10-29 03:05:44 +09:00
|
|
|
this.props.onFollow(this.props.account);
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2016-10-29 03:05:44 +09:00
|
|
|
|
2017-05-25 00:55:16 +09:00
|
|
|
handleBlock = () => {
|
2017-01-17 03:36:32 +09:00
|
|
|
this.props.onBlock(this.props.account);
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2017-01-17 03:36:32 +09:00
|
|
|
|
2017-05-25 00:55:16 +09:00
|
|
|
handleMute = () => {
|
2017-04-15 08:23:49 +09:00
|
|
|
this.props.onMute(this.props.account);
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2017-04-15 08:23:49 +09:00
|
|
|
|
2017-11-15 11:56:41 +09:00
|
|
|
handleMuteNotifications = () => {
|
|
|
|
this.props.onMuteNotifications(this.props.account, true);
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2017-11-15 11:56:41 +09:00
|
|
|
|
|
|
|
handleUnmuteNotifications = () => {
|
|
|
|
this.props.onMuteNotifications(this.props.account, false);
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2017-11-15 11:56:41 +09:00
|
|
|
|
2018-10-23 07:08:39 +09:00
|
|
|
handleAction = () => {
|
|
|
|
this.props.onActionClick(this.props.account);
|
2023-01-30 09:45:35 +09:00
|
|
|
};
|
2018-10-23 07:08:39 +09:00
|
|
|
|
2016-10-28 04:59:56 +09:00
|
|
|
render () {
|
2023-04-01 16:27:23 +09:00
|
|
|
const { account, intl, hidden, onActionClick, actionIcon, actionTitle, defaultAction, size, minimal } = this.props;
|
2016-10-28 04:59:56 +09:00
|
|
|
|
|
|
|
if (!account) {
|
2023-05-11 14:55:10 +09:00
|
|
|
return <EmptyAccount size={size} minimal={minimal} />;
|
2016-10-28 04:59:56 +09:00
|
|
|
}
|
|
|
|
|
2017-08-29 05:23:44 +09:00
|
|
|
if (hidden) {
|
|
|
|
return (
|
2023-04-01 16:27:23 +09:00
|
|
|
<>
|
2017-08-29 05:23:44 +09:00
|
|
|
{account.get('display_name')}
|
|
|
|
{account.get('username')}
|
2023-04-01 16:27:23 +09:00
|
|
|
</>
|
2017-08-29 05:23:44 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-09 09:20:09 +09:00
|
|
|
let buttons;
|
2016-10-29 03:05:44 +09:00
|
|
|
|
2023-06-06 11:14:28 +09:00
|
|
|
if (actionIcon && onActionClick) {
|
|
|
|
buttons = <IconButton icon={actionIcon} title={actionTitle} onClick={this.handleAction} />;
|
|
|
|
} else if (!actionIcon && account.get('id') !== me && account.get('relationship', null) !== null) {
|
2016-11-02 02:03:51 +09:00
|
|
|
const following = account.getIn(['relationship', 'following']);
|
2017-01-17 03:36:32 +09:00
|
|
|
const requested = account.getIn(['relationship', 'requested']);
|
|
|
|
const blocking = account.getIn(['relationship', 'blocking']);
|
2017-04-15 08:23:49 +09:00
|
|
|
const muting = account.getIn(['relationship', 'muting']);
|
2017-01-17 03:36:32 +09:00
|
|
|
|
|
|
|
if (requested) {
|
2023-06-06 11:14:28 +09:00
|
|
|
buttons = <Button text={intl.formatMessage(messages.cancel_follow_request)} onClick={this.handleFollow} />;
|
2017-01-17 03:36:32 +09:00
|
|
|
} else if (blocking) {
|
2023-06-06 11:14:28 +09:00
|
|
|
buttons = <Button text={intl.formatMessage(messages.unblock)} onClick={this.handleBlock} />;
|
2017-04-15 08:23:49 +09:00
|
|
|
} else if (muting) {
|
2017-11-15 11:56:41 +09:00
|
|
|
let hidingNotificationsButton;
|
2023-06-06 11:14:28 +09:00
|
|
|
|
2017-12-07 00:10:54 +09:00
|
|
|
if (account.getIn(['relationship', 'muting_notifications'])) {
|
2023-06-06 11:14:28 +09:00
|
|
|
hidingNotificationsButton = <Button text={intl.formatMessage(messages.unmute_notifications)} onClick={this.handleUnmuteNotifications} />;
|
2017-11-15 11:56:41 +09:00
|
|
|
} else {
|
2023-06-06 11:14:28 +09:00
|
|
|
hidingNotificationsButton = <Button text={intl.formatMessage(messages.mute_notifications)} onClick={this.handleMuteNotifications} />;
|
2017-11-15 11:56:41 +09:00
|
|
|
}
|
2023-06-06 11:14:28 +09:00
|
|
|
|
2017-11-15 11:56:41 +09:00
|
|
|
buttons = (
|
2023-04-01 16:27:23 +09:00
|
|
|
<>
|
2023-06-06 11:14:28 +09:00
|
|
|
<Button text={intl.formatMessage(messages.unmute)} onClick={this.handleMute} />
|
2017-11-15 11:56:41 +09:00
|
|
|
{hidingNotificationsButton}
|
2023-04-01 16:27:23 +09:00
|
|
|
</>
|
2017-11-15 11:56:41 +09:00
|
|
|
);
|
2022-05-10 06:20:19 +09:00
|
|
|
} else if (defaultAction === 'mute') {
|
2023-06-06 11:14:28 +09:00
|
|
|
buttons = <Button title={intl.formatMessage(messages.mute)} onClick={this.handleMute} />;
|
2022-05-10 06:20:19 +09:00
|
|
|
} else if (defaultAction === 'block') {
|
2023-06-06 11:14:28 +09:00
|
|
|
buttons = <Button text={intl.formatMessage(messages.block)} onClick={this.handleBlock} />;
|
2018-01-16 02:42:15 +09:00
|
|
|
} else if (!account.get('moved') || following) {
|
2023-06-06 11:14:28 +09:00
|
|
|
buttons = <Button text={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} />;
|
2017-01-17 03:36:32 +09:00
|
|
|
}
|
2016-10-28 04:59:56 +09:00
|
|
|
}
|
|
|
|
|
2023-03-25 16:46:32 +09:00
|
|
|
let muteTimeRemaining;
|
|
|
|
|
2020-10-13 08:01:14 +09:00
|
|
|
if (account.get('mute_expires_at')) {
|
2023-03-25 16:46:32 +09:00
|
|
|
muteTimeRemaining = <>· <RelativeTimestamp timestamp={account.get('mute_expires_at')} futureDate /></>;
|
|
|
|
}
|
|
|
|
|
|
|
|
let verification;
|
|
|
|
|
|
|
|
const firstVerifiedField = account.get('fields').find(item => !!item.get('verified_at'));
|
|
|
|
|
|
|
|
if (firstVerifiedField) {
|
2023-06-01 21:47:55 +09:00
|
|
|
verification = <VerifiedBadge link={firstVerifiedField.get('value')} />;
|
2020-10-13 08:01:14 +09:00
|
|
|
}
|
|
|
|
|
2016-10-28 04:59:56 +09:00
|
|
|
return (
|
2023-04-01 16:27:23 +09:00
|
|
|
<div className={classNames('account', { 'account--minimal': minimal })}>
|
2017-04-23 11:26:55 +09:00
|
|
|
<div className='account__wrapper'>
|
2022-11-14 05:10:20 +09:00
|
|
|
<Link key={account.get('id')} className='account__display-name' title={account.get('acct')} to={`/@${account.get('acct')}`}>
|
2023-03-25 16:46:32 +09:00
|
|
|
<div className='account__avatar-wrapper'>
|
|
|
|
<Avatar account={account} size={size} />
|
|
|
|
</div>
|
|
|
|
|
2023-06-01 21:47:55 +09:00
|
|
|
<div className='account__contents'>
|
2023-03-25 16:46:32 +09:00
|
|
|
<DisplayName account={account} />
|
2023-06-01 21:47:55 +09:00
|
|
|
{!minimal && (
|
|
|
|
<div className='account__details'>
|
|
|
|
<ShortNumber value={account.get('followers_count')} renderer={counterRenderer('followers')} /> {verification} {muteTimeRemaining}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-03-25 16:46:32 +09:00
|
|
|
</div>
|
2022-11-14 05:10:20 +09:00
|
|
|
</Link>
|
2016-10-29 03:05:44 +09:00
|
|
|
|
2023-04-01 16:27:23 +09:00
|
|
|
{!minimal && (
|
|
|
|
<div className='account__relationship'>
|
|
|
|
{buttons}
|
|
|
|
</div>
|
|
|
|
)}
|
2016-10-29 03:05:44 +09:00
|
|
|
</div>
|
2016-10-28 04:59:56 +09:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2023-03-24 11:17:53 +09:00
|
|
|
|
|
|
|
export default injectIntl(Account);
|