2017-05-03 09:04:16 +09:00
|
|
|
import React from 'react';
|
2016-10-28 04:59:56 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2016-11-21 03:39:18 +09:00
|
|
|
import Avatar from './avatar';
|
|
|
|
import DisplayName from './display_name';
|
2016-12-02 23:05:50 +09:00
|
|
|
import Permalink from './permalink';
|
2016-11-21 03:39:18 +09:00
|
|
|
import IconButton from './icon_button';
|
2016-11-18 23:36:16 +09:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-05-03 09:04:16 +09:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-10-31 11:27:48 +09:00
|
|
|
import { me } from '../initial_state';
|
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' },
|
|
|
|
requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
|
2017-04-27 19:03:28 +09:00
|
|
|
unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
|
2017-05-21 00:31:47 +09:00
|
|
|
unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
|
2016-11-18 23:36:16 +09:00
|
|
|
});
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2017-06-24 02:36:54 +09:00
|
|
|
@injectIntl
|
|
|
|
export default class Account extends ImmutablePureComponent {
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
|
|
onFollow: PropTypes.func.isRequired,
|
|
|
|
onBlock: PropTypes.func.isRequired,
|
|
|
|
onMute: 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,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
|
|
|
|
2017-05-25 00:55:16 +09:00
|
|
|
handleFollow = () => {
|
2016-10-29 03:05:44 +09:00
|
|
|
this.props.onFollow(this.props.account);
|
2017-04-22 03:05: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);
|
2017-04-22 03:05: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);
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-04-15 08:23:49 +09:00
|
|
|
|
2016-10-28 04:59:56 +09:00
|
|
|
render () {
|
2017-10-31 11:27:48 +09:00
|
|
|
const { account, intl, hidden } = this.props;
|
2016-10-28 04:59:56 +09:00
|
|
|
|
|
|
|
if (!account) {
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
|
2017-08-29 05:23:44 +09:00
|
|
|
if (hidden) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{account.get('display_name')}
|
|
|
|
{account.get('username')}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-09 09:20:09 +09:00
|
|
|
let buttons;
|
2016-10-29 03:05:44 +09:00
|
|
|
|
2017-01-17 03:36:32 +09:00
|
|
|
if (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) {
|
2017-06-06 20:20:07 +09:00
|
|
|
buttons = <IconButton disabled icon='hourglass' title={intl.formatMessage(messages.requested)} />;
|
2017-01-17 03:36:32 +09:00
|
|
|
} else if (blocking) {
|
2017-06-06 20:20:07 +09:00
|
|
|
buttons = <IconButton active icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.handleBlock} />;
|
2017-04-15 08:23:49 +09:00
|
|
|
} else if (muting) {
|
2017-06-06 20:20:07 +09:00
|
|
|
buttons = <IconButton active icon='volume-up' title={intl.formatMessage(messages.unmute, { name: account.get('username') })} onClick={this.handleMute} />;
|
2017-01-17 03:36:32 +09:00
|
|
|
} else {
|
|
|
|
buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
|
|
|
|
}
|
2016-10-28 04:59:56 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-02-09 09:20:09 +09:00
|
|
|
<div className='account'>
|
2017-04-23 11:26:55 +09:00
|
|
|
<div className='account__wrapper'>
|
2017-02-09 09:20:09 +09:00
|
|
|
<Permalink key={account.get('id')} className='account__display-name' href={account.get('url')} to={`/accounts/${account.get('id')}`}>
|
2017-08-08 02:44:55 +09:00
|
|
|
<div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
|
2016-10-29 03:05:44 +09:00
|
|
|
<DisplayName account={account} />
|
2016-12-02 23:05:50 +09:00
|
|
|
</Permalink>
|
2016-10-29 03:05:44 +09:00
|
|
|
|
2017-04-23 11:26:55 +09:00
|
|
|
<div className='account__relationship'>
|
2016-12-02 22:52:41 +09:00
|
|
|
{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
|
|
|
}
|