From dadb98634cff44268a5e976fa523789c6fc49af5 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 2 Sep 2022 11:57:06 +0200 Subject: [PATCH] Fix regexp filtering in pinned community/public TLs (#1840) --- .../flavours/glitch/components/status_list.js | 1 + .../features/community_timeline/index.js | 4 ++++ .../glitch/features/home_timeline/index.js | 3 +++ .../glitch/features/public_timeline/index.js | 4 ++++ .../ui/containers/status_list_container.js | 20 ++++--------------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/javascript/flavours/glitch/components/status_list.js b/app/javascript/flavours/glitch/components/status_list.js index 9095e087ee..ac255f4ac4 100644 --- a/app/javascript/flavours/glitch/components/status_list.js +++ b/app/javascript/flavours/glitch/components/status_list.js @@ -25,6 +25,7 @@ export default class StatusList extends ImmutablePureComponent { alwaysPrepend: PropTypes.bool, emptyMessage: PropTypes.node, timelineId: PropTypes.string.isRequired, + regex: PropTypes.string, }; static defaultProps = { diff --git a/app/javascript/flavours/glitch/features/community_timeline/index.js b/app/javascript/flavours/glitch/features/community_timeline/index.js index 7341f9702e..64030e1956 100644 --- a/app/javascript/flavours/glitch/features/community_timeline/index.js +++ b/app/javascript/flavours/glitch/features/community_timeline/index.js @@ -19,11 +19,13 @@ const mapStateToProps = (state, { columnId }) => { const columns = state.getIn(['settings', 'columns']); const index = columns.findIndex(c => c.get('uuid') === uuid); const onlyMedia = (columnId && index >= 0) ? columns.get(index).getIn(['params', 'other', 'onlyMedia']) : state.getIn(['settings', 'community', 'other', 'onlyMedia']); + const regex = (columnId && index >= 0) ? columns.get(index).getIn(['params', 'regex', 'body']) : state.getIn(['settings', 'community', 'regex', 'body']); const timelineState = state.getIn(['timelines', `community${onlyMedia ? ':media' : ''}`]); return { hasUnread: !!timelineState && timelineState.get('unread') > 0, onlyMedia, + regex, }; }; @@ -46,6 +48,7 @@ class CommunityTimeline extends React.PureComponent { hasUnread: PropTypes.bool, multiColumn: PropTypes.bool, onlyMedia: PropTypes.bool, + regex: PropTypes.string, }; handlePin = () => { @@ -127,6 +130,7 @@ class CommunityTimeline extends React.PureComponent { onLoadMore={this.handleLoadMore} emptyMessage={} bindToDocument={!multiColumn} + regex={this.props.regex} /> ); diff --git a/app/javascript/flavours/glitch/features/home_timeline/index.js b/app/javascript/flavours/glitch/features/home_timeline/index.js index 19551d6b89..51e9323077 100644 --- a/app/javascript/flavours/glitch/features/home_timeline/index.js +++ b/app/javascript/flavours/glitch/features/home_timeline/index.js @@ -26,6 +26,7 @@ const mapStateToProps = state => ({ hasAnnouncements: !state.getIn(['announcements', 'items']).isEmpty(), unreadAnnouncements: state.getIn(['announcements', 'items']).count(item => !item.get('read')), showAnnouncements: state.getIn(['announcements', 'show']), + regex: state.getIn(['settings', 'home', 'regex', 'body']), }); export default @connect(mapStateToProps) @@ -42,6 +43,7 @@ class HomeTimeline extends React.PureComponent { hasAnnouncements: PropTypes.bool, unreadAnnouncements: PropTypes.number, showAnnouncements: PropTypes.bool, + regex: PropTypes.string, }; handlePin = () => { @@ -154,6 +156,7 @@ class HomeTimeline extends React.PureComponent { timelineId='home' emptyMessage={ }} />} bindToDocument={!multiColumn} + regex={this.props.regex} /> ); diff --git a/app/javascript/flavours/glitch/features/public_timeline/index.js b/app/javascript/flavours/glitch/features/public_timeline/index.js index 8480499656..9f31cf9223 100644 --- a/app/javascript/flavours/glitch/features/public_timeline/index.js +++ b/app/javascript/flavours/glitch/features/public_timeline/index.js @@ -21,6 +21,7 @@ const mapStateToProps = (state, { columnId }) => { const onlyMedia = (columnId && index >= 0) ? columns.get(index).getIn(['params', 'other', 'onlyMedia']) : state.getIn(['settings', 'public', 'other', 'onlyMedia']); const onlyRemote = (columnId && index >= 0) ? columns.get(index).getIn(['params', 'other', 'onlyRemote']) : state.getIn(['settings', 'public', 'other', 'onlyRemote']); const allowLocalOnly = (columnId && index >= 0) ? columns.get(index).getIn(['params', 'other', 'allowLocalOnly']) : state.getIn(['settings', 'public', 'other', 'allowLocalOnly']); + const regex = (columnId && index >= 0) ? columns.get(index).getIn(['params', 'regex', 'body']) : state.getIn(['settings', 'public', 'regex', 'body']); const timelineState = state.getIn(['timelines', `public${onlyMedia ? ':media' : ''}`]); return { @@ -28,6 +29,7 @@ const mapStateToProps = (state, { columnId }) => { onlyMedia, onlyRemote, allowLocalOnly, + regex, }; }; @@ -52,6 +54,7 @@ class PublicTimeline extends React.PureComponent { onlyMedia: PropTypes.bool, onlyRemote: PropTypes.bool, allowLocalOnly: PropTypes.bool, + regex: PropTypes.string, }; handlePin = () => { @@ -133,6 +136,7 @@ class PublicTimeline extends React.PureComponent { scrollKey={`public_timeline-${columnId}`} emptyMessage={} bindToDocument={!multiColumn} + regex={this.props.regex} /> ); diff --git a/app/javascript/flavours/glitch/features/ui/containers/status_list_container.js b/app/javascript/flavours/glitch/features/ui/containers/status_list_container.js index 0828e3cb03..53c3b8f392 100644 --- a/app/javascript/flavours/glitch/features/ui/containers/status_list_container.js +++ b/app/javascript/flavours/glitch/features/ui/containers/status_list_container.js @@ -6,20 +6,8 @@ import { createSelector } from 'reselect'; import { debounce } from 'lodash'; import { me } from 'flavours/glitch/util/initial_state'; -const normalizeTimelineId = timelineId => { - if (timelineId.startsWith('public:')) { - return 'public'; - } - - if (timelineId.startsWith('community:')) { - return 'community'; - } - - return timelineId; -}; - const getRegex = createSelector([ - (state, { type }) => state.getIn(['settings', normalizeTimelineId(type), 'regex', 'body']), + (state, { regex }) => regex, ], (rawRegex) => { let regex = null; @@ -32,7 +20,7 @@ const getRegex = createSelector([ }); const makeGetStatusIds = (pending = false) => createSelector([ - (state, { type }) => state.getIn(['settings', normalizeTimelineId(type)], ImmutableMap()), + (state, { type }) => state.getIn(['settings', type], ImmutableMap()), (state, { type }) => state.getIn(['timelines', type, pending ? 'pendingItems' : 'items'], ImmutableList()), (state) => state.get('statuses'), getRegex, @@ -70,8 +58,8 @@ const makeMapStateToProps = () => { const getStatusIds = makeGetStatusIds(); const getPendingStatusIds = makeGetStatusIds(true); - const mapStateToProps = (state, { timelineId }) => ({ - statusIds: getStatusIds(state, { type: timelineId }), + const mapStateToProps = (state, { timelineId, regex }) => ({ + statusIds: getStatusIds(state, { type: timelineId, regex }), isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true), isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false), hasMore: state.getIn(['timelines', timelineId, 'hasMore']),