The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

127 lines
4.8 KiB

  1. import React, { Fragment } from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import Avatar from './avatar';
  5. import DisplayName from './display_name';
  6. import Permalink from './permalink';
  7. import IconButton from './icon_button';
  8. import { defineMessages, injectIntl } from 'react-intl';
  9. import ImmutablePureComponent from 'react-immutable-pure-component';
  10. import { me } from '../initial_state';
  11. const messages = defineMessages({
  12. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  13. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  14. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
  15. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  16. unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
  17. mute_notifications: { id: 'account.mute_notifications', defaultMessage: 'Mute notifications from @{name}' },
  18. unmute_notifications: { id: 'account.unmute_notifications', defaultMessage: 'Unmute notifications from @{name}' },
  19. });
  20. export default @injectIntl
  21. class Account extends ImmutablePureComponent {
  22. static propTypes = {
  23. account: ImmutablePropTypes.map.isRequired,
  24. onFollow: PropTypes.func.isRequired,
  25. onBlock: PropTypes.func.isRequired,
  26. onMute: PropTypes.func.isRequired,
  27. onMuteNotifications: PropTypes.func.isRequired,
  28. intl: PropTypes.object.isRequired,
  29. hidden: PropTypes.bool,
  30. actionIcon: PropTypes.string,
  31. actionTitle: PropTypes.string,
  32. onActionClick: PropTypes.func,
  33. };
  34. handleFollow = () => {
  35. this.props.onFollow(this.props.account);
  36. }
  37. handleBlock = () => {
  38. this.props.onBlock(this.props.account);
  39. }
  40. handleMute = () => {
  41. this.props.onMute(this.props.account);
  42. }
  43. handleMuteNotifications = () => {
  44. this.props.onMuteNotifications(this.props.account, true);
  45. }
  46. handleUnmuteNotifications = () => {
  47. this.props.onMuteNotifications(this.props.account, false);
  48. }
  49. handleAction = () => {
  50. this.props.onActionClick(this.props.account);
  51. }
  52. render () {
  53. const { account, intl, hidden, onActionClick, actionIcon, actionTitle } = this.props;
  54. if (!account) {
  55. return <div />;
  56. }
  57. if (hidden) {
  58. return (
  59. <Fragment>
  60. {account.get('display_name')}
  61. {account.get('username')}
  62. </Fragment>
  63. );
  64. }
  65. let buttons;
  66. if (onActionClick && actionIcon) {
  67. buttons = <IconButton icon={actionIcon} title={actionTitle} onClick={this.handleAction} />;
  68. } else if (account.get('id') !== me && account.get('relationship', null) !== null) {
  69. const following = account.getIn(['relationship', 'following']);
  70. const requested = account.getIn(['relationship', 'requested']);
  71. const blocking = account.getIn(['relationship', 'blocking']);
  72. const muting = account.getIn(['relationship', 'muting']);
  73. if (requested) {
  74. buttons = <IconButton disabled icon='hourglass' title={intl.formatMessage(messages.requested)} />;
  75. } else if (blocking) {
  76. buttons = <IconButton active icon='unlock' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.handleBlock} />;
  77. } else if (muting) {
  78. let hidingNotificationsButton;
  79. if (account.getIn(['relationship', 'muting_notifications'])) {
  80. hidingNotificationsButton = <IconButton active icon='bell' title={intl.formatMessage(messages.unmute_notifications, { name: account.get('username') })} onClick={this.handleUnmuteNotifications} />;
  81. } else {
  82. hidingNotificationsButton = <IconButton active icon='bell-slash' title={intl.formatMessage(messages.mute_notifications, { name: account.get('username') })} onClick={this.handleMuteNotifications} />;
  83. }
  84. buttons = (
  85. <Fragment>
  86. <IconButton active icon='volume-up' title={intl.formatMessage(messages.unmute, { name: account.get('username') })} onClick={this.handleMute} />
  87. {hidingNotificationsButton}
  88. </Fragment>
  89. );
  90. } else if (!account.get('moved') || following) {
  91. buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
  92. }
  93. }
  94. return (
  95. <div className='account'>
  96. <div className='account__wrapper'>
  97. <Permalink key={account.get('id')} className='account__display-name' title={account.get('acct')} href={account.get('url')} to={`/accounts/${account.get('id')}`}>
  98. <div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
  99. <DisplayName account={account} />
  100. </Permalink>
  101. <div className='account__relationship'>
  102. {buttons}
  103. </div>
  104. </div>
  105. </div>
  106. );
  107. }
  108. }