The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

285 linhas
15 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 Button from 'mastodon/components/button';
  6. import ImmutablePureComponent from 'react-immutable-pure-component';
  7. import { autoPlayGif, me, isStaff } from 'mastodon/initial_state';
  8. import classNames from 'classnames';
  9. import Icon from 'mastodon/components/icon';
  10. import Avatar from 'mastodon/components/avatar';
  11. import { shortNumberFormat } from 'mastodon/utils/numbers';
  12. import { NavLink } from 'react-router-dom';
  13. import DropdownMenuContainer from 'mastodon/containers/dropdown_menu_container';
  14. const messages = defineMessages({
  15. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  16. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  17. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' },
  18. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  19. edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
  20. linkVerifiedOn: { id: 'account.link_verified_on', defaultMessage: 'Ownership of this link was checked on {date}' },
  21. account_locked: { id: 'account.locked_info', defaultMessage: 'This account privacy status is set to locked. The owner manually reviews who can follow them.' },
  22. mention: { id: 'account.mention', defaultMessage: 'Mention @{name}' },
  23. direct: { id: 'account.direct', defaultMessage: 'Direct message @{name}' },
  24. unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
  25. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  26. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  27. report: { id: 'account.report', defaultMessage: 'Report @{name}' },
  28. share: { id: 'account.share', defaultMessage: 'Share @{name}\'s profile' },
  29. media: { id: 'account.media', defaultMessage: 'Media' },
  30. blockDomain: { id: 'account.block_domain', defaultMessage: 'Hide everything from {domain}' },
  31. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' },
  32. hideReblogs: { id: 'account.hide_reblogs', defaultMessage: 'Hide boosts from @{name}' },
  33. showReblogs: { id: 'account.show_reblogs', defaultMessage: 'Show boosts from @{name}' },
  34. pins: { id: 'navigation_bar.pins', defaultMessage: 'Pinned toots' },
  35. preferences: { id: 'navigation_bar.preferences', defaultMessage: 'Preferences' },
  36. follow_requests: { id: 'navigation_bar.follow_requests', defaultMessage: 'Follow requests' },
  37. favourites: { id: 'navigation_bar.favourites', defaultMessage: 'Favourites' },
  38. lists: { id: 'navigation_bar.lists', defaultMessage: 'Lists' },
  39. blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' },
  40. domain_blocks: { id: 'navigation_bar.domain_blocks', defaultMessage: 'Hidden domains' },
  41. mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' },
  42. endorse: { id: 'account.endorse', defaultMessage: 'Feature on profile' },
  43. unendorse: { id: 'account.unendorse', defaultMessage: 'Don\'t feature on profile' },
  44. add_or_remove_from_list: { id: 'account.add_or_remove_from_list', defaultMessage: 'Add or Remove from lists' },
  45. admin_account: { id: 'status.admin_account', defaultMessage: 'Open moderation interface for @{name}' },
  46. });
  47. const dateFormatOptions = {
  48. month: 'short',
  49. day: 'numeric',
  50. year: 'numeric',
  51. hour12: false,
  52. hour: '2-digit',
  53. minute: '2-digit',
  54. };
  55. export default @injectIntl
  56. class Header extends ImmutablePureComponent {
  57. static propTypes = {
  58. account: ImmutablePropTypes.map,
  59. identity_props: ImmutablePropTypes.list,
  60. onFollow: PropTypes.func.isRequired,
  61. onBlock: PropTypes.func.isRequired,
  62. intl: PropTypes.object.isRequired,
  63. domain: PropTypes.string.isRequired,
  64. };
  65. openEditProfile = () => {
  66. window.open('/settings/profile', '_blank');
  67. }
  68. isStatusesPageActive = (match, location) => {
  69. if (!match) {
  70. return false;
  71. }
  72. return !location.pathname.match(/\/(followers|following)\/?$/);
  73. }
  74. render () {
  75. const { account, intl, domain, identity_proofs } = this.props;
  76. if (!account) {
  77. return null;
  78. }
  79. let info = [];
  80. let actionBtn = '';
  81. let lockedIcon = '';
  82. let menu = [];
  83. if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
  84. info.push(<span key='followed_by' className='relationship-tag'><FormattedMessage id='account.follows_you' defaultMessage='Follows you' /></span>);
  85. } else if (me !== account.get('id') && account.getIn(['relationship', 'blocking'])) {
  86. info.push(<span key='blocked' className='relationship-tag'><FormattedMessage id='account.blocked' defaultMessage='Blocked' /></span>);
  87. }
  88. if (me !== account.get('id') && account.getIn(['relationship', 'muting'])) {
  89. info.push(<span key='muted' className='relationship-tag'><FormattedMessage id='account.muted' defaultMessage='Muted' /></span>);
  90. } else if (me !== account.get('id') && account.getIn(['relationship', 'domain_blocking'])) {
  91. info.push(<span key='domain_blocked' className='relationship-tag'><FormattedMessage id='account.domain_blocked' defaultMessage='Domain hidden' /></span>);
  92. }
  93. if (me !== account.get('id')) {
  94. if (!account.get('relationship')) { // Wait until the relationship is loaded
  95. actionBtn = '';
  96. } else if (account.getIn(['relationship', 'requested'])) {
  97. actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.requested)} onClick={this.props.onFollow} />;
  98. } else if (!account.getIn(['relationship', 'blocking'])) {
  99. actionBtn = <Button disabled={account.getIn(['relationship', 'blocked_by'])} className={classNames('logo-button', { 'button--destructive': account.getIn(['relationship', 'following']) })} text={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.props.onFollow} />;
  100. } else if (account.getIn(['relationship', 'blocking'])) {
  101. actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />;
  102. }
  103. } else {
  104. actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.edit_profile)} onClick={this.openEditProfile} />;
  105. }
  106. if (account.get('moved') && !account.getIn(['relationship', 'following'])) {
  107. actionBtn = '';
  108. }
  109. if (account.get('locked')) {
  110. lockedIcon = <Icon id='lock' title={intl.formatMessage(messages.account_locked)} />;
  111. }
  112. if (account.get('id') !== me) {
  113. menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention });
  114. menu.push({ text: intl.formatMessage(messages.direct, { name: account.get('username') }), action: this.props.onDirect });
  115. menu.push(null);
  116. }
  117. if ('share' in navigator) {
  118. menu.push({ text: intl.formatMessage(messages.share, { name: account.get('username') }), action: this.handleShare });
  119. menu.push(null);
  120. }
  121. if (account.get('id') === me) {
  122. menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' });
  123. menu.push({ text: intl.formatMessage(messages.preferences), href: '/settings/preferences' });
  124. menu.push({ text: intl.formatMessage(messages.pins), to: '/pinned' });
  125. menu.push(null);
  126. menu.push({ text: intl.formatMessage(messages.follow_requests), to: '/follow_requests' });
  127. menu.push({ text: intl.formatMessage(messages.favourites), to: '/favourites' });
  128. menu.push({ text: intl.formatMessage(messages.lists), to: '/lists' });
  129. menu.push(null);
  130. menu.push({ text: intl.formatMessage(messages.mutes), to: '/mutes' });
  131. menu.push({ text: intl.formatMessage(messages.blocks), to: '/blocks' });
  132. menu.push({ text: intl.formatMessage(messages.domain_blocks), to: '/domain_blocks' });
  133. } else {
  134. if (account.getIn(['relationship', 'following'])) {
  135. if (account.getIn(['relationship', 'showing_reblogs'])) {
  136. menu.push({ text: intl.formatMessage(messages.hideReblogs, { name: account.get('username') }), action: this.props.onReblogToggle });
  137. } else {
  138. menu.push({ text: intl.formatMessage(messages.showReblogs, { name: account.get('username') }), action: this.props.onReblogToggle });
  139. }
  140. menu.push({ text: intl.formatMessage(account.getIn(['relationship', 'endorsed']) ? messages.unendorse : messages.endorse), action: this.props.onEndorseToggle });
  141. menu.push({ text: intl.formatMessage(messages.add_or_remove_from_list), action: this.props.onAddToList });
  142. menu.push(null);
  143. }
  144. if (account.getIn(['relationship', 'muting'])) {
  145. menu.push({ text: intl.formatMessage(messages.unmute, { name: account.get('username') }), action: this.props.onMute });
  146. } else {
  147. menu.push({ text: intl.formatMessage(messages.mute, { name: account.get('username') }), action: this.props.onMute });
  148. }
  149. if (account.getIn(['relationship', 'blocking'])) {
  150. menu.push({ text: intl.formatMessage(messages.unblock, { name: account.get('username') }), action: this.props.onBlock });
  151. } else {
  152. menu.push({ text: intl.formatMessage(messages.block, { name: account.get('username') }), action: this.props.onBlock });
  153. }
  154. menu.push({ text: intl.formatMessage(messages.report, { name: account.get('username') }), action: this.props.onReport });
  155. }
  156. if (account.get('acct') !== account.get('username')) {
  157. const domain = account.get('acct').split('@')[1];
  158. menu.push(null);
  159. if (account.getIn(['relationship', 'domain_blocking'])) {
  160. menu.push({ text: intl.formatMessage(messages.unblockDomain, { domain }), action: this.props.onUnblockDomain });
  161. } else {
  162. menu.push({ text: intl.formatMessage(messages.blockDomain, { domain }), action: this.props.onBlockDomain });
  163. }
  164. }
  165. if (account.get('id') !== me && isStaff) {
  166. menu.push(null);
  167. menu.push({ text: intl.formatMessage(messages.admin_account, { name: account.get('username') }), href: `/admin/accounts/${account.get('id')}` });
  168. }
  169. const content = { __html: account.get('note_emojified') };
  170. const displayNameHtml = { __html: account.get('display_name_html') };
  171. const fields = account.get('fields');
  172. const badge = account.get('bot') ? (<div className='account-role bot'><FormattedMessage id='account.badges.bot' defaultMessage='Bot' /></div>) : null;
  173. const acct = account.get('acct').indexOf('@') === -1 && domain ? `${account.get('acct')}@${domain}` : account.get('acct');
  174. return (
  175. <div className={classNames('account__header', { inactive: !!account.get('moved') })}>
  176. <div className='account__header__image'>
  177. <div className='account__header__info'>
  178. {info}
  179. </div>
  180. <img src={autoPlayGif ? account.get('header') : account.get('header_static')} alt='' className='parallax' />
  181. </div>
  182. <div className='account__header__bar'>
  183. <div className='account__header__tabs'>
  184. <a className='avatar' href={account.get('url')} rel='noopener' target='_blank'>
  185. <Avatar account={account} size={90} />
  186. </a>
  187. <div className='spacer' />
  188. <div className='account__header__tabs__buttons'>
  189. {actionBtn}
  190. <DropdownMenuContainer items={menu} icon='ellipsis-v' size={24} direction='right' />
  191. </div>
  192. </div>
  193. <div className='account__header__tabs__name'>
  194. <h1>
  195. <span dangerouslySetInnerHTML={displayNameHtml} /> {badge}
  196. <small>@{acct} {lockedIcon}</small>
  197. </h1>
  198. </div>
  199. <div className='account__header__extra'>
  200. <div className='account__header__bio'>
  201. { (fields.size > 0 || identity_proofs.size > 0) && (
  202. <div className='account__header__fields'>
  203. {identity_proofs.map((proof, i) => (
  204. <dl key={i}>
  205. <dt dangerouslySetInnerHTML={{ __html: proof.get('provider') }} />
  206. <dd className='verified'>
  207. <a href={proof.get('proof_url')} target='_blank' rel='noopener'><span title={intl.formatMessage(messages.linkVerifiedOn, { date: intl.formatDate(proof.get('updated_at'), dateFormatOptions) })}>
  208. <Icon id='check' className='verified__mark' />
  209. </span></a>
  210. <a href={proof.get('profile_url')} target='_blank' rel='noopener'><span dangerouslySetInnerHTML={{ __html: ' '+proof.get('provider_username') }} /></a>
  211. </dd>
  212. </dl>
  213. ))}
  214. {fields.map((pair, i) => (
  215. <dl key={i}>
  216. <dt dangerouslySetInnerHTML={{ __html: pair.get('name_emojified') }} title={pair.get('name')} />
  217. <dd className={pair.get('verified_at') && 'verified'} title={pair.get('value_plain')}>
  218. {pair.get('verified_at') && <span title={intl.formatMessage(messages.linkVerifiedOn, { date: intl.formatDate(pair.get('verified_at'), dateFormatOptions) })}><Icon id='check' className='verified__mark' /></span>} <span dangerouslySetInnerHTML={{ __html: pair.get('value_emojified') }} />
  219. </dd>
  220. </dl>
  221. ))}
  222. </div>
  223. )}
  224. {account.get('note').length > 0 && account.get('note') !== '<p></p>' && <div className='account__header__content' dangerouslySetInnerHTML={content} />}
  225. </div>
  226. <div className='account__header__extra__links'>
  227. <NavLink isActive={this.isStatusesPageActive} activeClassName='active' to={`/accounts/${account.get('id')}`} title={intl.formatNumber(account.get('statuses_count'))}>
  228. <strong>{shortNumberFormat(account.get('statuses_count'))}</strong> <FormattedMessage id='account.posts' defaultMessage='Toots' />
  229. </NavLink>
  230. <NavLink exact activeClassName='active' to={`/accounts/${account.get('id')}/following`} title={intl.formatNumber(account.get('following_count'))}>
  231. <strong>{shortNumberFormat(account.get('following_count'))}</strong> <FormattedMessage id='account.follows' defaultMessage='Follows' />
  232. </NavLink>
  233. <NavLink exact activeClassName='active' to={`/accounts/${account.get('id')}/followers`} title={intl.formatNumber(account.get('followers_count'))}>
  234. <strong>{shortNumberFormat(account.get('followers_count'))}</strong> <FormattedMessage id='account.followers' defaultMessage='Followers' />
  235. </NavLink>
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. );
  241. }
  242. }