2017-04-22 04:05:35 +10:00
|
|
|
import PropTypes from 'prop-types';
|
2024-04-24 18:45:12 +10:00
|
|
|
import { useCallback } from 'react';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import classNames from 'classnames';
|
2022-11-14 07:10:20 +11:00
|
|
|
import { Link } from 'react-router-dom';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
import MoreHorizIcon from '@/material-icons/400-24px/more_horiz.svg?react';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { EmptyAccount } from 'mastodon/components/empty_account';
|
2023-07-08 19:11:58 +10:00
|
|
|
import { ShortNumber } from 'mastodon/components/short_number';
|
2023-05-09 11:11:56 +10:00
|
|
|
import { VerifiedBadge } from 'mastodon/components/verified_badge';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
import DropdownMenuContainer from '../containers/dropdown_menu_container';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { me } from '../initial_state';
|
|
|
|
|
|
|
|
import { Avatar } from './avatar';
|
2023-10-23 18:43:00 +11:00
|
|
|
import { Button } from './button';
|
2023-07-08 19:11:22 +10:00
|
|
|
import { FollowersCounter } from './counters';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { DisplayName } from './display_name';
|
|
|
|
import { RelativeTimestamp } from './relative_timestamp';
|
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' },
|
2023-06-06 12:14:28 +10: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 18:45:12 +10:00
|
|
|
more: { id: 'status.more', defaultMessage: 'More' },
|
2016-11-19 01:36:16 +11:00
|
|
|
});
|
2016-10-28 06:59:56 +11:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
const Account = ({ size = 46, account, onFollow, onBlock, onMute, onMuteNotifications, hidden, minimal, defaultAction, withBio }) => {
|
|
|
|
const intl = useIntl();
|
2016-10-28 06:59:56 +11:00
|
|
|
|
2024-04-24 18:45:12 +10: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 06:23:44 +10:00
|
|
|
|
2024-04-24 18:45:12 +10: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 05:36:32 +11:00
|
|
|
}
|
2016-10-28 06:59:56 +11:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
buttons = (
|
|
|
|
<>
|
|
|
|
<DropdownMenuContainer
|
|
|
|
items={menu}
|
|
|
|
icon='ellipsis-h'
|
|
|
|
iconComponent={MoreHorizIcon}
|
|
|
|
direction='right'
|
|
|
|
title={intl.formatMessage(messages.more)}
|
|
|
|
/>
|
2023-03-25 18:46:32 +11:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
<Button text={intl.formatMessage(messages.unmute)} onClick={handleMute} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else if (defaultAction === 'mute') {
|
2024-08-06 23:34:55 +10:00
|
|
|
buttons = <Button text={intl.formatMessage(messages.mute)} onClick={handleMute} />;
|
2024-04-24 18:45:12 +10:00
|
|
|
} 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 18:46:32 +11:00
|
|
|
}
|
2024-04-24 18:45:12 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
let muteTimeRemaining;
|
2023-03-25 18:46:32 +11:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
if (account.get('mute_expires_at')) {
|
|
|
|
muteTimeRemaining = <>· <RelativeTimestamp timestamp={account.get('mute_expires_at')} futureDate /></>;
|
|
|
|
}
|
2023-03-25 18:46:32 +11:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
let verification;
|
2023-03-25 18:46:32 +11:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
const firstVerifiedField = account.get('fields').find(item => !!item.get('verified_at'));
|
2020-10-13 10:01:14 +11:00
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
if (firstVerifiedField) {
|
|
|
|
verification = <VerifiedBadge link={firstVerifiedField.get('value')} />;
|
2016-10-28 06:59:56 +11:00
|
|
|
}
|
|
|
|
|
2024-04-24 18:45:12 +10:00
|
|
|
return (
|
|
|
|
<div className={classNames('account', { 'account--minimal': minimal })}>
|
|
|
|
<div className='account__wrapper'>
|
2024-07-08 02:13:10 +10:00
|
|
|
<Link key={account.get('id')} className='account__display-name' title={account.get('acct')} to={`/@${account.get('acct')}`} data-hover-card-account={account.get('id')}>
|
2024-04-24 18:45:12 +10:00
|
|
|
<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 13:17:53 +11:00
|
|
|
|
2024-04-24 18:45:12 +10: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;
|