You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
6.3 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import Avatar from 'flavours/glitch/components/avatar';
  7. import IconButton from 'flavours/glitch/components/icon_button';
  8. import { autoPlayGif, me } from 'flavours/glitch/util/initial_state';
  9. import classNames from 'classnames';
  10. const messages = defineMessages({
  11. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  12. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  13. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' },
  14. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  15. edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
  16. link_verified_on: { id: 'account.link_verified_on', defaultMessage: 'Ownership of this link was checked on {date}' },
  17. });
  18. const dateFormatOptions = {
  19. month: 'short',
  20. day: 'numeric',
  21. year: 'numeric',
  22. hour12: false,
  23. hour: '2-digit',
  24. minute: '2-digit',
  25. };
  26. @injectIntl
  27. export default class Header extends ImmutablePureComponent {
  28. static propTypes = {
  29. account: ImmutablePropTypes.map,
  30. onFollow: PropTypes.func.isRequired,
  31. onBlock: PropTypes.func.isRequired,
  32. intl: PropTypes.object.isRequired,
  33. };
  34. openEditProfile = () => {
  35. window.open('/settings/profile', '_blank');
  36. }
  37. render () {
  38. const { account, intl } = this.props;
  39. if (!account) {
  40. return null;
  41. }
  42. let displayName = account.get('display_name_html');
  43. let fields = account.get('fields');
  44. let badge = account.get('bot') ? (<div className='roles'><div className='account-role bot'><FormattedMessage id='account.badges.bot' defaultMessage='Bot' /></div></div>) : null;
  45. let info = '';
  46. let mutingInfo = '';
  47. let actionBtn = '';
  48. if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
  49. info = <span className='account--follows-info'><FormattedMessage id='account.follows_you' defaultMessage='Follows you' /></span>;
  50. }
  51. else if (me !== account.get('id') && account.getIn(['relationship', 'blocking'])) {
  52. info = <span className='account--follows-info'><FormattedMessage id='account.blocked' defaultMessage='Blocked' /></span>;
  53. }
  54. if (me !== account.get('id') && account.getIn(['relationship', 'muting'])) {
  55. mutingInfo = <span className='account--muting-info'><FormattedMessage id='account.muted' defaultMessage='Muted' /></span>;
  56. } else if (me !== account.get('id') && account.getIn(['relationship', 'domain_blocking'])) {
  57. mutingInfo = <span className='account--muting-info'><FormattedMessage id='account.domain_blocked' defaultMessage='Domain hidden' /></span>;
  58. }
  59. if (me !== account.get('id')) {
  60. if (!account.get('relationship')) { // Wait until the relationship is loaded
  61. actionBtn = '';
  62. } else if (account.getIn(['relationship', 'requested'])) {
  63. actionBtn = (
  64. <div className='account--action-button'>
  65. <IconButton size={26} active icon='hourglass' title={intl.formatMessage(messages.requested)} onClick={this.props.onFollow} />
  66. </div>
  67. );
  68. } else if (!account.getIn(['relationship', 'blocking'])) {
  69. actionBtn = (
  70. <div className='account--action-button'>
  71. <IconButton size={26} icon={account.getIn(['relationship', 'following']) ? 'user-times' : 'user-plus'} active={account.getIn(['relationship', 'following'])} title={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.props.onFollow} />
  72. </div>
  73. );
  74. } else if (account.getIn(['relationship', 'blocking'])) {
  75. actionBtn = (
  76. <div className='account--action-button'>
  77. <IconButton size={26} icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />
  78. </div>
  79. );
  80. }
  81. } else {
  82. actionBtn = (
  83. <div className='account--action-button'>
  84. <IconButton size={26} icon='pencil' title={intl.formatMessage(messages.edit_profile)} onClick={this.openEditProfile} />
  85. </div>
  86. );
  87. }
  88. if (account.get('moved') && !account.getIn(['relationship', 'following'])) {
  89. actionBtn = '';
  90. }
  91. const content = { __html: account.get('note_emojified') };
  92. return (
  93. <div className='account__header__wrapper'>
  94. <div className={classNames('account__header', { inactive: !!account.get('moved') })} style={{ backgroundImage: `url(${autoPlayGif ? account.get('header') : account.get('header_static')})` }}>
  95. <div>
  96. <a
  97. href={account.get('url')}
  98. className='account__header__avatar'
  99. role='presentation'
  100. target='_blank'
  101. rel='noopener'
  102. >
  103. <Avatar account={account} size={90} />
  104. </a>
  105. <span className='account__header__display-name' dangerouslySetInnerHTML={{ __html: displayName }} />
  106. <span className='account__header__username'>@{account.get('acct')} {account.get('locked') ? <i className='fa fa-lock' /> : null}</span>
  107. {badge}
  108. <div className='account__header__content' dangerouslySetInnerHTML={content} />
  109. {fields.size > 0 && (
  110. <div className='account__header__fields'>
  111. {fields.map((pair, i) => (
  112. <dl key={i}>
  113. <dt dangerouslySetInnerHTML={{ __html: pair.get('name_emojified') }} title={pair.get('name')} />
  114. <dd className={pair.get('verified_at') && 'verified'} title={pair.get('value_plain')}>
  115. {pair.get('verified_at') && <span title={intl.formatMessage(messages.link_verified_on, { date: intl.formatDate(pair.get('verified_at'), dateFormatOptions) })}><i className='fa fa-check verified__mark' /></span>} <span dangerouslySetInnerHTML={{ __html: pair.get('value_emojified') }} />
  116. </dd>
  117. </dl>
  118. ))}
  119. </div>
  120. )}
  121. {info}
  122. {mutingInfo}
  123. {actionBtn}
  124. </div>
  125. </div>
  126. </div>
  127. );
  128. }
  129. }