2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
2016-11-18 23:36:16 +09:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-05-03 09:04:16 +09:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
|
|
|
import { Skeleton } from 'flavours/glitch/components/skeleton';
|
2022-10-11 17:17:04 +09:00
|
|
|
import { me } from 'flavours/glitch/initial_state';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
|
|
|
import { Avatar } from './avatar';
|
|
|
|
import { DisplayName } from './display_name';
|
|
|
|
import { IconButton } from './icon_button';
|
|
|
|
import Permalink from './permalink';
|
2023-05-09 10:11:56 +09:00
|
|
|
import { RelativeTimestamp } from './relative_timestamp';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
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' },
|
2023-05-24 19:38:50 +09:00
|
|
|
requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' },
|
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}' },
|
2022-05-10 06:20:19 +09:00
|
|
|
mute_notifications: { id: 'account.mute_notifications', defaultMessage: 'Mute notifications from @{name}' },
|
|
|
|
unmute_notifications: { id: 'account.unmute_notifications', defaultMessage: 'Unmute notifications from @{name}' },
|
|
|
|
mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
|
|
|
|
block: { id: 'account.block', defaultMessage: 'Block @{name}' },
|
2016-11-18 23:36:16 +09:00
|
|
|
});
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2019-09-09 22:16:08 +09:00
|
|
|
class Account extends ImmutablePureComponent {
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
2022-10-31 21:06:17 +09:00
|
|
|
size: PropTypes.number,
|
2022-10-05 10:47:56 +09:00
|
|
|
account: ImmutablePropTypes.map,
|
2017-05-12 21:44:10 +09:00
|
|
|
onFollow: PropTypes.func.isRequired,
|
|
|
|
onBlock: PropTypes.func.isRequired,
|
|
|
|
onMute: PropTypes.func.isRequired,
|
2017-12-27 04:25:43 +09:00
|
|
|
onMuteNotifications: 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-12-24 15:16:45 +09:00
|
|
|
small: PropTypes.bool,
|
2018-10-23 07:08:39 +09:00
|
|
|
actionIcon: PropTypes.string,
|
|
|
|
actionTitle: PropTypes.string,
|
2022-05-10 06:20:19 +09:00
|
|
|
defaultAction: PropTypes.string,
|
2018-10-23 07:08:39 +09:00
|
|
|
onActionClick: PropTypes.func,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
|
|
|
|
2022-10-31 21:06:17 +09:00
|
|
|
static defaultProps = {
|
|
|
|
size: 36,
|
|
|
|
};
|
|
|
|
|
2017-05-25 00:55:16 +09:00
|
|
|
handleFollow = () => {
|
2016-10-29 03:05:44 +09:00
|
|
|
this.props.onFollow(this.props.account);
|
2023-02-04 04:52:07 +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);
|
2023-02-04 04:52:07 +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);
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-04-15 08:23:49 +09:00
|
|
|
|
2017-11-15 11:56:41 +09:00
|
|
|
handleMuteNotifications = () => {
|
|
|
|
this.props.onMuteNotifications(this.props.account, true);
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-11-15 11:56:41 +09:00
|
|
|
|
|
|
|
handleUnmuteNotifications = () => {
|
|
|
|
this.props.onMuteNotifications(this.props.account, false);
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-11-15 11:56:41 +09:00
|
|
|
|
2018-10-23 07:08:39 +09:00
|
|
|
handleAction = () => {
|
|
|
|
this.props.onActionClick(this.props.account);
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2018-10-23 07:08:39 +09:00
|
|
|
|
2016-10-28 04:59:56 +09:00
|
|
|
render () {
|
2017-12-24 15:16:45 +09:00
|
|
|
const {
|
|
|
|
account,
|
|
|
|
hidden,
|
|
|
|
intl,
|
|
|
|
small,
|
2018-10-23 07:08:39 +09:00
|
|
|
onActionClick,
|
|
|
|
actionIcon,
|
|
|
|
actionTitle,
|
2022-05-10 06:20:19 +09:00
|
|
|
defaultAction,
|
2022-10-31 21:06:17 +09:00
|
|
|
size,
|
2017-12-24 15:16:45 +09:00
|
|
|
} = this.props;
|
2016-10-28 04:59:56 +09:00
|
|
|
|
|
|
|
if (!account) {
|
2022-10-05 10:47:56 +09:00
|
|
|
return (
|
|
|
|
<div className='account'>
|
|
|
|
<div className='account__wrapper'>
|
|
|
|
<div className='account__display-name'>
|
|
|
|
<div className='account__avatar-wrapper'><Skeleton width={36} height={36} /></div>
|
|
|
|
<DisplayName />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2016-10-28 04:59:56 +09:00
|
|
|
}
|
|
|
|
|
2017-08-29 05:23:44 +09:00
|
|
|
if (hidden) {
|
|
|
|
return (
|
2023-05-28 21:56:24 +09:00
|
|
|
<>
|
2017-08-29 05:23:44 +09:00
|
|
|
{account.get('display_name')}
|
|
|
|
{account.get('username')}
|
2023-05-28 21:56:24 +09:00
|
|
|
</>
|
2017-08-29 05:23:44 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-09 09:20:09 +09:00
|
|
|
let buttons;
|
2016-10-29 03:05:44 +09:00
|
|
|
|
2021-04-16 17:06:42 +09:00
|
|
|
if (onActionClick) {
|
|
|
|
if (actionIcon) {
|
|
|
|
buttons = <IconButton icon={actionIcon} title={actionTitle} onClick={this.handleAction} />;
|
|
|
|
}
|
2018-10-23 07:08:39 +09:00
|
|
|
} else if (account.get('id') !== me && !small && 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) {
|
2019-02-02 00:15:44 +09:00
|
|
|
buttons = <IconButton active icon='unlock' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.handleBlock} />;
|
2017-04-15 08:23:49 +09:00
|
|
|
} else if (muting) {
|
2017-11-15 11:56:41 +09:00
|
|
|
let hidingNotificationsButton;
|
2017-12-07 09:23:28 +09:00
|
|
|
if (account.getIn(['relationship', 'muting_notifications'])) {
|
2017-11-15 11:56:41 +09: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 = (
|
2023-05-28 21:56:24 +09:00
|
|
|
<>
|
2017-11-15 11:56:41 +09:00
|
|
|
<IconButton active icon='volume-up' title={intl.formatMessage(messages.unmute, { name: account.get('username') })} onClick={this.handleMute} />
|
|
|
|
{hidingNotificationsButton}
|
2023-05-28 21:56:24 +09:00
|
|
|
</>
|
2017-11-15 11:56:41 +09:00
|
|
|
);
|
2022-05-10 06:20:19 +09:00
|
|
|
} else if (defaultAction === 'mute') {
|
|
|
|
buttons = <IconButton icon='volume-off' title={intl.formatMessage(messages.mute, { name: account.get('username') })} onClick={this.handleMute} />;
|
|
|
|
} else if (defaultAction === 'block') {
|
|
|
|
buttons = <IconButton icon='lock' title={intl.formatMessage(messages.block, { name: account.get('username') })} onClick={this.handleBlock} />;
|
2018-03-29 21:46:00 +09:00
|
|
|
} else if (!account.get('moved') || following) {
|
2017-12-07 09:23:28 +09: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 03:36:32 +09:00
|
|
|
}
|
2016-10-28 04:59:56 +09:00
|
|
|
}
|
|
|
|
|
2020-10-13 08:01:14 +09:00
|
|
|
let mute_expires_at;
|
|
|
|
if (account.get('mute_expires_at')) {
|
|
|
|
mute_expires_at = <div><RelativeTimestamp timestamp={account.get('mute_expires_at')} futureDate /></div>;
|
|
|
|
}
|
|
|
|
|
2017-12-24 15:16:45 +09:00
|
|
|
return small ? (
|
2018-01-06 13:04:13 +09:00
|
|
|
<Permalink
|
|
|
|
className='account small'
|
|
|
|
href={account.get('url')}
|
2021-09-26 12:46:13 +09:00
|
|
|
to={`/@${account.get('acct')}`}
|
2018-01-06 13:04:13 +09:00
|
|
|
>
|
|
|
|
<div className='account__avatar-wrapper'>
|
|
|
|
<Avatar
|
|
|
|
account={account}
|
|
|
|
size={24}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<DisplayName
|
|
|
|
account={account}
|
|
|
|
inline
|
|
|
|
/>
|
|
|
|
</Permalink>
|
2017-12-24 15:16:45 +09:00
|
|
|
) : (
|
2017-02-09 09:20:09 +09:00
|
|
|
<div className='account'>
|
2017-04-23 11:26:55 +09:00
|
|
|
<div className='account__wrapper'>
|
2021-09-26 12:46:13 +09:00
|
|
|
<Permalink key={account.get('id')} className='account__display-name' title={account.get('acct')} href={account.get('url')} to={`/@${account.get('acct')}`}>
|
2022-10-31 21:06:17 +09:00
|
|
|
<div className='account__avatar-wrapper'><Avatar account={account} size={size} /></div>
|
2020-10-13 08:01:14 +09:00
|
|
|
{mute_expires_at}
|
2016-10-29 03:05:44 +09:00
|
|
|
<DisplayName account={account} />
|
2016-12-02 23:05:50 +09:00
|
|
|
</Permalink>
|
2017-12-24 15:16:45 +09:00
|
|
|
{buttons ?
|
|
|
|
<div className='account__relationship'>
|
|
|
|
{buttons}
|
|
|
|
</div>
|
2018-01-19 00:13:07 +09:00
|
|
|
: null}
|
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
|
|
|
}
|
2023-03-25 07:15:25 +09:00
|
|
|
|
|
|
|
export default injectIntl(Account);
|