2017-12-08 01:59:31 +11:00
|
|
|
import React, { Fragment } 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';
|
2017-10-31 13:27:48 +11:00
|
|
|
import { me } from '../initial_state';
|
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}' },
|
2016-11-19 01:36:16 +11:00
|
|
|
});
|
2016-10-28 06:59:56 +11:00
|
|
|
|
2017-06-24 03:36:54 +10:00
|
|
|
@injectIntl
|
|
|
|
export default class Account extends ImmutablePureComponent {
|
2016-10-28 06:59:56 +11:00
|
|
|
|
2017-05-12 22:44:10 +10:00
|
|
|
static propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
|
|
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,
|
2017-05-12 22:44:10 +10:00
|
|
|
};
|
|
|
|
|
2017-05-25 01:55:16 +10:00
|
|
|
handleFollow = () => {
|
2016-10-29 05:05:44 +11:00
|
|
|
this.props.onFollow(this.props.account);
|
2017-04-22 04:05:35 +10: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);
|
2017-04-22 04:05:35 +10: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);
|
2017-04-22 04:05:35 +10: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUnmuteNotifications = () => {
|
|
|
|
this.props.onMuteNotifications(this.props.account, false);
|
|
|
|
}
|
|
|
|
|
2016-10-28 06:59:56 +11:00
|
|
|
render () {
|
2017-10-31 13:27:48 +11:00
|
|
|
const { account, intl, hidden } = this.props;
|
2016-10-28 06:59:56 +11:00
|
|
|
|
|
|
|
if (!account) {
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
|
2017-08-29 06:23:44 +10:00
|
|
|
if (hidden) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{account.get('display_name')}
|
|
|
|
{account.get('username')}
|
|
|
|
</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) {
|
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) {
|
2017-06-06 21:20:07 +10:00
|
|
|
buttons = <IconButton active icon='unlock-alt' 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 = (
|
2017-12-08 01:59:31 +11:00
|
|
|
<Fragment>
|
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}
|
2017-12-08 01:59:31 +11:00
|
|
|
</Fragment>
|
2017-11-15 13:56:41 +11:00
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-08-08 03:44:55 +10:00
|
|
|
<div className='account__avatar-wrapper'><Avatar account={account} 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
|
|
|
}
|