2017-09-20 01:57:08 -07:00
|
|
|
// Package imports.
|
2017-07-05 18:51:03 -07:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
|
2017-09-20 01:57:08 -07:00
|
|
|
// Mastodon imports.
|
2017-11-17 19:11:18 -08:00
|
|
|
import Avatar from './avatar';
|
|
|
|
import AvatarOverlay from './avatar_overlay';
|
2019-06-09 03:07:23 -07:00
|
|
|
import AvatarComposite from './avatar_composite';
|
2017-11-17 19:11:18 -08:00
|
|
|
import DisplayName from './display_name';
|
2017-07-05 18:51:03 -07:00
|
|
|
|
|
|
|
export default class StatusHeader extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-07-26 15:41:28 -07:00
|
|
|
status: ImmutablePropTypes.map.isRequired,
|
2017-07-05 18:51:03 -07:00
|
|
|
friend: ImmutablePropTypes.map,
|
|
|
|
parseClick: PropTypes.func.isRequired,
|
2019-06-09 03:07:23 -07:00
|
|
|
otherAccounts: ImmutablePropTypes.list,
|
2017-07-05 18:51:03 -07:00
|
|
|
};
|
|
|
|
|
2017-09-20 01:57:08 -07:00
|
|
|
// Handles clicks on account name/image
|
2021-09-25 20:46:13 -07:00
|
|
|
handleClick = (acct, e) => {
|
2019-06-09 03:07:23 -07:00
|
|
|
const { parseClick } = this.props;
|
2021-09-25 20:46:13 -07:00
|
|
|
parseClick(e, `/@${acct}`);
|
2019-06-09 03:07:23 -07:00
|
|
|
}
|
|
|
|
|
2017-07-05 18:51:03 -07:00
|
|
|
handleAccountClick = (e) => {
|
2019-06-09 03:07:23 -07:00
|
|
|
const { status } = this.props;
|
2021-09-25 20:46:13 -07:00
|
|
|
this.handleClick(status.getIn(['account', 'acct']), e);
|
2017-07-05 18:51:03 -07:00
|
|
|
}
|
|
|
|
|
2017-09-20 01:57:08 -07:00
|
|
|
// Rendering.
|
2017-07-05 18:51:03 -07:00
|
|
|
render () {
|
|
|
|
const {
|
2017-07-26 15:41:28 -07:00
|
|
|
status,
|
2017-07-05 18:51:03 -07:00
|
|
|
friend,
|
2019-06-09 03:07:23 -07:00
|
|
|
otherAccounts,
|
2017-07-05 18:51:03 -07:00
|
|
|
} = this.props;
|
|
|
|
|
2017-07-26 15:41:28 -07:00
|
|
|
const account = status.get('account');
|
2017-07-07 15:34:47 -07:00
|
|
|
|
2019-06-09 03:07:23 -07:00
|
|
|
let statusAvatar;
|
|
|
|
if (otherAccounts && otherAccounts.size > 0) {
|
|
|
|
statusAvatar = <AvatarComposite accounts={otherAccounts} size={48} onAccountClick={this.handleClick} />;
|
|
|
|
} else if (friend === undefined || friend === null) {
|
|
|
|
statusAvatar = <Avatar account={account} size={48} />;
|
|
|
|
} else {
|
|
|
|
statusAvatar = <AvatarOverlay account={account} friend={friend} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!otherAccounts) {
|
|
|
|
return (
|
|
|
|
<div className='status__info__account'>
|
|
|
|
<a
|
|
|
|
href={account.get('url')}
|
|
|
|
target='_blank'
|
|
|
|
className='status__avatar'
|
|
|
|
onClick={this.handleAccountClick}
|
2019-10-24 13:44:42 -07:00
|
|
|
rel='noopener noreferrer'
|
2019-06-09 03:07:23 -07:00
|
|
|
>
|
|
|
|
{statusAvatar}
|
|
|
|
</a>
|
|
|
|
<a
|
|
|
|
href={account.get('url')}
|
|
|
|
target='_blank'
|
|
|
|
className='status__display-name'
|
|
|
|
onClick={this.handleAccountClick}
|
2019-10-24 13:44:42 -07:00
|
|
|
rel='noopener noreferrer'
|
2019-06-09 03:07:23 -07:00
|
|
|
>
|
|
|
|
<DisplayName account={account} others={otherAccounts} />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// This is a DM conversation
|
|
|
|
return (
|
|
|
|
<div className='status__info__account'>
|
|
|
|
<span className='status__avatar'>
|
|
|
|
{statusAvatar}
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span className='status__display-name'>
|
|
|
|
<DisplayName account={account} others={otherAccounts} onAccountClick={this.handleClick} />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-07-05 18:51:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|