about summary refs log tree commit diff
path: root/app/javascript/mastodon/components/display_name.js
blob: acddf77c54361806b5c695c1c2540940daf245a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';

export default class DisplayName extends React.PureComponent {

  static propTypes = {
    account: ImmutablePropTypes.map.isRequired,
    others: ImmutablePropTypes.list,
    localDomain: PropTypes.string,
  };

  render () {
    const { account, others, localDomain } = this.props;
    const displayNameHtml = { __html: account.get('display_name_html') };

    let suffix;

    if (others && others.size > 1) {
      suffix = `+${others.size}`;
    } else {
      let acct = account.get('acct');

      if (acct.indexOf('@') === -1 && localDomain) {
        acct = `${acct}@${localDomain}`;
      }

      suffix = <span className='display-name__account'>@{acct}</span>;
    }

    return (
      <span className='display-name'>
        <bdi><strong className='display-name__html' dangerouslySetInnerHTML={displayNameHtml} /></bdi> {suffix}
      </span>
    );
  }

}