2017-09-20 17:57:08 +09:00
|
|
|
// Package imports.
|
2017-07-06 10:51:03 +09:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
|
2017-09-20 17:57:08 +09:00
|
|
|
// Mastodon imports.
|
2017-11-18 12:11:18 +09:00
|
|
|
import Avatar from './avatar';
|
|
|
|
import AvatarOverlay from './avatar_overlay';
|
2019-06-09 19:07:23 +09:00
|
|
|
import AvatarComposite from './avatar_composite';
|
2017-11-18 12:11:18 +09:00
|
|
|
import DisplayName from './display_name';
|
2017-07-06 10:51:03 +09:00
|
|
|
|
|
|
|
export default class StatusHeader extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2017-07-27 07:41:28 +09:00
|
|
|
status: ImmutablePropTypes.map.isRequired,
|
2017-07-06 10:51:03 +09:00
|
|
|
friend: ImmutablePropTypes.map,
|
|
|
|
parseClick: PropTypes.func.isRequired,
|
2019-06-09 19:07:23 +09:00
|
|
|
otherAccounts: ImmutablePropTypes.list,
|
2017-07-06 10:51:03 +09:00
|
|
|
};
|
|
|
|
|
2017-09-20 17:57:08 +09:00
|
|
|
// Handles clicks on account name/image
|
2019-06-09 19:07:23 +09:00
|
|
|
handleClick = (id, e) => {
|
|
|
|
const { parseClick } = this.props;
|
|
|
|
parseClick(e, `/accounts/${id}`);
|
|
|
|
}
|
|
|
|
|
2017-07-06 10:51:03 +09:00
|
|
|
handleAccountClick = (e) => {
|
2019-06-09 19:07:23 +09:00
|
|
|
const { status } = this.props;
|
|
|
|
this.handleClick(status.getIn(['account', 'id']), e);
|
2017-07-06 10:51:03 +09:00
|
|
|
}
|
|
|
|
|
2017-09-20 17:57:08 +09:00
|
|
|
// Rendering.
|
2017-07-06 10:51:03 +09:00
|
|
|
render () {
|
|
|
|
const {
|
2017-07-27 07:41:28 +09:00
|
|
|
status,
|
2017-07-06 10:51:03 +09:00
|
|
|
friend,
|
2019-06-09 19:07:23 +09:00
|
|
|
otherAccounts,
|
2017-07-06 10:51:03 +09:00
|
|
|
} = this.props;
|
|
|
|
|
2017-07-27 07:41:28 +09:00
|
|
|
const account = status.get('account');
|
2017-07-08 07:34:47 +09:00
|
|
|
|
2019-06-09 19:07:23 +09: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-25 05:44:42 +09:00
|
|
|
rel='noopener noreferrer'
|
2019-06-09 19:07:23 +09:00
|
|
|
>
|
|
|
|
{statusAvatar}
|
|
|
|
</a>
|
|
|
|
<a
|
|
|
|
href={account.get('url')}
|
|
|
|
target='_blank'
|
|
|
|
className='status__display-name'
|
|
|
|
onClick={this.handleAccountClick}
|
2019-10-25 05:44:42 +09:00
|
|
|
rel='noopener noreferrer'
|
2019-06-09 19:07:23 +09: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-06 10:51:03 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|