2017-04-21 21:05:35 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2023-06-23 17:34:27 +03:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2023-12-02 17:27:12 +02:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2023-05-28 17:38:10 +03:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-05-03 03:04:16 +03:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2023-12-02 17:27:12 +02:00
|
|
|
import { EmptyAccount } from 'flavours/glitch/components/empty_account';
|
2023-07-08 12:11:22 +03:00
|
|
|
import { ShortNumber } from 'flavours/glitch/components/short_number';
|
2023-05-09 04:11:56 +03:00
|
|
|
import { VerifiedBadge } from 'flavours/glitch/components/verified_badge';
|
2023-11-15 23:44:47 +02:00
|
|
|
|
|
|
|
import { me } from '../initial_state';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
|
|
|
import { Avatar } from './avatar';
|
2023-07-08 12:11:22 +03:00
|
|
|
import { Button } from './button';
|
|
|
|
import { FollowersCounter } from './counters';
|
2023-05-28 17:38:10 +03:00
|
|
|
import { DisplayName } from './display_name';
|
|
|
|
import { IconButton } from './icon_button';
|
|
|
|
import Permalink from './permalink';
|
2023-05-09 04:11:56 +03:00
|
|
|
import { RelativeTimestamp } from './relative_timestamp';
|
2023-05-28 17:38:10 +03:00
|
|
|
|
2016-11-18 16:36:16 +02:00
|
|
|
const messages = defineMessages({
|
2016-12-12 00:13:05 +02:00
|
|
|
follow: { id: 'account.follow', defaultMessage: 'Follow' },
|
2017-01-16 20:36:32 +02:00
|
|
|
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
|
2023-06-06 05:14:28 +03: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' },
|
2016-11-18 16:36:16 +02:00
|
|
|
});
|
2016-10-27 22:59:56 +03:00
|
|
|
|
2019-09-09 16:16:08 +03:00
|
|
|
class Account extends ImmutablePureComponent {
|
2016-10-27 22:59:56 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
static propTypes = {
|
2022-10-31 14:06:17 +02:00
|
|
|
size: PropTypes.number,
|
2022-10-05 04:47:56 +03:00
|
|
|
account: ImmutablePropTypes.map,
|
2017-05-12 15:44:10 +03:00
|
|
|
onFollow: PropTypes.func.isRequired,
|
|
|
|
onBlock: PropTypes.func.isRequired,
|
|
|
|
onMute: PropTypes.func.isRequired,
|
2017-12-26 21:25:43 +02:00
|
|
|
onMuteNotifications: PropTypes.func.isRequired,
|
2017-05-20 18:31:47 +03:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-08-28 23:23:44 +03:00
|
|
|
hidden: PropTypes.bool,
|
2023-04-01 10:27:23 +03:00
|
|
|
minimal: PropTypes.bool,
|
2018-10-23 01:08:39 +03:00
|
|
|
actionIcon: PropTypes.string,
|
|
|
|
actionTitle: PropTypes.string,
|
2022-05-10 00:20:19 +03:00
|
|
|
defaultAction: PropTypes.string,
|
2018-10-23 01:08:39 +03:00
|
|
|
onActionClick: PropTypes.func,
|
2023-06-23 17:34:27 +03:00
|
|
|
withBio: PropTypes.bool,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
|
|
|
|
2022-10-31 14:06:17 +02:00
|
|
|
static defaultProps = {
|
2023-12-02 18:05:54 +02:00
|
|
|
size: 46,
|
2022-10-31 14:06:17 +02:00
|
|
|
};
|
|
|
|
|
2017-05-24 18:55:16 +03:00
|
|
|
handleFollow = () => {
|
2016-10-28 21:05:44 +03:00
|
|
|
this.props.onFollow(this.props.account);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2016-10-28 21:05:44 +03:00
|
|
|
|
2017-05-24 18:55:16 +03:00
|
|
|
handleBlock = () => {
|
2017-01-16 20:36:32 +02:00
|
|
|
this.props.onBlock(this.props.account);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-01-16 20:36:32 +02:00
|
|
|
|
2017-05-24 18:55:16 +03:00
|
|
|
handleMute = () => {
|
2017-04-15 02:23:49 +03:00
|
|
|
this.props.onMute(this.props.account);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-04-15 02:23:49 +03:00
|
|
|
|
2017-11-15 04:56:41 +02:00
|
|
|
handleMuteNotifications = () => {
|
|
|
|
this.props.onMuteNotifications(this.props.account, true);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-11-15 04:56:41 +02:00
|
|
|
|
|
|
|
handleUnmuteNotifications = () => {
|
|
|
|
this.props.onMuteNotifications(this.props.account, false);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2017-11-15 04:56:41 +02:00
|
|
|
|
2018-10-23 01:08:39 +03:00
|
|
|
handleAction = () => {
|
|
|
|
this.props.onActionClick(this.props.account);
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2018-10-23 01:08:39 +03:00
|
|
|
|
2016-10-27 22:59:56 +03:00
|
|
|
render () {
|
2023-06-23 17:34:27 +03:00
|
|
|
const { account, intl, hidden, withBio, onActionClick, actionIcon, actionTitle, defaultAction, size, minimal } = this.props;
|
2016-10-27 22:59:56 +03:00
|
|
|
|
|
|
|
if (!account) {
|
2023-05-11 08:55:10 +03:00
|
|
|
return <EmptyAccount size={size} minimal={minimal} />;
|
2016-10-27 22:59:56 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 23:23:44 +03:00
|
|
|
if (hidden) {
|
|
|
|
return (
|
2023-05-28 15:56:24 +03:00
|
|
|
<>
|
2017-08-28 23:23:44 +03:00
|
|
|
{account.get('display_name')}
|
|
|
|
{account.get('username')}
|
2023-05-28 15:56:24 +03:00
|
|
|
</>
|
2017-08-28 23:23:44 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-09 02:20:09 +02:00
|
|
|
let buttons;
|
2016-10-28 21:05:44 +03:00
|
|
|
|
2023-06-06 05:14:28 +03:00
|
|
|
if (actionIcon && onActionClick) {
|
|
|
|
buttons = <IconButton icon={actionIcon} title={actionTitle} onClick={this.handleAction} />;
|
|
|
|
} else if (!actionIcon && account.get('id') !== me && account.get('relationship', null) !== null) {
|
2016-11-01 19:03:51 +02:00
|
|
|
const following = account.getIn(['relationship', 'following']);
|
2017-01-16 20:36:32 +02:00
|
|
|
const requested = account.getIn(['relationship', 'requested']);
|
|
|
|
const blocking = account.getIn(['relationship', 'blocking']);
|
2017-04-15 02:23:49 +03:00
|
|
|
const muting = account.getIn(['relationship', 'muting']);
|
2017-01-16 20:36:32 +02:00
|
|
|
|
|
|
|
if (requested) {
|
2023-06-06 05:14:28 +03:00
|
|
|
buttons = <Button text={intl.formatMessage(messages.cancel_follow_request)} onClick={this.handleFollow} />;
|
2017-01-16 20:36:32 +02:00
|
|
|
} else if (blocking) {
|
2023-06-06 05:14:28 +03:00
|
|
|
buttons = <Button text={intl.formatMessage(messages.unblock)} onClick={this.handleBlock} />;
|
2017-04-15 02:23:49 +03:00
|
|
|
} else if (muting) {
|
2017-11-15 04:56:41 +02:00
|
|
|
let hidingNotificationsButton;
|
2023-06-06 05:14:28 +03:00
|
|
|
|
2017-12-07 02:23:28 +02:00
|
|
|
if (account.getIn(['relationship', 'muting_notifications'])) {
|
2023-06-06 05:14:28 +03:00
|
|
|
hidingNotificationsButton = <Button text={intl.formatMessage(messages.unmute_notifications)} onClick={this.handleUnmuteNotifications} />;
|
2017-11-15 04:56:41 +02:00
|
|
|
} else {
|
2023-06-06 05:14:28 +03:00
|
|
|
hidingNotificationsButton = <Button text={intl.formatMessage(messages.mute_notifications)} onClick={this.handleMuteNotifications} />;
|
2017-11-15 04:56:41 +02:00
|
|
|
}
|
2023-06-06 05:14:28 +03:00
|
|
|
|
2017-11-15 04:56:41 +02:00
|
|
|
buttons = (
|
2023-05-28 15:56:24 +03:00
|
|
|
<>
|
2023-06-06 05:14:28 +03:00
|
|
|
<Button text={intl.formatMessage(messages.unmute)} onClick={this.handleMute} />
|
2017-11-15 04:56:41 +02:00
|
|
|
{hidingNotificationsButton}
|
2023-05-28 15:56:24 +03:00
|
|
|
</>
|
2017-11-15 04:56:41 +02:00
|
|
|
);
|
2022-05-10 00:20:19 +03:00
|
|
|
} else if (defaultAction === 'mute') {
|
2023-06-06 05:14:28 +03:00
|
|
|
buttons = <Button title={intl.formatMessage(messages.mute)} onClick={this.handleMute} />;
|
2022-05-10 00:20:19 +03:00
|
|
|
} else if (defaultAction === 'block') {
|
2023-06-06 05:14:28 +03:00
|
|
|
buttons = <Button text={intl.formatMessage(messages.block)} onClick={this.handleBlock} />;
|
2018-03-29 15:46:00 +03:00
|
|
|
} else if (!account.get('moved') || following) {
|
2023-06-06 05:14:28 +03:00
|
|
|
buttons = <Button text={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} />;
|
2017-01-16 20:36:32 +02:00
|
|
|
}
|
2016-10-27 22:59:56 +03:00
|
|
|
}
|
|
|
|
|
2023-03-25 09:46:32 +02:00
|
|
|
let muteTimeRemaining;
|
|
|
|
|
2020-10-13 02:01:14 +03:00
|
|
|
if (account.get('mute_expires_at')) {
|
2023-03-25 09:46:32 +02:00
|
|
|
muteTimeRemaining = <>· <RelativeTimestamp timestamp={account.get('mute_expires_at')} futureDate /></>;
|
|
|
|
}
|
|
|
|
|
|
|
|
let verification;
|
|
|
|
|
|
|
|
const firstVerifiedField = account.get('fields').find(item => !!item.get('verified_at'));
|
|
|
|
|
|
|
|
if (firstVerifiedField) {
|
2023-06-01 15:47:55 +03:00
|
|
|
verification = <VerifiedBadge link={firstVerifiedField.get('value')} />;
|
2020-10-13 02:01:14 +03:00
|
|
|
}
|
|
|
|
|
2023-11-19 23:04:48 +02:00
|
|
|
return (
|
2023-04-01 10:27:23 +03:00
|
|
|
<div className={classNames('account', { 'account--minimal': minimal })}>
|
2017-04-23 05:26:55 +03:00
|
|
|
<div className='account__wrapper'>
|
2021-09-26 06:46:13 +03:00
|
|
|
<Permalink key={account.get('id')} className='account__display-name' title={account.get('acct')} href={account.get('url')} to={`/@${account.get('acct')}`}>
|
2023-03-25 09:46:32 +02:00
|
|
|
<div className='account__avatar-wrapper'>
|
|
|
|
<Avatar account={account} size={size} />
|
|
|
|
</div>
|
|
|
|
|
2023-06-01 15:47:55 +03:00
|
|
|
<div className='account__contents'>
|
2023-12-02 18:05:54 +02:00
|
|
|
<DisplayName account={account} inline />
|
2023-06-01 15:47:55 +03:00
|
|
|
{!minimal && (
|
|
|
|
<div className='account__details'>
|
2023-12-02 18:16:21 +02:00
|
|
|
{account.get('followers_count') !== -1 && (
|
|
|
|
<ShortNumber value={account.get('followers_count')} renderer={FollowersCounter} />
|
|
|
|
)} {verification} {muteTimeRemaining}
|
2023-06-01 15:47:55 +03:00
|
|
|
</div>
|
|
|
|
)}
|
2017-12-24 08:16:45 +02:00
|
|
|
</div>
|
2023-03-25 09:46:32 +02:00
|
|
|
</Permalink>
|
|
|
|
|
2023-04-01 10:27:23 +03:00
|
|
|
{!minimal && (
|
|
|
|
<div className='account__relationship'>
|
|
|
|
{buttons}
|
|
|
|
</div>
|
|
|
|
)}
|
2016-10-28 21:05:44 +03:00
|
|
|
</div>
|
2023-06-23 17:34:27 +03: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>
|
|
|
|
))}
|
2016-10-27 22:59:56 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 21:05:35 +03:00
|
|
|
}
|
2023-03-25 00:15:25 +02:00
|
|
|
|
|
|
|
export default injectIntl(Account);
|