1 import React
, { Fragment
} from 'react';
2 import ImmutablePropTypes
from 'react-immutable-proptypes';
3 import PropTypes
from 'prop-types';
4 import Avatar
from './avatar';
5 import DisplayName
from './display_name';
6 import Permalink
from './permalink';
7 import IconButton
from './icon_button';
8 import { defineMessages
, injectIntl
} from 'react-intl';
9 import ImmutablePureComponent
from 'react-immutable-pure-component';
10 import { me
} from '../initial_state';
11 import RelativeTimestamp
from './relative_timestamp';
13 const messages
= defineMessages({
14 follow: { id: 'account.follow', defaultMessage: 'Follow' },
15 unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
16 requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
17 unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
18 unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
19 mute_notifications: { id: 'account.mute_notifications', defaultMessage: 'Mute notifications from @{name}' },
20 unmute_notifications: { id: 'account.unmute_notifications', defaultMessage: 'Unmute notifications from @{name}' },
23 export default @injectIntl
24 class Account
extends ImmutablePureComponent
{
27 account: ImmutablePropTypes
.map
.isRequired
,
28 onFollow: PropTypes
.func
.isRequired
,
29 onBlock: PropTypes
.func
.isRequired
,
30 onMute: PropTypes
.func
.isRequired
,
31 onMuteNotifications: PropTypes
.func
.isRequired
,
32 intl: PropTypes
.object
.isRequired
,
33 hidden: PropTypes
.bool
,
34 actionIcon: PropTypes
.string
,
35 actionTitle: PropTypes
.string
,
36 onActionClick: PropTypes
.func
,
39 handleFollow
= () => {
40 this.props
.onFollow(this.props
.account
);
44 this.props
.onBlock(this.props
.account
);
48 this.props
.onMute(this.props
.account
);
51 handleMuteNotifications
= () => {
52 this.props
.onMuteNotifications(this.props
.account
, true);
55 handleUnmuteNotifications
= () => {
56 this.props
.onMuteNotifications(this.props
.account
, false);
59 handleAction
= () => {
60 this.props
.onActionClick(this.props
.account
);
64 const { account
, intl
, hidden
, onActionClick
, actionIcon
, actionTitle
} = this.props
;
73 {account
.get('display_name')}
74 {account
.get('username')}
83 buttons
= <IconButton icon
={actionIcon
} title
={actionTitle
} onClick
={this.handleAction
} />;
85 } else if (account
.get('id') !== me
&& account
.get('relationship', null) !== null) {
86 const following
= account
.getIn(['relationship', 'following']);
87 const requested
= account
.getIn(['relationship', 'requested']);
88 const blocking
= account
.getIn(['relationship', 'blocking']);
89 const muting
= account
.getIn(['relationship', 'muting']);
92 buttons
= <IconButton disabled icon
='hourglass' title
={intl
.formatMessage(messages
.requested
)} />;
93 } else if (blocking
) {
94 buttons
= <IconButton active icon
='unlock' title
={intl
.formatMessage(messages
.unblock
, { name: account
.get('username') })} onClick
={this.handleBlock
} />;
96 let hidingNotificationsButton
;
97 if (account
.getIn(['relationship', 'muting_notifications'])) {
98 hidingNotificationsButton
= <IconButton active icon
='bell' title
={intl
.formatMessage(messages
.unmute_notifications
, { name: account
.get('username') })} onClick
={this.handleUnmuteNotifications
} />;
100 hidingNotificationsButton
= <IconButton active icon
='bell-slash' title
={intl
.formatMessage(messages
.mute_notifications
, { name: account
.get('username') })} onClick
={this.handleMuteNotifications
} />;
104 <IconButton active icon
='volume-up' title
={intl
.formatMessage(messages
.unmute
, { name: account
.get('username') })} onClick
={this.handleMute
} />
105 {hidingNotificationsButton
}
108 } else if (!account
.get('moved') || following
) {
109 buttons
= <IconButton icon
={following
? 'user-times' : 'user-plus'} title
={intl
.formatMessage(following
? messages
.unfollow : messages
.follow
)} onClick
={this.handleFollow
} active
={following
} />;
114 if (account
.get('mute_expires_at')) {
115 mute_expires_at
= <div
><RelativeTimestamp timestamp
={account
.get('mute_expires_at')} futureDate
/></div>;
119 <div className
='account'>
120 <div className
='account__wrapper'>
121 <Permalink key
={account
.get('id')} className
='account__display-name' title
={account
.get('acct')} href
={account
.get('url')} to
={`/@${account.get('acct')}`}>
122 <div className
='account__avatar-wrapper'><Avatar account
={account
} size
={36} /></div>
124 <DisplayName account
={account
} />
127 <div className
='account__relationship'>