Add regex filter back to firehose (#2266)

* Add regex filter back to firehose

The regex filter will apply to all tabs and not be automatically applied when pinned.

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>

* Keep regex when pinned

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>

---------

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>
pull/2274/head
Plastikmensch 2023-07-03 15:41:50 +02:00 committed by GitHub
parent b422b5eebd
commit ed15893eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import { changeSetting } from 'flavours/glitch/actions/settings';
import { connectPublicStream, connectCommunityStream } from 'flavours/glitch/actions/streaming'; import { connectPublicStream, connectCommunityStream } from 'flavours/glitch/actions/streaming';
import { expandPublicTimeline, expandCommunityTimeline } from 'flavours/glitch/actions/timelines'; import { expandPublicTimeline, expandCommunityTimeline } from 'flavours/glitch/actions/timelines';
import DismissableBanner from 'flavours/glitch/components/dismissable_banner'; import DismissableBanner from 'flavours/glitch/components/dismissable_banner';
import SettingText from 'flavours/glitch/components/setting_text';
import initialState, { domain } from 'flavours/glitch/initial_state'; import initialState, { domain } from 'flavours/glitch/initial_state';
import { useAppDispatch, useAppSelector } from 'flavours/glitch/store'; import { useAppDispatch, useAppSelector } from 'flavours/glitch/store';
@ -21,6 +22,7 @@ import StatusListContainer from '../ui/containers/status_list_container';
const messages = defineMessages({ const messages = defineMessages({
title: { id: 'column.firehose', defaultMessage: 'Live feeds' }, title: { id: 'column.firehose', defaultMessage: 'Live feeds' },
filter_regex: { id: 'home.column_settings.filter_regex', defaultMessage: 'Filter out by regular expressions' },
}); });
// TODO: use a proper React context later on // TODO: use a proper React context later on
@ -33,6 +35,7 @@ const useIdentity = () => ({
}); });
const ColumnSettings = () => { const ColumnSettings = () => {
const intl = useIntl();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const settings = useAppSelector((state) => state.getIn(['settings', 'firehose'])); const settings = useAppSelector((state) => state.getIn(['settings', 'firehose']));
const onChange = useCallback( const onChange = useCallback(
@ -55,6 +58,13 @@ const ColumnSettings = () => {
onChange={onChange} onChange={onChange}
label={<FormattedMessage id='firehose.column_settings.allow_local_only' defaultMessage='Show local-only posts in "All"' />} label={<FormattedMessage id='firehose.column_settings.allow_local_only' defaultMessage='Show local-only posts in "All"' />}
/> />
<span className='column-settings__section'><FormattedMessage id='home.column_settings.advanced' defaultMessage='Advanced' /></span>
<SettingText
settings={settings}
settingPath={['regex', 'body']}
onChange={onChange}
label={intl.formatMessage(messages.filter_regex)}
/>
</div> </div>
</div> </div>
); );
@ -70,22 +80,23 @@ const Firehose = ({ feedType, multiColumn }) => {
const hasUnread = useAppSelector((state) => state.getIn(['timelines', `${feedType}${onlyMedia ? ':media' : ''}`, 'unread'], 0) > 0); const hasUnread = useAppSelector((state) => state.getIn(['timelines', `${feedType}${onlyMedia ? ':media' : ''}`, 'unread'], 0) > 0);
const allowLocalOnly = useAppSelector((state) => state.getIn(['settings', 'firehose', 'allowLocalOnly'])); const allowLocalOnly = useAppSelector((state) => state.getIn(['settings', 'firehose', 'allowLocalOnly']));
const regex = useAppSelector((state) => state.getIn(['settings', 'firehose', 'regex', 'body']));
const handlePin = useCallback( const handlePin = useCallback(
() => { () => {
switch(feedType) { switch(feedType) {
case 'community': case 'community':
dispatch(addColumn('COMMUNITY', { other: { onlyMedia } })); dispatch(addColumn('COMMUNITY', { other: { onlyMedia }, regex: { body: regex } }));
break; break;
case 'public': case 'public':
dispatch(addColumn('PUBLIC', { other: { onlyMedia, allowLocalOnly } })); dispatch(addColumn('PUBLIC', { other: { onlyMedia, allowLocalOnly }, regex: { body: regex } }));
break; break;
case 'public:remote': case 'public:remote':
dispatch(addColumn('REMOTE', { other: { onlyMedia, onlyRemote: true } })); dispatch(addColumn('REMOTE', { other: { onlyMedia, onlyRemote: true }, regex: { body: regex } }));
break; break;
} }
}, },
[dispatch, onlyMedia, feedType, allowLocalOnly], [dispatch, onlyMedia, feedType, allowLocalOnly, regex],
); );
const handleLoadMore = useCallback( const handleLoadMore = useCallback(
@ -199,6 +210,7 @@ const Firehose = ({ feedType, multiColumn }) => {
scrollKey='firehose' scrollKey='firehose'
emptyMessage={emptyMessage} emptyMessage={emptyMessage}
bindToDocument={!multiColumn} bindToDocument={!multiColumn}
regex={regex}
/> />
</div> </div>

View File

@ -87,6 +87,10 @@ const initialState = ImmutableMap({
firehose: ImmutableMap({ firehose: ImmutableMap({
onlyMedia: false, onlyMedia: false,
allowLocalOnly: true, allowLocalOnly: true,
regex: ImmutableMap({
body: '',
}),
}), }),
community: ImmutableMap({ community: ImmutableMap({