From bde7a415b9ecbe9bcdf5d32918fd2cfcf5dad0d7 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 12 Jul 2019 16:01:33 +0200 Subject: Add a way to know why a status has been filtered, and show it anyway --- app/javascript/flavours/glitch/components/status.js | 17 ++++++++++++++++- .../flavours/glitch/components/status_action_bar.js | 11 +++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'app/javascript/flavours/glitch/components') diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index 022ae6de8..973275fbb 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -106,6 +106,7 @@ class Status extends ImmutablePureComponent { statusId: undefined, revealBehindCW: undefined, showCard: false, + bypassFilter: false, } // Avoid checking props that are functions (and whose equality will always @@ -126,6 +127,7 @@ class Status extends ImmutablePureComponent { 'isExpanded', 'isCollapsed', 'showMedia', + 'bypassFilter', ] // If our settings have changed to disable collapsed statuses, then we @@ -427,6 +429,15 @@ class Status extends ImmutablePureComponent { this.handleToggleMediaVisibility(); } + handleUnfilterClick = e => { + const { onUnfilter, status } = this.props; + onUnfilter(status.get('reblog') ? status.get('reblog') : status, () => this.setState({ bypassFilter: true })); + } + + handleFilterClick = () => { + this.setState({ bypassFilter: false }); + } + handleRef = c => { this.node = c; } @@ -485,7 +496,7 @@ class Status extends ImmutablePureComponent { ); } - if (status.get('filtered') || status.getIn(['reblog', 'filtered'])) { + if ((status.get('filtered') || status.getIn(['reblog', 'filtered'])) && !this.state.bypassFilter) { const minHandlers = this.props.muted ? {} : { moveUp: this.handleHotkeyMoveUp, moveDown: this.handleHotkeyMoveDown, @@ -495,6 +506,9 @@ class Status extends ImmutablePureComponent {
+
); @@ -689,6 +703,7 @@ class Status extends ImmutablePureComponent { account={status.get('account')} showReplyCount={settings.get('show_reply_count')} directMessage={!!otherAccounts} + onFilter={this.handleFilterClick} /> ) : null} {notification ? ( diff --git a/app/javascript/flavours/glitch/components/status_action_bar.js b/app/javascript/flavours/glitch/components/status_action_bar.js index c424fbde1..4ef518f5e 100644 --- a/app/javascript/flavours/glitch/components/status_action_bar.js +++ b/app/javascript/flavours/glitch/components/status_action_bar.js @@ -35,6 +35,7 @@ const messages = defineMessages({ admin_account: { id: 'status.admin_account', defaultMessage: 'Open moderation interface for @{name}' }, admin_status: { id: 'status.admin_status', defaultMessage: 'Open this status in the moderation interface' }, copy: { id: 'status.copy', defaultMessage: 'Copy link to status' }, + hide: { id: 'status.hide', defaultMessage: 'Hide toot' }, }); const obfuscatedCount = count => { @@ -69,6 +70,7 @@ export default class StatusActionBar extends ImmutablePureComponent { onMuteConversation: PropTypes.func, onPin: PropTypes.func, onBookmark: PropTypes.func, + onFilter: PropTypes.func, withDismiss: PropTypes.bool, showReplyCount: PropTypes.bool, directMessage: PropTypes.bool, @@ -191,6 +193,10 @@ export default class StatusActionBar extends ImmutablePureComponent { } } + handleFilterClick = () => { + this.props.onFilter(); + } + render () { const { status, intl, withDismiss, showReplyCount, directMessage } = this.props; @@ -263,6 +269,10 @@ export default class StatusActionBar extends ImmutablePureComponent { ); + const filterButton = status.get('filtered') && ( + + ); + let replyButton = ( , shareButton, , + filterButton,
, -- cgit From 16b79a6237b90fd0c2550794631a7ced146b01e3 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 12 Jul 2019 18:27:43 +0200 Subject: Add options to configure filtering behavior --- .../flavours/glitch/components/status.js | 8 +++++--- .../features/local_settings/navigation/index.js | 20 +++++++++++++------ .../glitch/features/local_settings/page/index.js | 23 ++++++++++++++++++++++ .../flavours/glitch/reducers/local_settings.js | 1 + 4 files changed, 43 insertions(+), 9 deletions(-) (limited to 'app/javascript/flavours/glitch/components') diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index 973275fbb..c8d0dacb0 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -506,9 +506,11 @@ class Status extends ImmutablePureComponent {
- + {settings.get('filtering_behavior') === 'hide' && ( + + )}
); diff --git a/app/javascript/flavours/glitch/features/local_settings/navigation/index.js b/app/javascript/flavours/glitch/features/local_settings/navigation/index.js index 01368abad..47f3d6d15 100644 --- a/app/javascript/flavours/glitch/features/local_settings/navigation/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/navigation/index.js @@ -13,6 +13,7 @@ const messages = defineMessages({ general: { id: 'settings.general', defaultMessage: 'General' }, compose: { id: 'settings.compose_box_opts', defaultMessage: 'Compose box' }, content_warnings: { id: 'settings.content_warnings', defaultMessage: 'Content Warnings' }, + filters: { id: 'settings.filters', defaultMessage: 'Filters' }, collapsed: { id: 'settings.collapsed_statuses', defaultMessage: 'Collapsed toots' }, media: { id: 'settings.media', defaultMessage: 'Media' }, preferences: { id: 'settings.preferences', defaultMessage: 'Preferences' }, @@ -60,27 +61,34 @@ export default class LocalSettingsNavigation extends React.PureComponent { active={index === 3} index={3} onNavigate={onNavigate} - icon='angle-double-up' - title={intl.formatMessage(messages.collapsed)} + icon='filter' + title={intl.formatMessage(messages.filters)} /> + ), + ({ intl, onChange, settings }) => ( +
+

+ + + +
+ ), ({ onChange, settings }) => (

diff --git a/app/javascript/flavours/glitch/reducers/local_settings.js b/app/javascript/flavours/glitch/reducers/local_settings.js index 68e1c8424..6fd3d901b 100644 --- a/app/javascript/flavours/glitch/reducers/local_settings.js +++ b/app/javascript/flavours/glitch/reducers/local_settings.js @@ -21,6 +21,7 @@ const initialState = ImmutableMap({ inline_preview_cards: true, hicolor_privacy_icons: false, show_content_type_choice: false, + filtering_behavior: 'hide', content_warnings : ImmutableMap({ auto_unfold : false, filter : null, -- cgit From 85f3bc1ab39bb4244e910de24eac8415c0d66207 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 12 Jul 2019 18:53:40 +0200 Subject: Implement feature to add filtered phrases to content warnings --- app/javascript/flavours/glitch/components/status.js | 12 ++++++------ app/javascript/flavours/glitch/selectors/index.js | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'app/javascript/flavours/glitch/components') diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index c8d0dacb0..4cd6b3a36 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -106,7 +106,7 @@ class Status extends ImmutablePureComponent { statusId: undefined, revealBehindCW: undefined, showCard: false, - bypassFilter: false, + forceFilter: undefined, } // Avoid checking props that are functions (and whose equality will always @@ -127,7 +127,7 @@ class Status extends ImmutablePureComponent { 'isExpanded', 'isCollapsed', 'showMedia', - 'bypassFilter', + 'forceFilter', ] // If our settings have changed to disable collapsed statuses, then we @@ -431,11 +431,11 @@ class Status extends ImmutablePureComponent { handleUnfilterClick = e => { const { onUnfilter, status } = this.props; - onUnfilter(status.get('reblog') ? status.get('reblog') : status, () => this.setState({ bypassFilter: true })); + onUnfilter(status.get('reblog') ? status.get('reblog') : status, () => this.setState({ forceFilter: false })); } handleFilterClick = () => { - this.setState({ bypassFilter: false }); + this.setState({ forceFilter: true }); } handleRef = c => { @@ -496,7 +496,7 @@ class Status extends ImmutablePureComponent { ); } - if ((status.get('filtered') || status.getIn(['reblog', 'filtered'])) && !this.state.bypassFilter) { + if ((status.get('filtered') || status.getIn(['reblog', 'filtered'])) && (this.state.forceFilter === true || settings.get('filtering_behavior') !== 'content_warning')) { const minHandlers = this.props.muted ? {} : { moveUp: this.handleHotkeyMoveUp, moveDown: this.handleHotkeyMoveDown, @@ -506,7 +506,7 @@ class Status extends ImmutablePureComponent {
- {settings.get('filtering_behavior') === 'hide' && ( + {settings.get('filtering_behavior') !== 'upstream' && ( diff --git a/app/javascript/flavours/glitch/selectors/index.js b/app/javascript/flavours/glitch/selectors/index.js index 551a3ae31..b414cd5e5 100644 --- a/app/javascript/flavours/glitch/selectors/index.js +++ b/app/javascript/flavours/glitch/selectors/index.js @@ -1,3 +1,4 @@ +import escapeTextContentForBrowser from 'escape-html'; import { createSelector } from 'reselect'; import { List as ImmutableList, is } from 'immutable'; import { me } from 'flavours/glitch/util/initial_state'; @@ -90,10 +91,12 @@ export const makeGetStatus = () => { (state, { id }) => state.getIn(['accounts', state.getIn(['statuses', id, 'account'])]), (state, { id }) => state.getIn(['accounts', state.getIn(['statuses', state.getIn(['statuses', id, 'reblog']), 'account'])]), (state, _) => state.getIn(['local_settings', 'filtering_behavior']), + (state, _) => state.get('filters', ImmutableList()), + (_, { contextType }) => contextType, getFiltersRegex, ], - (statusBase, statusReblog, accountBase, accountReblog, filteringBehavior, filtersRegex) => { + (statusBase, statusReblog, accountBase, accountReblog, filteringBehavior, filters, contextType, filtersRegex) => { if (!statusBase) { return null; } @@ -119,6 +122,22 @@ export const makeGetStatus = () => { if (filtered && filteringBehavior === 'drop') { return null; + } else if (filtered && filteringBehavior === 'content_warning') { + let spoilerText = (statusReblog || statusBase).get('spoiler_text', ''); + const searchIndex = (statusReblog || statusBase).get('search_index'); + const serverSideType = toServerSideType(contextType); + const enabledFilters = filters.filter(filter => filter.get('context').includes(serverSideType) && (filter.get('expires_at') === null || Date.parse(filter.get('expires_at')) > (new Date()))).toArray(); + const matchingFilters = enabledFilters.filter(filter => { + const regexp = regexFromFilters([filter]); + return regexp.test(searchIndex) && !regexp.test(spoilerText); + }); + if (statusReblog) { + statusReblog = statusReblog.set('spoiler_text', matchingFilters.map(filter => filter.get('phrase')).concat([spoilerText]).filter(cw => !!cw).join(', ')); + statusReblog = statusReblog.update('spoilerHtml', '', spoilerText => matchingFilters.map(filter => escapeTextContentForBrowser(filter.get('phrase'))).concat([spoilerText]).filter(cw => !!cw).join(', ')); + } else { + statusBase = statusBase.set('spoiler_text', matchingFilters.map(filter => filter.get('phrase')).concat([spoilerText]).filter(cw => !!cw).join(', ')); + statusBase = statusBase.update('spoilerHtml', '', spoilerText => matchingFilters.map(filter => escapeTextContentForBrowser(filter.get('phrase'))).concat([spoilerText]).filter(cw => !!cw).join(', ')); + } } return statusBase.withMutations(map => { -- cgit From 707b8d7d75d8f44b4a638752b6a24824c0ba4bbd Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sun, 14 Jul 2019 21:39:07 +0200 Subject: Move the “Show why” button inline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/flavours/glitch/components/status.js | 3 ++- app/javascript/flavours/glitch/styles/components/status.scss | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'app/javascript/flavours/glitch/components') diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index 4cd6b3a36..e94ce6dfe 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -506,9 +506,10 @@ class Status extends ImmutablePureComponent {
+ {settings.get('filtering_behavior') !== 'upstream' && ' '} {settings.get('filtering_behavior') !== 'upstream' && ( )}
diff --git a/app/javascript/flavours/glitch/styles/components/status.scss b/app/javascript/flavours/glitch/styles/components/status.scss index cf8f39693..4ffbb2c21 100644 --- a/app/javascript/flavours/glitch/styles/components/status.scss +++ b/app/javascript/flavours/glitch/styles/components/status.scss @@ -998,14 +998,13 @@ a.status-card.compact:hover { } .status__wrapper--filtered__button { - display: block; - font-size: 15px; - line-height: 20px; + display: inline; color: lighten($ui-highlight-color, 8%); border: 0; background: transparent; padding: 0; - padding-top: 8px; + font-size: inherit; + line-height: inherit; &:hover, &:active { -- cgit From fc8577cf2b0f852fe9b5ac2e19ec2fcce0180c49 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sun, 14 Jul 2019 21:43:49 +0200 Subject: Minor refactoring --- .../flavours/glitch/components/spoilers.js | 50 ++++++++++++++++++++++ .../flavours/glitch/containers/status_container.js | 49 +++------------------ 2 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 app/javascript/flavours/glitch/components/spoilers.js (limited to 'app/javascript/flavours/glitch/components') diff --git a/app/javascript/flavours/glitch/components/spoilers.js b/app/javascript/flavours/glitch/components/spoilers.js new file mode 100644 index 000000000..8527403c1 --- /dev/null +++ b/app/javascript/flavours/glitch/components/spoilers.js @@ -0,0 +1,50 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { FormattedMessage } from 'react-intl'; + +export default +class Spoilers extends React.PureComponent { + static propTypes = { + spoilerText: PropTypes.string, + children: PropTypes.node, + }; + + state = { + hidden: true, + } + + handleSpoilerClick = () => { + this.setState({ hidden: !this.state.hidden }); + } + + render () { + const { spoilerText, children } = this.props; + const { hidden } = this.state; + + const toggleText = hidden ? + : + ; + + return ([ +

+ {spoilerText} + {' '} + +

, +
+ {children} +
+ ]); + } +} + diff --git a/app/javascript/flavours/glitch/containers/status_container.js b/app/javascript/flavours/glitch/containers/status_container.js index ba12ad38d..41fcc2010 100644 --- a/app/javascript/flavours/glitch/containers/status_container.js +++ b/app/javascript/flavours/glitch/containers/status_container.js @@ -28,6 +28,7 @@ import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { boostModal, favouriteModal, deleteModal } from 'flavours/glitch/util/initial_state'; import { showAlertForError } from '../actions/alerts'; import AccountContainer from 'flavours/glitch/containers/account_container'; +import Spoilers from '../components/spoilers'; const messages = defineMessages({ deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' }, @@ -41,46 +42,6 @@ const messages = defineMessages({ unfilterConfirm: { id: 'confirmations.unfilter.confirm', defaultMessage: 'Show' }, }); -class SpoilerMachin extends React.PureComponent { - state = { - hidden: true, - } - - handleSpoilerClick = () => { - this.setState({ hidden: !this.state.hidden }); - } - - render () { - const { spoilerText, children } = this.props; - const { hidden } = this.state; - - const toggleText = hidden ? - : - ; - - return ([ -

- {spoilerText} - {' '} - -

, -
- {children} -
- ]); - } -} - const makeMapStateToProps = () => { const getStatus = makeGetStatus(); @@ -243,14 +204,14 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({ message: [ ,
- + - - + +
    {matchingFilters.map(filter =>
  • {filter.get('phrase')}
  • )}
-
+
], confirm: intl.formatMessage(messages.unfilterConfirm), -- cgit