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