logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

account.js (4514B)


  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. @injectIntl
  21. export default 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. };
  31. handleFollow = () => {
  32. this.props.onFollow(this.props.account);
  33. }
  34. handleBlock = () => {
  35. this.props.onBlock(this.props.account);
  36. }
  37. handleMute = () => {
  38. this.props.onMute(this.props.account);
  39. }
  40. handleMuteNotifications = () => {
  41. this.props.onMuteNotifications(this.props.account, true);
  42. }
  43. handleUnmuteNotifications = () => {
  44. this.props.onMuteNotifications(this.props.account, false);
  45. }
  46. render () {
  47. const { account, intl, hidden } = this.props;
  48. if (!account) {
  49. return <div />;
  50. }
  51. if (hidden) {
  52. return (
  53. <div>
  54. {account.get('display_name')}
  55. {account.get('username')}
  56. </div>
  57. );
  58. }
  59. let buttons;
  60. if (account.get('id') !== me && account.get('relationship', null) !== null) {
  61. const following = account.getIn(['relationship', 'following']);
  62. const requested = account.getIn(['relationship', 'requested']);
  63. const blocking = account.getIn(['relationship', 'blocking']);
  64. const muting = account.getIn(['relationship', 'muting']);
  65. if (requested) {
  66. buttons = <IconButton disabled icon='hourglass' title={intl.formatMessage(messages.requested)} />;
  67. } else if (blocking) {
  68. buttons = <IconButton active icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.handleBlock} />;
  69. } else if (muting) {
  70. let hidingNotificationsButton;
  71. if (account.getIn(['relationship', 'muting_notifications'])) {
  72. hidingNotificationsButton = <IconButton active icon='bell' title={intl.formatMessage(messages.unmute_notifications, { name: account.get('username') })} onClick={this.handleUnmuteNotifications} />;
  73. } else {
  74. hidingNotificationsButton = <IconButton active icon='bell-slash' title={intl.formatMessage(messages.mute_notifications, { name: account.get('username') })} onClick={this.handleMuteNotifications} />;
  75. }
  76. buttons = (
  77. <Fragment>
  78. <IconButton active icon='volume-up' title={intl.formatMessage(messages.unmute, { name: account.get('username') })} onClick={this.handleMute} />
  79. {hidingNotificationsButton}
  80. </Fragment>
  81. );
  82. } else if (!account.get('moved') || following) {
  83. buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
  84. }
  85. }
  86. return (
  87. <div className='account'>
  88. <div className='account__wrapper'>
  89. <Permalink key={account.get('id')} className='account__display-name' href={account.get('url')} to={`/accounts/${account.get('id')}`}>
  90. <div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
  91. <DisplayName account={account} />
  92. </Permalink>
  93. <div className='account__relationship'>
  94. {buttons}
  95. </div>
  96. </div>
  97. </div>
  98. );
  99. }
  100. }