Fix filters not applying in detailed view (#34259)

This commit is contained in:
Claire 2025-03-25 14:11:49 +01:00 committed by KMY
parent ff2ba559e8
commit 853b848109
4 changed files with 34 additions and 12 deletions

View file

@ -15,6 +15,7 @@ import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?re
import { AnimatedNumber } from 'mastodon/components/animated_number';
import { ContentWarning } from 'mastodon/components/content_warning';
import EditedTimestamp from 'mastodon/components/edited_timestamp';
import { FilterWarning } from 'mastodon/components/filter_warning';
import type { StatusLike } from 'mastodon/components/hashtag_bar';
import { getHashtagBarForStatus } from 'mastodon/components/hashtag_bar';
import { Icon } from 'mastodon/components/icon';
@ -80,6 +81,7 @@ export const DetailedStatus: React.FC<{
}) => {
const properStatus = status?.get('reblog') ?? status;
const [height, setHeight] = useState(0);
const [showDespiteFilter, setShowDespiteFilter] = useState(false);
const nodeRef = useRef<HTMLDivElement>();
const handleOpenVideo = useCallback(
@ -92,6 +94,10 @@ export const DetailedStatus: React.FC<{
[onOpenVideo, status],
);
const handleFilterToggle = useCallback(() => {
setShowDespiteFilter(!showDespiteFilter);
}, [showDespiteFilter, setShowDespiteFilter]);
const handleExpandedToggle = useCallback(() => {
if (onToggleHidden) onToggleHidden(status);
}, [onToggleHidden, status]);
@ -369,8 +375,12 @@ export const DetailedStatus: React.FC<{
const { statusContentProps, hashtagBar } = getHashtagBarForStatus(
status as StatusLike,
);
const matchedFilters = status.get('matched_filters');
const expanded =
!status.get('hidden') || status.get('spoiler_text').length === 0;
(!matchedFilters || showDespiteFilter) &&
(!status.get('hidden') || status.get('spoiler_text').length === 0);
const quote = !muted && status.get('quote_id') && (
<>
@ -418,17 +428,26 @@ export const DetailedStatus: React.FC<{
)}
</Link>
{status.get('spoiler_text').length > 0 && (
<ContentWarning
text={
status.getIn(['translation', 'spoilerHtml']) ||
status.get('spoilerHtml')
}
expanded={expanded}
onClick={handleExpandedToggle}
{matchedFilters && (
<FilterWarning
title={matchedFilters.join(', ')}
expanded={showDespiteFilter}
onClick={handleFilterToggle}
/>
)}
{status.get('spoiler_text').length > 0 &&
(!matchedFilters || showDespiteFilter) && (
<ContentWarning
text={
status.getIn(['translation', 'spoilerHtml']) ||
status.get('spoilerHtml')
}
expanded={expanded}
onClick={handleExpandedToggle}
/>
)}
{expanded && (
<>
<StatusContent

View file

@ -147,7 +147,7 @@ const makeMapStateToProps = () => {
});
const mapStateToProps = (state, props) => {
const status = getStatus(state, { id: props.params.statusId });
const status = getStatus(state, { id: props.params.statusId, contextType: 'detailed' });
let ancestorsIds = ImmutableList();
let descendantsIds = ImmutableList();

View file

@ -17,9 +17,10 @@ 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'])]),
getFilters,
(_, { contextType }) => contextType === 'detailed',
],
(statusBase, statusReblog, statusQuote, statusReblogQuote, accountBase, accountReblog, filters) => {
(statusBase, statusReblog, statusQuote, statusReblogQuote, accountBase, accountReblog, filters, warnInsteadOfHide) => {
if (!statusBase || statusBase.get('isLoading')) {
return null;
}
@ -46,7 +47,7 @@ export const makeGetStatus = () => {
}
}
if (filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action']) === 'hide')) {
if (!warnInsteadOfHide && filterResults.some((result) => filters.getIn([result.get('filter'), 'filter_action']) === 'hide')) {
return null;
}
filterResults = filterResults.filter(result => filters.has(result.get('filter')));

View file

@ -7,6 +7,8 @@ export const toServerSideType = (columnType: string) => {
case 'account':
case 'explore':
return columnType;
case 'detailed':
return 'thread';
default:
if (columnType.includes('list:') || columnType.includes('antenna:')) {
return 'home';