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