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