2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2024-04-24 17:45:12 +09:00
|
|
|
import { useCallback } from 'react';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
|
|
|
import classNames from 'classnames';
|
2022-11-14 05:10:20 +09:00
|
|
|
import { Link } from 'react-router-dom';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
import MoreHorizIcon from '@/material-icons/400-24px/more_horiz.svg?react';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { EmptyAccount } from 'mastodon/components/empty_account';
|
2023-07-08 18:11:58 +09:00
|
|
|
import { ShortNumber } from 'mastodon/components/short_number';
|
2023-05-09 10:11:56 +09:00
|
|
|
import { VerifiedBadge } from 'mastodon/components/verified_badge';
|
2023-05-24 00:15:17 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
import DropdownMenuContainer from '../containers/dropdown_menu_container';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { me } from '../initial_state';
|
|
|
|
|
|
|
|
import { Avatar } from './avatar';
|
2023-10-23 16:43:00 +09:00
|
|
|
import { Button } from './button';
|
2023-07-08 18:11:22 +09:00
|
|
|
import { FollowersCounter } from './counters';
|
2023-05-24 00:15:17 +09:00
|
|
|
import { DisplayName } from './display_name';
|
|
|
|
import { RelativeTimestamp } from './relative_timestamp';
|
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-06-06 11:14:28 +09:00
|
|
|
cancel_follow_request: { id: 'account.cancel_follow_request', defaultMessage: 'Withdraw follow request' },
|
|
|
|
unblock: { id: 'account.unblock_short', defaultMessage: 'Unblock' },
|
|
|
|
unmute: { id: 'account.unmute_short', defaultMessage: 'Unmute' },
|
|
|
|
mute_notifications: { id: 'account.mute_notifications_short', defaultMessage: 'Mute notifications' },
|
|
|
|
unmute_notifications: { id: 'account.unmute_notifications_short', defaultMessage: 'Unmute notifications' },
|
|
|
|
mute: { id: 'account.mute_short', defaultMessage: 'Mute' },
|
|
|
|
block: { id: 'account.block_short', defaultMessage: 'Block' },
|
2024-04-24 17:45:12 +09:00
|
|
|
more: { id: 'status.more', defaultMessage: 'More' },
|
2016-11-18 23:36:16 +09:00
|
|
|
});
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
const Account = ({ size = 46, account, onFollow, onBlock, onMute, onMuteNotifications, hidden, minimal, defaultAction, withBio }) => {
|
|
|
|
const intl = useIntl();
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
const handleFollow = useCallback(() => {
|
|
|
|
onFollow(account);
|
|
|
|
}, [onFollow, account]);
|
|
|
|
|
|
|
|
const handleBlock = useCallback(() => {
|
|
|
|
onBlock(account);
|
|
|
|
}, [onBlock, account]);
|
|
|
|
|
|
|
|
const handleMute = useCallback(() => {
|
|
|
|
onMute(account);
|
|
|
|
}, [onMute, account]);
|
|
|
|
|
|
|
|
const handleMuteNotifications = useCallback(() => {
|
|
|
|
onMuteNotifications(account, true);
|
|
|
|
}, [onMuteNotifications, account]);
|
|
|
|
|
|
|
|
const handleUnmuteNotifications = useCallback(() => {
|
|
|
|
onMuteNotifications(account, false);
|
|
|
|
}, [onMuteNotifications, account]);
|
|
|
|
|
|
|
|
if (!account) {
|
|
|
|
return <EmptyAccount size={size} minimal={minimal} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hidden) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{account.get('display_name')}
|
|
|
|
{account.get('username')}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2017-08-29 05:23:44 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
let buttons;
|
|
|
|
|
|
|
|
if (account.get('id') !== me && account.get('relationship', null) !== null) {
|
|
|
|
const following = account.getIn(['relationship', 'following']);
|
|
|
|
const requested = account.getIn(['relationship', 'requested']);
|
|
|
|
const blocking = account.getIn(['relationship', 'blocking']);
|
|
|
|
const muting = account.getIn(['relationship', 'muting']);
|
|
|
|
|
|
|
|
if (requested) {
|
|
|
|
buttons = <Button text={intl.formatMessage(messages.cancel_follow_request)} onClick={handleFollow} />;
|
|
|
|
} else if (blocking) {
|
|
|
|
buttons = <Button text={intl.formatMessage(messages.unblock)} onClick={handleBlock} />;
|
|
|
|
} else if (muting) {
|
|
|
|
let menu;
|
|
|
|
|
|
|
|
if (account.getIn(['relationship', 'muting_notifications'])) {
|
|
|
|
menu = [{ text: intl.formatMessage(messages.unmute_notifications), action: handleUnmuteNotifications }];
|
|
|
|
} else {
|
|
|
|
menu = [{ text: intl.formatMessage(messages.mute_notifications), action: handleMuteNotifications }];
|
2017-01-17 03:36:32 +09:00
|
|
|
}
|
2016-10-28 04:59:56 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
buttons = (
|
|
|
|
<>
|
|
|
|
<DropdownMenuContainer
|
|
|
|
items={menu}
|
|
|
|
icon='ellipsis-h'
|
|
|
|
iconComponent={MoreHorizIcon}
|
|
|
|
direction='right'
|
|
|
|
title={intl.formatMessage(messages.more)}
|
|
|
|
/>
|
2023-03-25 16:46:32 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
<Button text={intl.formatMessage(messages.unmute)} onClick={handleMute} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else if (defaultAction === 'mute') {
|
|
|
|
buttons = <Button title={intl.formatMessage(messages.mute)} onClick={handleMute} />;
|
|
|
|
} else if (defaultAction === 'block') {
|
|
|
|
buttons = <Button text={intl.formatMessage(messages.block)} onClick={handleBlock} />;
|
|
|
|
} else if (!account.get('suspended') && !account.get('moved') || following) {
|
|
|
|
buttons = <Button text={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={handleFollow} />;
|
2023-03-25 16:46:32 +09:00
|
|
|
}
|
2024-04-24 17:45:12 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
let muteTimeRemaining;
|
2023-03-25 16:46:32 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
if (account.get('mute_expires_at')) {
|
|
|
|
muteTimeRemaining = <>· <RelativeTimestamp timestamp={account.get('mute_expires_at')} futureDate /></>;
|
|
|
|
}
|
2023-03-25 16:46:32 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
let verification;
|
2023-03-25 16:46:32 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
const firstVerifiedField = account.get('fields').find(item => !!item.get('verified_at'));
|
2020-10-13 08:01:14 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
if (firstVerifiedField) {
|
|
|
|
verification = <VerifiedBadge link={firstVerifiedField.get('value')} />;
|
2016-10-28 04:59:56 +09:00
|
|
|
}
|
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
return (
|
|
|
|
<div className={classNames('account', { 'account--minimal': minimal })}>
|
|
|
|
<div className='account__wrapper'>
|
|
|
|
<Link key={account.get('id')} className='account__display-name' title={account.get('acct')} to={`/@${account.get('acct')}`}>
|
|
|
|
<div className='account__avatar-wrapper'>
|
|
|
|
<Avatar account={account} size={size} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='account__contents'>
|
|
|
|
<DisplayName account={account} />
|
|
|
|
{!minimal && (
|
|
|
|
<div className='account__details'>
|
|
|
|
<ShortNumber value={account.get('followers_count')} renderer={FollowersCounter} /> {verification} {muteTimeRemaining}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
{!minimal && (
|
|
|
|
<div className='account__relationship'>
|
|
|
|
{buttons}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-03-24 11:17:53 +09:00
|
|
|
|
2024-04-24 17:45:12 +09:00
|
|
|
{withBio && (account.get('note').length > 0 ? (
|
|
|
|
<div
|
|
|
|
className='account__note translate'
|
|
|
|
dangerouslySetInnerHTML={{ __html: account.get('note_emojified') }}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className='account__note account__note--missing'><FormattedMessage id='account.no_bio' defaultMessage='No description provided.' /></div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Account.propTypes = {
|
|
|
|
size: PropTypes.number,
|
|
|
|
account: ImmutablePropTypes.record,
|
|
|
|
onFollow: PropTypes.func,
|
|
|
|
onBlock: PropTypes.func,
|
|
|
|
onMute: PropTypes.func,
|
|
|
|
onMuteNotifications: PropTypes.func,
|
|
|
|
hidden: PropTypes.bool,
|
|
|
|
minimal: PropTypes.bool,
|
|
|
|
defaultAction: PropTypes.string,
|
|
|
|
withBio: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Account;
|