2017-05-03 03:04:16 +03:00
|
|
|
import React from 'react';
|
2016-09-01 15:12:11 +03:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2019-07-23 11:45:35 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classNames from 'classnames';
|
2022-10-11 11:17:04 +03:00
|
|
|
import { autoPlayGif } from 'flavours/glitch/initial_state';
|
2022-10-05 04:47:56 +03:00
|
|
|
import Skeleton from 'flavours/glitch/components/skeleton';
|
2016-09-01 15:12:11 +03:00
|
|
|
|
2019-07-23 11:45:35 +03:00
|
|
|
export default class DisplayName extends React.PureComponent {
|
2016-09-01 15:12:11 +03:00
|
|
|
|
2019-07-23 11:45:35 +03:00
|
|
|
static propTypes = {
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
others: ImmutablePropTypes.list,
|
2023-05-18 00:24:27 +03:00
|
|
|
localDomain: PropTypes.string,
|
|
|
|
inline: PropTypes.bool,
|
2019-07-23 11:45:35 +03:00
|
|
|
};
|
2019-01-19 19:55:27 +02:00
|
|
|
|
2021-01-31 22:25:31 +02:00
|
|
|
handleMouseEnter = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
2019-07-21 19:10:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-31 22:25:31 +02:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-07-21 19:10:40 +03:00
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
2021-01-31 22:25:31 +02:00
|
|
|
emoji.src = emoji.getAttribute('data-original');
|
2019-07-21 19:10:40 +03:00
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2019-07-21 19:10:40 +03:00
|
|
|
|
2021-01-31 22:25:31 +02:00
|
|
|
handleMouseLeave = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
2019-07-21 19:10:40 +03:00
|
|
|
|
2021-01-31 22:25:31 +02:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-07-21 19:10:40 +03:00
|
|
|
|
2021-01-31 22:25:31 +02:00
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
emoji.src = emoji.getAttribute('data-static');
|
|
|
|
}
|
2023-02-03 21:52:07 +02:00
|
|
|
};
|
2019-07-21 19:10:40 +03:00
|
|
|
|
2023-05-18 00:24:27 +03:00
|
|
|
render () {
|
|
|
|
const { others, localDomain, inline } = this.props;
|
2019-06-09 13:07:23 +03:00
|
|
|
|
2023-05-18 00:24:27 +03:00
|
|
|
let displayName, suffix, account;
|
2019-06-09 13:07:23 +03:00
|
|
|
|
2023-05-18 00:24:27 +03:00
|
|
|
if (others && others.size > 1) {
|
|
|
|
displayName = others.take(2).map(a => <bdi key={a.get('id')}><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: a.get('display_name_html') }} /></bdi>).reduce((prev, cur) => [prev, ', ', cur]);
|
2019-01-19 19:55:27 +02:00
|
|
|
|
2023-05-18 00:24:27 +03:00
|
|
|
if (others.size - 2 > 0) {
|
|
|
|
suffix = `+${others.size - 2}`;
|
|
|
|
}
|
|
|
|
} else if ((others && others.size > 0) || this.props.account) {
|
|
|
|
if (others && others.size > 0) {
|
|
|
|
account = others.first();
|
|
|
|
} else {
|
|
|
|
account = this.props.account;
|
2022-10-05 04:47:56 +03:00
|
|
|
}
|
2019-06-09 13:07:23 +03:00
|
|
|
|
2023-05-18 00:24:27 +03:00
|
|
|
let acct = account.get('acct');
|
2019-07-23 11:45:35 +03:00
|
|
|
|
2023-05-18 00:24:27 +03:00
|
|
|
if (acct.indexOf('@') === -1 && localDomain) {
|
|
|
|
acct = `${acct}@${localDomain}`;
|
2019-07-23 11:45:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
displayName = <bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /></bdi>;
|
|
|
|
suffix = <span className='display-name__account'>@{acct}</span>;
|
2022-10-05 04:47:56 +03:00
|
|
|
} else {
|
|
|
|
displayName = <bdi><strong className='display-name__html'><Skeleton width='10ch' /></strong></bdi>;
|
|
|
|
suffix = <span className='display-name__account'><Skeleton width='7ch' /></span>;
|
2019-07-23 11:45:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-05-18 00:24:27 +03:00
|
|
|
<span className={classNames('display-name', { inline })} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
|
2019-07-23 11:45:35 +03:00
|
|
|
{displayName}
|
|
|
|
{inline ? ' ' : null}
|
|
|
|
{suffix}
|
|
|
|
</span>
|
2019-06-09 13:07:23 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 21:05:35 +03:00
|
|
|
}
|