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.

105 lines
3.1 KiB

Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
7 years ago
Optional notification muting (#5087) * Add a hide_notifications column to mutes * Add muting_notifications? and a notifications argument to mute! * block notifications in notify_service from hard muted accounts * Add specs for how mute! interacts with muting_notifications? * specs testing that hide_notifications in mutes actually hides notifications * Add support for muting notifications in MuteService * API support for muting notifications (and specs) * Less gross passing of notifications flag * Break out a separate mute modal with a hide-notifications checkbox. * Convert profile header mute to use mute modal * Satisfy eslint. * specs for MuteService notifications params * add trailing newlines to files for Pork :) * Put the label for the hide notifications checkbox in a label element. * Add a /api/v1/mutes/details route that just returns the array of mutes. * Define a serializer for /api/v1/mutes/details * Add more specs for the /api/v1/mutes/details endpoint * Expose whether a mute hides notifications in the api/v1/relationships endpoint * Show whether muted users' notifications are muted in account lists * Allow modifying the hide_notifications of a mute with the /api/v1/accounts/:id/mute endpoint * make the hide/unhide notifications buttons work * satisfy eslint * In probably dead code, replace a dispatch of muteAccount that was skipping the modal with launching the mute modal. * fix a missing import * add an explanatory comment to AccountInteractions * Refactor handling of default params for muting to make code cleaner * minor code style fixes oops * Fixed a typo that was breaking the account mute API endpoint * Apply white-space: nowrap to account relationships icons * Fix code style issues * Remove superfluous blank line * Rename /api/v1/mutes/details -> /api/v2/mutes * Don't serialize "account" in MuteSerializer Doing so is somewhat unnecessary since it's always the current user's account. * Fix wrong variable name in api/v2/mutes * Use Toggle in place of checkbox in the mute modal. * Make the Toggle in the mute modal look better * Code style changes in specs and removed an extra space * Code review suggestions from akihikodaki Also fixed a syntax error in tests for AccountInteractions. * Make AddHideNotificationsToMute Concurrent It's not clear how much this will benefit instances in practice, as the number of mutes tends to be pretty small, but this should prevent any blocking migrations nonetheless. * Fix up migration things * Remove /api/v2/mutes
7 years ago
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import { injectIntl, FormattedMessage } from 'react-intl';
  5. import Toggle from 'react-toggle';
  6. import Button from 'flavours/glitch/components/button';
  7. import { closeModal } from 'flavours/glitch/actions/modal';
  8. import { muteAccount } from 'flavours/glitch/actions/accounts';
  9. import { toggleHideNotifications } from 'flavours/glitch/actions/mutes';
  10. const mapStateToProps = state => {
  11. return {
  12. isSubmitting: state.getIn(['reports', 'new', 'isSubmitting']),
  13. account: state.getIn(['mutes', 'new', 'account']),
  14. notifications: state.getIn(['mutes', 'new', 'notifications']),
  15. };
  16. };
  17. const mapDispatchToProps = dispatch => {
  18. return {
  19. onConfirm(account, notifications) {
  20. dispatch(muteAccount(account.get('id'), notifications));
  21. },
  22. onClose() {
  23. dispatch(closeModal());
  24. },
  25. onToggleNotifications() {
  26. dispatch(toggleHideNotifications());
  27. },
  28. };
  29. };
  30. @connect(mapStateToProps, mapDispatchToProps)
  31. @injectIntl
  32. export default class MuteModal extends React.PureComponent {
  33. static propTypes = {
  34. isSubmitting: PropTypes.bool.isRequired,
  35. account: PropTypes.object.isRequired,
  36. notifications: PropTypes.bool.isRequired,
  37. onClose: PropTypes.func.isRequired,
  38. onConfirm: PropTypes.func.isRequired,
  39. onToggleNotifications: PropTypes.func.isRequired,
  40. intl: PropTypes.object.isRequired,
  41. };
  42. componentDidMount() {
  43. this.button.focus();
  44. }
  45. handleClick = () => {
  46. this.props.onClose();
  47. this.props.onConfirm(this.props.account, this.props.notifications);
  48. }
  49. handleCancel = () => {
  50. this.props.onClose();
  51. }
  52. setRef = (c) => {
  53. this.button = c;
  54. }
  55. toggleNotifications = () => {
  56. this.props.onToggleNotifications();
  57. }
  58. render () {
  59. const { account, notifications } = this.props;
  60. return (
  61. <div className='modal-root__modal mute-modal'>
  62. <div className='mute-modal__container'>
  63. <p>
  64. <FormattedMessage
  65. id='confirmations.mute.message'
  66. defaultMessage='Are you sure you want to mute {name}?'
  67. values={{ name: <strong>@{account.get('acct')}</strong> }}
  68. />
  69. </p>
  70. <div>
  71. <label htmlFor='mute-modal__hide-notifications-checkbox'>
  72. <FormattedMessage id='mute_modal.hide_notifications' defaultMessage='Hide notifications from this user?' />
  73. {' '}
  74. <Toggle id='mute-modal__hide-notifications-checkbox' checked={notifications} onChange={this.toggleNotifications} />
  75. </label>
  76. </div>
  77. </div>
  78. <div className='mute-modal__action-bar'>
  79. <Button onClick={this.handleCancel} className='mute-modal__cancel-button'>
  80. <FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
  81. </Button>
  82. <Button onClick={this.handleClick} ref={this.setRef}>
  83. <FormattedMessage id='confirmations.mute.confirm' defaultMessage='Mute' />
  84. </Button>
  85. </div>
  86. </div>
  87. );
  88. }
  89. }