2019-08-29 22:14:36 +00:00
|
|
|
import React from 'react';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { makeGetAccount } from 'mastodon/selectors';
|
|
|
|
import Avatar from 'mastodon/components/avatar';
|
|
|
|
import DisplayName from 'mastodon/components/display_name';
|
|
|
|
import Permalink from 'mastodon/components/permalink';
|
|
|
|
import RelativeTimestamp from 'mastodon/components/relative_timestamp';
|
|
|
|
import IconButton from 'mastodon/components/icon_button';
|
|
|
|
import { FormattedMessage, injectIntl, defineMessages } from 'react-intl';
|
|
|
|
import { autoPlayGif, me, unfollowModal } from 'mastodon/initial_state';
|
2020-07-06 12:27:32 +00:00
|
|
|
import ShortNumber from 'mastodon/components/short_number';
|
|
|
|
import {
|
|
|
|
followAccount,
|
|
|
|
unfollowAccount,
|
|
|
|
blockAccount,
|
|
|
|
unblockAccount,
|
|
|
|
unmuteAccount,
|
|
|
|
} from 'mastodon/actions/accounts';
|
2019-08-29 22:14:36 +00:00
|
|
|
import { openModal } from 'mastodon/actions/modal';
|
|
|
|
import { initMuteModal } from 'mastodon/actions/mutes';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
follow: { id: 'account.follow', defaultMessage: 'Follow' },
|
|
|
|
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
|
|
|
|
requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
|
|
|
|
unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
|
|
|
|
unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
|
2020-07-06 12:27:32 +00:00
|
|
|
unfollowConfirm: {
|
|
|
|
id: 'confirmations.unfollow.confirm',
|
|
|
|
defaultMessage: 'Unfollow',
|
|
|
|
},
|
2019-08-29 22:14:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { id }) => ({
|
|
|
|
account: getAccount(state, id),
|
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch, { intl }) => ({
|
2020-07-06 12:27:32 +00:00
|
|
|
onFollow(account) {
|
|
|
|
if (
|
|
|
|
account.getIn(['relationship', 'following']) ||
|
|
|
|
account.getIn(['relationship', 'requested'])
|
|
|
|
) {
|
2019-08-29 22:14:36 +00:00
|
|
|
if (unfollowModal) {
|
2020-07-06 12:27:32 +00:00
|
|
|
dispatch(
|
|
|
|
openModal('CONFIRM', {
|
|
|
|
message: (
|
|
|
|
<FormattedMessage
|
|
|
|
id='confirmations.unfollow.message'
|
|
|
|
defaultMessage='Are you sure you want to unfollow {name}?'
|
|
|
|
values={{ name: <strong>@{account.get('acct')}</strong> }}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
confirm: intl.formatMessage(messages.unfollowConfirm),
|
|
|
|
onConfirm: () => dispatch(unfollowAccount(account.get('id'))),
|
|
|
|
}),
|
|
|
|
);
|
2019-08-29 22:14:36 +00:00
|
|
|
} else {
|
|
|
|
dispatch(unfollowAccount(account.get('id')));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dispatch(followAccount(account.get('id')));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-07-06 12:27:32 +00:00
|
|
|
onBlock(account) {
|
2019-08-29 22:14:36 +00:00
|
|
|
if (account.getIn(['relationship', 'blocking'])) {
|
|
|
|
dispatch(unblockAccount(account.get('id')));
|
|
|
|
} else {
|
|
|
|
dispatch(blockAccount(account.get('id')));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-07-06 12:27:32 +00:00
|
|
|
onMute(account) {
|
2019-08-29 22:14:36 +00:00
|
|
|
if (account.getIn(['relationship', 'muting'])) {
|
|
|
|
dispatch(unmuteAccount(account.get('id')));
|
|
|
|
} else {
|
|
|
|
dispatch(initMuteModal(account));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-06 12:27:32 +00:00
|
|
|
export default
|
|
|
|
@injectIntl
|
2019-08-29 22:14:36 +00:00
|
|
|
@connect(makeMapStateToProps, mapDispatchToProps)
|
|
|
|
class AccountCard extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onFollow: PropTypes.func.isRequired,
|
|
|
|
onBlock: PropTypes.func.isRequired,
|
|
|
|
onMute: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
handleMouseEnter = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
2019-09-01 18:04:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-09-01 18:04:35 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
2021-01-31 20:25:31 +00:00
|
|
|
emoji.src = emoji.getAttribute('data-original');
|
2019-09-01 18:04:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
handleMouseLeave = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-01 18:04:35 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-09-01 18:04:35 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
emoji.src = emoji.getAttribute('data-static');
|
|
|
|
}
|
|
|
|
}
|
2019-09-01 18:04:35 +00:00
|
|
|
|
2019-08-29 22:14:36 +00:00
|
|
|
handleFollow = () => {
|
|
|
|
this.props.onFollow(this.props.account);
|
2020-07-06 12:27:32 +00:00
|
|
|
};
|
2019-08-29 22:14:36 +00:00
|
|
|
|
|
|
|
handleBlock = () => {
|
|
|
|
this.props.onBlock(this.props.account);
|
2020-07-06 12:27:32 +00:00
|
|
|
};
|
2019-08-29 22:14:36 +00:00
|
|
|
|
|
|
|
handleMute = () => {
|
|
|
|
this.props.onMute(this.props.account);
|
2020-07-06 12:27:32 +00:00
|
|
|
};
|
2019-08-29 22:14:36 +00:00
|
|
|
|
2020-07-06 12:27:32 +00:00
|
|
|
render() {
|
2019-08-29 22:14:36 +00:00
|
|
|
const { account, intl } = this.props;
|
|
|
|
|
|
|
|
let buttons;
|
|
|
|
|
2020-07-06 12:27:32 +00:00
|
|
|
if (
|
|
|
|
account.get('id') !== me &&
|
|
|
|
account.get('relationship', null) !== null
|
|
|
|
) {
|
2019-08-29 22:14:36 +00:00
|
|
|
const following = account.getIn(['relationship', 'following']);
|
|
|
|
const requested = account.getIn(['relationship', 'requested']);
|
2020-07-06 12:27:32 +00:00
|
|
|
const blocking = account.getIn(['relationship', 'blocking']);
|
|
|
|
const muting = account.getIn(['relationship', 'muting']);
|
2019-08-29 22:14:36 +00:00
|
|
|
|
|
|
|
if (requested) {
|
2020-07-06 12:27:32 +00:00
|
|
|
buttons = (
|
|
|
|
<IconButton
|
|
|
|
disabled
|
|
|
|
icon='hourglass'
|
|
|
|
title={intl.formatMessage(messages.requested)}
|
|
|
|
/>
|
|
|
|
);
|
2019-08-29 22:14:36 +00:00
|
|
|
} else if (blocking) {
|
2020-07-06 12:27:32 +00:00
|
|
|
buttons = (
|
|
|
|
<IconButton
|
|
|
|
active
|
|
|
|
icon='unlock'
|
|
|
|
title={intl.formatMessage(messages.unblock, {
|
|
|
|
name: account.get('username'),
|
|
|
|
})}
|
|
|
|
onClick={this.handleBlock}
|
|
|
|
/>
|
|
|
|
);
|
2019-08-29 22:14:36 +00:00
|
|
|
} else if (muting) {
|
2020-07-06 12:27:32 +00:00
|
|
|
buttons = (
|
|
|
|
<IconButton
|
|
|
|
active
|
|
|
|
icon='volume-up'
|
|
|
|
title={intl.formatMessage(messages.unmute, {
|
|
|
|
name: account.get('username'),
|
|
|
|
})}
|
|
|
|
onClick={this.handleMute}
|
|
|
|
/>
|
|
|
|
);
|
2019-08-29 22:14:36 +00:00
|
|
|
} else if (!account.get('moved') || following) {
|
2020-07-06 12:27:32 +00:00
|
|
|
buttons = (
|
|
|
|
<IconButton
|
|
|
|
icon={following ? 'user-times' : 'user-plus'}
|
|
|
|
title={intl.formatMessage(
|
|
|
|
following ? messages.unfollow : messages.follow,
|
|
|
|
)}
|
|
|
|
onClick={this.handleFollow}
|
|
|
|
active={following}
|
|
|
|
/>
|
|
|
|
);
|
2019-08-29 22:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='directory__card'>
|
|
|
|
<div className='directory__card__img'>
|
2020-07-06 12:27:32 +00:00
|
|
|
<img
|
|
|
|
src={
|
|
|
|
autoPlayGif ? account.get('header') : account.get('header_static')
|
|
|
|
}
|
|
|
|
alt=''
|
|
|
|
/>
|
2019-08-29 22:14:36 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='directory__card__bar'>
|
2020-07-06 12:27:32 +00:00
|
|
|
<Permalink
|
|
|
|
className='directory__card__bar__name'
|
|
|
|
href={account.get('url')}
|
|
|
|
to={`/accounts/${account.get('id')}`}
|
|
|
|
>
|
2019-08-29 22:14:36 +00:00
|
|
|
<Avatar account={account} size={48} />
|
|
|
|
<DisplayName account={account} />
|
|
|
|
</Permalink>
|
|
|
|
|
|
|
|
<div className='directory__card__bar__relationship account__relationship'>
|
|
|
|
{buttons}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
<div className='directory__card__extra' onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
|
2020-07-06 12:27:32 +00:00
|
|
|
<div
|
2021-01-22 09:09:23 +00:00
|
|
|
className='account__header__content translate'
|
2020-07-06 12:27:32 +00:00
|
|
|
dangerouslySetInnerHTML={{ __html: account.get('note_emojified') }}
|
|
|
|
/>
|
2019-08-29 22:14:36 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='directory__card__extra'>
|
2020-07-06 12:27:32 +00:00
|
|
|
<div className='accounts-table__count'>
|
|
|
|
<ShortNumber value={account.get('statuses_count')} />
|
|
|
|
<small>
|
|
|
|
<FormattedMessage id='account.posts' defaultMessage='Toots' />
|
|
|
|
</small>
|
|
|
|
</div>
|
|
|
|
<div className='accounts-table__count'>
|
|
|
|
<ShortNumber value={account.get('followers_count')} />{' '}
|
|
|
|
<small>
|
|
|
|
<FormattedMessage
|
|
|
|
id='account.followers'
|
|
|
|
defaultMessage='Followers'
|
|
|
|
/>
|
|
|
|
</small>
|
|
|
|
</div>
|
|
|
|
<div className='accounts-table__count'>
|
|
|
|
{account.get('last_status_at') === null ? (
|
|
|
|
<FormattedMessage
|
|
|
|
id='account.never_active'
|
|
|
|
defaultMessage='Never'
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<RelativeTimestamp timestamp={account.get('last_status_at')} />
|
|
|
|
)}{' '}
|
|
|
|
<small>
|
|
|
|
<FormattedMessage
|
|
|
|
id='account.last_status'
|
|
|
|
defaultMessage='Last active'
|
|
|
|
/>
|
|
|
|
</small>
|
|
|
|
</div>
|
2019-08-29 22:14:36 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|