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-01-16 20:47:46 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2019-07-21 19:10:40 +03:00
|
|
|
import { autoPlayGif } from 'mastodon/initial_state';
|
2016-09-01 15:12:11 +03:00
|
|
|
|
2017-06-23 20:36:54 +03:00
|
|
|
export default class DisplayName extends React.PureComponent {
|
2016-09-13 03:24:40 +03:00
|
|
|
|
2017-05-12 15:44:10 +03:00
|
|
|
static propTypes = {
|
2017-05-20 18:31:47 +03:00
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
2018-10-20 03:23:58 +03:00
|
|
|
others: ImmutablePropTypes.list,
|
2019-01-16 20:47:46 +02:00
|
|
|
localDomain: PropTypes.string,
|
2017-05-12 15:44:10 +03:00
|
|
|
};
|
|
|
|
|
2019-07-21 19:10:40 +03:00
|
|
|
_updateEmojis () {
|
|
|
|
const node = this.node;
|
|
|
|
|
|
|
|
if (!node || autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const emojis = node.querySelectorAll('.custom-emoji');
|
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
if (emoji.classList.contains('status-emoji')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
emoji.classList.add('status-emoji');
|
|
|
|
|
|
|
|
emoji.addEventListener('mouseenter', this.handleEmojiMouseEnter, false);
|
|
|
|
emoji.addEventListener('mouseleave', this.handleEmojiMouseLeave, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this._updateEmojis();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this._updateEmojis();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEmojiMouseEnter = ({ target }) => {
|
|
|
|
target.src = target.getAttribute('data-original');
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEmojiMouseLeave = ({ target }) => {
|
|
|
|
target.src = target.getAttribute('data-static');
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = (c) => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
2016-09-01 15:12:11 +03:00
|
|
|
render () {
|
2019-02-15 17:08:48 +02:00
|
|
|
const { others, localDomain } = this.props;
|
2016-09-04 15:04:26 +03:00
|
|
|
|
2019-02-15 17:08:48 +02:00
|
|
|
let displayName, suffix, account;
|
2018-10-20 03:23:58 +03:00
|
|
|
|
|
|
|
if (others && others.size > 1) {
|
2019-02-15 17:08:48 +02:00
|
|
|
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]);
|
|
|
|
|
|
|
|
if (others.size - 2 > 0) {
|
|
|
|
suffix = `+${others.size - 2}`;
|
|
|
|
}
|
2018-10-20 03:23:58 +03:00
|
|
|
} else {
|
2019-02-19 21:00:41 +02:00
|
|
|
if (others && others.size > 0) {
|
2019-02-15 17:08:48 +02:00
|
|
|
account = others.first();
|
|
|
|
} else {
|
|
|
|
account = this.props.account;
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:47:46 +02:00
|
|
|
let acct = account.get('acct');
|
|
|
|
|
|
|
|
if (acct.indexOf('@') === -1 && localDomain) {
|
|
|
|
acct = `${acct}@${localDomain}`;
|
|
|
|
}
|
|
|
|
|
2019-02-15 17:08:48 +02:00
|
|
|
displayName = <bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }} /></bdi>;
|
|
|
|
suffix = <span className='display-name__account'>@{acct}</span>;
|
2018-10-20 03:23:58 +03:00
|
|
|
}
|
|
|
|
|
2016-09-01 15:12:11 +03:00
|
|
|
return (
|
2019-07-21 19:10:40 +03:00
|
|
|
<span className='display-name' ref={this.setRef}>
|
2019-02-15 17:08:48 +02:00
|
|
|
{displayName} {suffix}
|
2016-09-01 15:12:11 +03:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 21:05:35 +03:00
|
|
|
}
|