From ccfb48d3eb354e5cdce24dc975ea8a3fb2a1c80e Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 7 Jun 2019 18:38:07 +0200 Subject: [PATCH] Add option to display a warning before boosting toots lacking media descriptions --- .../glitch/containers/status_container.js | 15 ++++++++++----- .../glitch/features/local_settings/page/index.js | 8 ++++++++ .../flavours/glitch/features/status/index.js | 10 +++++++--- .../glitch/features/ui/components/boost_modal.js | 11 +++++++++-- .../flavours/glitch/reducers/local_settings.js | 1 + 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/javascript/flavours/glitch/containers/status_container.js b/app/javascript/flavours/glitch/containers/status_container.js index 98dc5bb87..a6069cb90 100644 --- a/app/javascript/flavours/glitch/containers/status_container.js +++ b/app/javascript/flavours/glitch/containers/status_container.js @@ -96,11 +96,16 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ }, onReblog (status, e) { - if (e.shiftKey || !boostModal) { - this.onModalReblog(status); - } else { - dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); - } + dispatch((_, getState) => { + let state = getState(); + if (state.getIn(['local_settings', 'confirm_boost_missing_media_description']) && status.get('media_attachments').some(item => !item.get('description')) && !status.get('reblogged')) { + dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog, missingMediaDescription: true })); + } else if (e.shiftKey || !boostModal) { + this.onModalReblog(status); + } else { + dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); + } + }); }, onBookmark (status) { diff --git a/app/javascript/flavours/glitch/features/local_settings/page/index.js b/app/javascript/flavours/glitch/features/local_settings/page/index.js index cd2d86713..8f5fc5401 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/page/index.js @@ -51,6 +51,14 @@ export default class LocalSettingsPage extends React.PureComponent { + + +

{ + const { settings, dispatch } = this.props; + if (status.get('reblogged')) { - this.props.dispatch(unreblog(status)); + dispatch(unreblog(status)); } else { - if ((e && e.shiftKey) || !boostModal) { + if (settings.get('confirm_boost_missing_media_description') && status.get('media_attachments').some(item => !item.get('description'))) { + dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog, missingMediaDescription: true })); + } else if ((e && e.shiftKey) || !boostModal) { this.handleModalReblog(status); } else { - this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog })); + dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog })); } } } diff --git a/app/javascript/flavours/glitch/features/ui/components/boost_modal.js b/app/javascript/flavours/glitch/features/ui/components/boost_modal.js index ce7ec2479..81bd1e576 100644 --- a/app/javascript/flavours/glitch/features/ui/components/boost_modal.js +++ b/app/javascript/flavours/glitch/features/ui/components/boost_modal.js @@ -25,6 +25,7 @@ export default class BoostModal extends ImmutablePureComponent { status: ImmutablePropTypes.map.isRequired, onReblog: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired, + missingMediaDescription: PropTypes.bool, intl: PropTypes.object.isRequired, }; @@ -52,7 +53,7 @@ export default class BoostModal extends ImmutablePureComponent { } render () { - const { status, intl } = this.props; + const { status, missingMediaDescription, intl } = this.props; const buttonText = status.get('reblogged') ? messages.cancel_reblog : messages.reblog; return ( @@ -78,7 +79,13 @@ export default class BoostModal extends ImmutablePureComponent {
-
Shift + }} />
+
+ { missingMediaDescription ? + + : + Shift + }} /> + } +
diff --git a/app/javascript/flavours/glitch/reducers/local_settings.js b/app/javascript/flavours/glitch/reducers/local_settings.js index 5716c5982..68e1c8424 100644 --- a/app/javascript/flavours/glitch/reducers/local_settings.js +++ b/app/javascript/flavours/glitch/reducers/local_settings.js @@ -15,6 +15,7 @@ const initialState = ImmutableMap({ show_reply_count : false, always_show_spoilers_field: false, confirm_missing_media_description: false, + confirm_boost_missing_media_description: false, confirm_before_clearing_draft: true, preselect_on_reply: true, inline_preview_cards: true,