Merge branch 'sensitive' into fork

This commit is contained in:
marcin mikołajczak 2024-04-28 15:27:15 +02:00
commit 4d75987b3f
24 changed files with 81 additions and 355 deletions

View file

@ -3,8 +3,6 @@ import { Entities } from 'soapbox/entity-store/entities';
import { Group, accountSchema, groupSchema } from 'soapbox/schemas';
import { filteredArray } from 'soapbox/schemas/utils';
import { getSettings } from '../settings';
import type { AppDispatch, RootState } from 'soapbox/store';
import type { APIEntity } from 'soapbox/types/entities';
@ -45,17 +43,9 @@ const importGroup = (group: Group) =>
const importGroups = (groups: Group[]) =>
importEntities(groups, Entities.GROUPS);
const importStatus = (status: APIEntity, idempotencyKey?: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const expandSpoilers = getSettings(getState()).get('expandSpoilers');
return dispatch({ type: STATUS_IMPORT, status, idempotencyKey, expandSpoilers });
};
const importStatus = (status: APIEntity, idempotencyKey?: string) => ({ type: STATUS_IMPORT, status, idempotencyKey });
const importStatuses = (statuses: APIEntity[]) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const expandSpoilers = getSettings(getState()).get('expandSpoilers');
return dispatch({ type: STATUSES_IMPORT, statuses, expandSpoilers });
};
const importStatuses = (statuses: APIEntity[]) => ({ type: STATUSES_IMPORT, statuses });
const importPolls = (polls: APIEntity[]) =>
({ type: POLLS_IMPORT, polls });

View file

@ -31,7 +31,6 @@ const defaultSettings = ImmutableMap({
underlineLinks: false,
autoPlayGif: true,
displayMedia: 'default',
expandSpoilers: false,
unfollowModal: false,
boostModal: false,
deleteModal: true,

View file

@ -46,7 +46,7 @@ describe('fetchStatusQuotes()', () => {
{ type: 'STATUS_QUOTES_FETCH_REQUEST', statusId },
{ type: 'POLLS_IMPORT', polls: [] },
{ type: 'ACCOUNTS_IMPORT', accounts: [status.account] },
{ type: 'STATUSES_IMPORT', statuses: [status], expandSpoilers: false },
{ type: 'STATUSES_IMPORT', statuses: [status] },
{ type: 'STATUS_QUOTES_FETCH_SUCCESS', statusId, statuses: [status], next: null },
];
await store.dispatch(fetchStatusQuotes(statusId));
@ -118,7 +118,7 @@ describe('expandStatusQuotes()', () => {
{ type: 'STATUS_QUOTES_EXPAND_REQUEST', statusId },
{ type: 'POLLS_IMPORT', polls: [] },
{ type: 'ACCOUNTS_IMPORT', accounts: [status.account] },
{ type: 'STATUSES_IMPORT', statuses: [status], expandSpoilers: false },
{ type: 'STATUSES_IMPORT', statuses: [status] },
{ type: 'STATUS_QUOTES_EXPAND_SUCCESS', statusId, statuses: [status], next: null },
];
await store.dispatch(expandStatusQuotes(statusId));

View file

@ -297,7 +297,6 @@ export interface IMediaGallery {
defaultWidth?: number;
cacheWidth?: (width: number) => void;
visible?: boolean;
onToggleVisibility?: () => void;
displayMedia?: string;
compact?: boolean;
className?: string;

View file

@ -6,8 +6,6 @@ import { useHistory } from 'react-router-dom';
import StatusMedia from 'soapbox/components/status-media';
import { Stack } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account-container';
import { useSettings } from 'soapbox/hooks';
import { defaultMediaVisibility } from 'soapbox/utils/status';
import EventPreview from './event-preview';
import OutlineBox from './outline-box';
@ -36,11 +34,8 @@ const QuotedStatus: React.FC<IQuotedStatus> = ({ status, onCancel, compose }) =>
const intl = useIntl();
const history = useHistory();
const { displayMedia } = useSettings();
const overlay = useRef<HTMLDivElement>(null);
const [showMedia, setShowMedia] = useState<boolean>(defaultMediaVisibility(status, displayMedia));
const [minHeight, setMinHeight] = useState(208);
useEffect(() => {
@ -71,10 +66,6 @@ const QuotedStatus: React.FC<IQuotedStatus> = ({ status, onCancel, compose }) =>
}
};
const handleToggleMediaVisibility = () => {
setShowMedia(!showMedia);
};
if (!status) {
return null;
}
@ -116,16 +107,12 @@ const QuotedStatus: React.FC<IQuotedStatus> = ({ status, onCancel, compose }) =>
{status.event ? <EventPreview status={status} hideAction /> : (
<Stack
className='relative z-0'
style={{ minHeight: status.hidden ? Math.max(minHeight, 208) + 12 : undefined }}
style={{ minHeight: status.sensitive ? Math.max(minHeight, 208) + 12 : undefined }}
>
{(status.hidden) && (
<SensitiveContentOverlay
status={status}
visible={showMedia}
onToggleVisibility={handleToggleMediaVisibility}
ref={overlay}
/>
)}
<SensitiveContentOverlay
status={status}
ref={overlay}
/>
<Stack space={4}>
<StatusContent
@ -136,12 +123,7 @@ const QuotedStatus: React.FC<IQuotedStatus> = ({ status, onCancel, compose }) =>
{status.quote && <QuotedStatusIndicator statusId={status.quote as string} />}
{status.media_attachments.size > 0 && (
<StatusMedia
status={status}
muted={compose}
showMedia={showMedia}
onToggleVisibility={handleToggleMediaVisibility}
/>
<StatusMedia status={status} muted={compose} />
)}
</Stack>
</Stack>

View file

@ -5,7 +5,8 @@ import AttachmentThumbs from 'soapbox/components/attachment-thumbs';
import PreviewCard from 'soapbox/components/preview-card';
import PlaceholderCard from 'soapbox/features/placeholder/components/placeholder-card';
import { MediaGallery, Video, Audio } from 'soapbox/features/ui/util/async-components';
import { useAppDispatch } from 'soapbox/hooks';
import { useAppDispatch, useSettings } from 'soapbox/hooks';
import { defaultMediaVisibility } from 'soapbox/utils/status';
import type { List as ImmutableList } from 'immutable';
import type { Status, Attachment } from 'soapbox/types/entities';
@ -19,8 +20,6 @@ interface IStatusMedia {
onClick?: () => void;
/** Whether or not the media is concealed behind a NSFW banner. */
showMedia?: boolean;
/** Callback when visibility is toggled (eg clicked through NSFW). */
onToggleVisibility?: () => void;
}
/** Render media attachments for a status. */
@ -28,10 +27,12 @@ const StatusMedia: React.FC<IStatusMedia> = ({
status,
muted = false,
onClick,
showMedia = true,
onToggleVisibility = () => { },
showMedia,
}) => {
const dispatch = useAppDispatch();
const { displayMedia } = useSettings();
const visible = showMedia || (status.hidden === null ? defaultMediaVisibility(status, displayMedia) : status.hidden);
const size = status.media_attachments.size;
const firstAttachment = status.media_attachments.first();
@ -75,7 +76,7 @@ const StatusMedia: React.FC<IStatusMedia> = ({
alt={video.description}
aspectRatio={Number(video.meta.getIn(['original', 'aspect']))}
height={285}
visible={showMedia}
visible={visible}
inline
/>
</Suspense>
@ -105,8 +106,7 @@ const StatusMedia: React.FC<IStatusMedia> = ({
sensitive={status.sensitive}
height={285}
onOpenMedia={openMedia}
visible={showMedia}
onToggleVisibility={onToggleVisibility}
visible={visible}
/>
</Suspense>
);

View file

@ -34,11 +34,5 @@ describe('<Status />', () => {
render(<Status status={status} />, undefined, state);
expect(screen.getByTestId('status-action-bar')).toBeInTheDocument();
});
it('is not rendered if status is under review', () => {
const inReviewStatus = status.set('visibility', 'self');
render(<Status status={inReviewStatus as ReducerStatus} />, undefined, state);
expect(screen.queryAllByTestId('status-action-bar')).toHaveLength(0);
});
});
});

View file

@ -12,7 +12,7 @@ import AccountContainer from 'soapbox/containers/account-container';
import QuotedStatus from 'soapbox/features/status/containers/quoted-status-container';
import { HotKeys } from 'soapbox/features/ui/components/hotkeys';
import { useAppDispatch, useSettings } from 'soapbox/hooks';
import { defaultMediaVisibility, textForScreenReader, getActualStatus } from 'soapbox/utils/status';
import { textForScreenReader, getActualStatus } from 'soapbox/utils/status';
import EventPreview from './event-preview';
import StatusActionBar from './status-action-bar';
@ -77,12 +77,11 @@ const Status: React.FC<IStatus> = (props) => {
const history = useHistory();
const dispatch = useAppDispatch();
const { displayMedia, boostModal } = useSettings();
const { boostModal } = useSettings();
const didShowCard = useRef(false);
const node = useRef<HTMLDivElement>(null);
const overlay = useRef<HTMLDivElement>(null);
const [showMedia, setShowMedia] = useState<boolean>(defaultMediaVisibility(status, displayMedia));
const [minHeight, setMinHeight] = useState(208);
const actualStatus = getActualStatus(status);
@ -97,20 +96,12 @@ const Status: React.FC<IStatus> = (props) => {
didShowCard.current = Boolean(!muted && !hidden && status?.card);
}, []);
useEffect(() => {
setShowMedia(defaultMediaVisibility(status, displayMedia));
}, [status.id]);
useEffect(() => {
if (overlay.current) {
setMinHeight(overlay.current.getBoundingClientRect().height);
}
}, [overlay.current]);
const handleToggleMediaVisibility = (): void => {
setShowMedia(!showMedia);
};
const handleClick = (e?: React.MouseEvent): void => {
e?.stopPropagation();
@ -188,12 +179,8 @@ const Status: React.FC<IStatus> = (props) => {
}
};
const handleHotkeyToggleHidden = (): void => {
dispatch(toggleStatusHidden(actualStatus));
};
const handleHotkeyToggleSensitive = (): void => {
handleToggleMediaVisibility();
dispatch(toggleStatusHidden(actualStatus));
};
const handleHotkeyReact = (): void => {
@ -377,14 +364,11 @@ const Status: React.FC<IStatus> = (props) => {
openProfile: handleHotkeyOpenProfile,
moveUp: handleHotkeyMoveUp,
moveDown: handleHotkeyMoveDown,
toggleHidden: handleHotkeyToggleHidden,
toggleSensitive: handleHotkeyToggleSensitive,
openMedia: handleHotkeyOpenMedia,
react: handleHotkeyReact,
};
const isUnderReview = actualStatus.visibility === 'self';
const isSensitive = actualStatus.hidden;
const isSoftDeleted = status.tombstone?.reason === 'deleted';
if (isSoftDeleted) {
@ -439,16 +423,12 @@ const Status: React.FC<IStatus> = (props) => {
<Stack
className='relative z-0'
style={{ minHeight: isUnderReview || isSensitive ? Math.max(minHeight, 208) + 12 : undefined }}
style={{ minHeight: actualStatus.sensitive ? Math.max(minHeight, 208) + 12 : undefined }}
>
{(isUnderReview || isSensitive) && (
<SensitiveContentOverlay
status={status}
visible={showMedia}
onToggleVisibility={handleToggleMediaVisibility}
ref={overlay}
/>
)}
<SensitiveContentOverlay
status={actualStatus}
ref={overlay}
/>
{actualStatus.event ? <EventPreview className='shadow-xl' status={actualStatus} /> : (
<Stack space={4}>
@ -467,8 +447,6 @@ const Status: React.FC<IStatus> = (props) => {
status={actualStatus}
muted={muted}
onClick={handleClick}
showMedia={showMedia}
onToggleVisibility={handleToggleMediaVisibility}
/>
{quote}
@ -478,7 +456,7 @@ const Status: React.FC<IStatus> = (props) => {
)}
</Stack>
{(!hideActionBar && !isUnderReview) && (
{!hideActionBar && (
<div className='pt-4'>
<StatusActionBar status={actualStatus} fromBookmarks={fromBookmarks} />
</div>

View file

@ -38,57 +38,6 @@ describe('<SensitiveContentOverlay />', () => {
});
});
describe('when the Status is marked as in review', () => {
beforeEach(() => {
status = normalizeStatus({ visibility: 'self', sensitive: false }) as ReducerStatus;
});
it('displays the "Under review" warning', () => {
render(<SensitiveContentOverlay status={status} />);
expect(screen.getByTestId('sensitive-overlay')).toHaveTextContent('Content Under Review');
});
it('allows the user to delete the status', () => {
render(<SensitiveContentOverlay status={status} />);
expect(screen.getByTestId('icon-button')).toBeInTheDocument();
});
it('can be toggled', () => {
render(<SensitiveContentOverlay status={status} />);
fireEvent.click(screen.getByTestId('button'));
expect(screen.getByTestId('sensitive-overlay')).not.toHaveTextContent('Content Under Review');
expect(screen.getByTestId('sensitive-overlay')).toHaveTextContent('Hide');
fireEvent.click(screen.getByTestId('button'));
expect(screen.getByTestId('sensitive-overlay')).toHaveTextContent('Content Under Review');
expect(screen.getByTestId('sensitive-overlay')).not.toHaveTextContent('Hide');
});
});
describe('when the Status is marked as in review and sensitive', () => {
beforeEach(() => {
status = normalizeStatus({ visibility: 'self', sensitive: true }) as ReducerStatus;
});
it('displays the "Under review" warning', () => {
render(<SensitiveContentOverlay status={status} />);
expect(screen.getByTestId('sensitive-overlay')).toHaveTextContent('Content Under Review');
});
it('can be toggled', () => {
render(<SensitiveContentOverlay status={status} />);
fireEvent.click(screen.getByTestId('button'));
expect(screen.getByTestId('sensitive-overlay')).not.toHaveTextContent('Content Under Review');
expect(screen.getByTestId('sensitive-overlay')).toHaveTextContent('Hide');
fireEvent.click(screen.getByTestId('button'));
expect(screen.getByTestId('sensitive-overlay')).toHaveTextContent('Content Under Review');
expect(screen.getByTestId('sensitive-overlay')).not.toHaveTextContent('Hide');
});
});
describe('when the Status is marked as sensitive and displayMedia set to "show_all"', () => {
let store: any;
@ -100,12 +49,6 @@ describe('<SensitiveContentOverlay />', () => {
}));
});
it('displays the "Under review" warning', () => {
render(<SensitiveContentOverlay status={status} />, undefined, store);
expect(screen.getByTestId('sensitive-overlay')).not.toHaveTextContent('Sensitive content');
expect(screen.getByTestId('sensitive-overlay')).toHaveTextContent('Hide');
});
it('can be toggled', () => {
render(<SensitiveContentOverlay status={status} />, undefined, store);

View file

@ -1,13 +1,10 @@
import clsx from 'clsx';
import React, { useEffect, useMemo, useState } from 'react';
import React from 'react';
import { defineMessages, useIntl } from 'react-intl';
import { openModal } from 'soapbox/actions/modals';
import { deleteStatus } from 'soapbox/actions/statuses';
import { useAppDispatch, useOwnAccount, useSettings, useSoapboxConfig } from 'soapbox/hooks';
import { defaultMediaVisibility } from 'soapbox/utils/status';
import { toggleStatusHidden } from 'soapbox/actions/statuses';
import { useAppDispatch, useSettings } from 'soapbox/hooks';
import DropdownMenu from '../dropdown-menu';
import { Button, HStack, Text } from '../ui';
import type { Status as StatusEntity } from 'soapbox/types/entities';
@ -19,73 +16,36 @@ const messages = defineMessages({
deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this post?' },
hide: { id: 'moderation_overlay.hide', defaultMessage: 'Hide content' },
sensitiveTitle: { id: 'status.sensitive_warning', defaultMessage: 'Sensitive content' },
underReviewTitle: { id: 'moderation_overlay.title', defaultMessage: 'Content Under Review' },
underReviewSubtitle: { id: 'moderation_overlay.subtitle', defaultMessage: 'This Post has been sent to Moderation for review and is only visible to you. If you believe this is an error please contact Support.' },
sensitiveSubtitle: { id: 'status.sensitive_warning.subtitle', defaultMessage: 'This content may not be suitable for all audiences.' },
contact: { id: 'moderation_overlay.contact', defaultMessage: 'Contact' },
show: { id: 'moderation_overlay.show', defaultMessage: 'Show Content' },
});
interface ISensitiveContentOverlay {
status: StatusEntity;
onToggleVisibility?(): void;
visible?: boolean;
}
const SensitiveContentOverlay = React.forwardRef<HTMLDivElement, ISensitiveContentOverlay>((props, ref) => {
const { onToggleVisibility, status } = props;
const { status } = props;
const { account } = useOwnAccount();
const dispatch = useAppDispatch();
const intl = useIntl();
const { displayMedia, deleteModal } = useSettings();
const { links } = useSoapboxConfig();
const { displayMedia } = useSettings();
const isUnderReview = status.visibility === 'self';
const isOwnStatus = status.getIn(['account', 'id']) === account?.id;
let visible = !status.sensitive;
const [visible, setVisible] = useState<boolean>(defaultMediaVisibility(status, displayMedia));
if (status.hidden !== null) visible = status.hidden;
else if (displayMedia === 'show_all') visible = true;
else if (displayMedia === 'hide_all' && status.media_attachments.size) visible = false;
const showHideButton = status.sensitive || (status.media_attachments.size && displayMedia === 'hide_all');
const toggleVisibility = (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
if (onToggleVisibility) {
onToggleVisibility();
} else {
setVisible((prevValue) => !prevValue);
}
dispatch(toggleStatusHidden(status));
};
const handleDeleteStatus = () => {
if (!deleteModal) {
dispatch(deleteStatus(status.id, false));
} else {
dispatch(openModal('CONFIRM', {
icon: require('@tabler/icons/outline/trash.svg'),
heading: intl.formatMessage(messages.deleteHeading),
message: intl.formatMessage(messages.deleteMessage),
confirm: intl.formatMessage(messages.deleteConfirm),
onConfirm: () => dispatch(deleteStatus(status.id, false)),
}));
}
};
const menu = useMemo(() => {
return [
{
text: intl.formatMessage(messages.delete),
action: handleDeleteStatus,
icon: require('@tabler/icons/outline/trash.svg'),
destructive: true,
},
];
}, []);
useEffect(() => {
if (typeof props.visible !== 'undefined') {
setVisible(!!props.visible);
}
}, [props.visible]);
if (visible && !showHideButton) return null;
return (
<div
@ -109,11 +69,11 @@ const SensitiveContentOverlay = React.forwardRef<HTMLDivElement, ISensitiveConte
<div className='mx-auto w-3/4 space-y-4 text-center' ref={ref}>
<div className='space-y-1'>
<Text theme='white' weight='semibold'>
{intl.formatMessage(isUnderReview ? messages.underReviewTitle : messages.sensitiveTitle)}
{intl.formatMessage(messages.sensitiveTitle)}
</Text>
<Text theme='white' size='sm' weight='medium'>
{intl.formatMessage(isUnderReview ? messages.underReviewSubtitle : messages.sensitiveSubtitle)}
{intl.formatMessage(messages.sensitiveSubtitle)}
</Text>
{status.spoiler_text && (
@ -126,27 +86,6 @@ const SensitiveContentOverlay = React.forwardRef<HTMLDivElement, ISensitiveConte
</div>
<HStack alignItems='center' justifyContent='center' space={2}>
{isUnderReview ? (
<>
{links.get('support') && (
<a
href={links.get('support')}
target='_blank'
onClick={(event) => event.stopPropagation()}
>
<Button
type='button'
theme='outline'
size='sm'
icon={require('@tabler/icons/outline/headset.svg')}
>
{intl.formatMessage(messages.contact)}
</Button>
</a>
)}
</>
) : null}
<Button
type='button'
theme='outline'
@ -156,13 +95,6 @@ const SensitiveContentOverlay = React.forwardRef<HTMLDivElement, ISensitiveConte
>
{intl.formatMessage(messages.show)}
</Button>
{(isUnderReview && isOwnStatus) ? (
<DropdownMenu
items={menu}
src={require('@tabler/icons/outline/dots.svg')}
/>
) : null}
</HStack>
</div>
</div>

View file

@ -49,7 +49,7 @@ const ReportStatus: React.FC<IReportStatus> = ({ status }) => {
<HStack space={2} alignItems='start'>
<Stack space={2} className='overflow-hidden' grow>
<StatusContent status={status} />
<StatusMedia status={status} />
<StatusMedia status={status} showMedia />
</Stack>
<div className='flex-none'>

View file

@ -9,9 +9,8 @@ import StatusMedia from 'soapbox/components/status-media';
import TranslateButton from 'soapbox/components/translate-button';
import { HStack, Icon, Stack, Text } from 'soapbox/components/ui';
import QuotedStatus from 'soapbox/features/status/containers/quoted-status-container';
import { useAppDispatch, useAppSelector, useSettings, useSoapboxConfig } from 'soapbox/hooks';
import { useAppDispatch, useAppSelector, useSoapboxConfig } from 'soapbox/hooks';
import { makeGetStatus } from 'soapbox/selectors';
import { defaultMediaVisibility } from 'soapbox/utils/status';
import type { Status as StatusEntity } from 'soapbox/types/entities';
@ -28,10 +27,8 @@ const EventInformation: React.FC<IEventInformation> = ({ params }) => {
const status = useAppSelector(state => getStatus(state, { id: params.statusId })) as StatusEntity;
const { tileServer } = useSoapboxConfig();
const { displayMedia } = useSettings();
const [isLoaded, setIsLoaded] = useState<boolean>(!!status);
const [showMedia, setShowMedia] = useState<boolean>(defaultMediaVisibility(status, displayMedia));
useEffect(() => {
dispatch(fetchStatus(params.statusId)).then(() => {
@ -39,14 +36,8 @@ const EventInformation: React.FC<IEventInformation> = ({ params }) => {
}).catch(() => {
setIsLoaded(true);
});
setShowMedia(defaultMediaVisibility(status, displayMedia));
}, [params.statusId]);
const handleToggleMediaVisibility = () => {
setShowMedia(!showMedia);
};
const handleShowMap: React.MouseEventHandler<HTMLAnchorElement> = (e) => {
e.preventDefault();
@ -195,11 +186,7 @@ const EventInformation: React.FC<IEventInformation> = ({ params }) => {
</Stack>
)}
<StatusMedia
status={status}
showMedia={showMedia}
onToggleVisibility={handleToggleMediaVisibility}
/>
<StatusMedia status={status} />
{status.quote && status.pleroma.get('quote_visible', true) && (
<QuotedStatus statusId={status.quote as string} />

View file

@ -6,7 +6,7 @@ import { mentionCompose } from 'soapbox/actions/compose';
import { reblog, favourite, unreblog, unfavourite } from 'soapbox/actions/interactions';
import { openModal } from 'soapbox/actions/modals';
import { getSettings } from 'soapbox/actions/settings';
import { hideStatus, revealStatus } from 'soapbox/actions/statuses';
import { toggleStatusHidden } from 'soapbox/actions/statuses';
import Icon from 'soapbox/components/icon';
import { HStack, Text, Emoji } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account-container';
@ -182,7 +182,7 @@ const Notification: React.FC<INotification> = (props) => {
openProfile: handleOpenProfile,
moveUp: handleMoveUp,
moveDown: handleMoveDown,
toggleHidden: handleHotkeyToggleHidden,
toggleSensitive: handleHotkeyToggleSensitive,
});
const handleOpen = () => {
@ -236,13 +236,9 @@ const Notification: React.FC<INotification> = (props) => {
}
}, [status]);
const handleHotkeyToggleHidden = useCallback((e?: KeyboardEvent) => {
const handleHotkeyToggleSensitive = useCallback((e?: KeyboardEvent) => {
if (status && typeof status === 'object') {
if (status.hidden) {
dispatch(revealStatus(status.id));
} else {
dispatch(hideStatus(status.id));
}
dispatch(toggleStatusHidden(status));
}
}, [status]);

View file

@ -78,7 +78,7 @@ const languages = {
const messages = defineMessages({
heading: { id: 'column.preferences', defaultMessage: 'Preferences' },
displayPostsDefault: { id: 'preferences.fields.display_media.default', defaultMessage: 'Hide posts marked as sensitive' },
displayPostsHideAll: { id: 'preferences.fields.display_media.hide_all', defaultMessage: 'Always hide posts' },
displayPostsHideAll: { id: 'preferences.fields.display_media.hide_all', defaultMessage: 'Always hide media posts' },
displayPostsShowAll: { id: 'preferences.fields.display_media.show_all', defaultMessage: 'Always show posts' },
privacy_public: { id: 'preferences.options.privacy_public', defaultMessage: 'Public' },
privacy_unlisted: { id: 'preferences.options.privacy_unlisted', defaultMessage: 'Unlisted' },
@ -201,10 +201,6 @@ const Preferences = () => {
<SettingToggle settings={settings} settingPath={['autoPlayGif']} onChange={onToggleChange} />
</ListItem>
{features.spoilers && <ListItem label={<FormattedMessage id='preferences.fields.expand_spoilers_label' defaultMessage='Always expand posts marked with content warnings' />}>
<SettingToggle settings={settings} settingPath={['expandSpoilers']} onChange={onToggleChange} />
</ListItem>}
<ListItem label={<FormattedMessage id='preferences.fields.autoload_timelines_label' defaultMessage='Automatically load new posts when scrolled to the top of the page' />}>
<SettingToggle settings={settings} settingPath={['autoloadTimelines']} onChange={onToggleChange} />
</ListItem>

View file

@ -19,17 +19,13 @@ import type { Group, Status as StatusEntity } from 'soapbox/types/entities';
interface IDetailedStatus {
status: StatusEntity;
showMedia?: boolean;
withMedia?: boolean;
onOpenCompareHistoryModal: (status: StatusEntity) => void;
onToggleMediaVisibility: () => void;
}
const DetailedStatus: React.FC<IDetailedStatus> = ({
status,
onOpenCompareHistoryModal,
onToggleMediaVisibility,
showMedia,
withMedia = true,
}) => {
const intl = useIntl();
@ -89,9 +85,6 @@ const DetailedStatus: React.FC<IDetailedStatus> = ({
const { account } = actualStatus;
if (!account || typeof account !== 'object') return null;
const isUnderReview = actualStatus.visibility === 'self';
const isSensitive = actualStatus.hidden;
let statusTypeIcon = null;
let quote;
@ -133,16 +126,12 @@ const DetailedStatus: React.FC<IDetailedStatus> = ({
<Stack
className='relative z-0'
style={{ minHeight: isUnderReview || isSensitive ? Math.max(minHeight, 208) + 12 : undefined }}
style={{ minHeight: actualStatus.sensitive ? Math.max(minHeight, 208) + 12 : undefined }}
>
{(isUnderReview || isSensitive) && (
<SensitiveContentOverlay
status={status}
visible={showMedia}
onToggleVisibility={onToggleMediaVisibility}
ref={overlay}
/>
)}
<SensitiveContentOverlay
status={status}
ref={overlay}
/>
<Stack space={4}>
<StatusContent
@ -155,11 +144,7 @@ const DetailedStatus: React.FC<IDetailedStatus> = ({
{(withMedia && (quote || actualStatus.card || actualStatus.media_attachments.size > 0)) && (
<Stack space={4}>
<StatusMedia
status={actualStatus}
showMedia={showMedia}
onToggleVisibility={onToggleMediaVisibility}
/>
<StatusMedia status={actualStatus} />
{quote}
</Stack>

View file

@ -1,7 +1,7 @@
import { createSelector } from '@reduxjs/toolkit';
import clsx from 'clsx';
import { List as ImmutableList, OrderedSet as ImmutableOrderedSet } from 'immutable';
import React, { useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef } from 'react';
import { useIntl } from 'react-intl';
import { useHistory } from 'react-router-dom';
import { type VirtuosoHandle } from 'react-virtuoso';
@ -10,7 +10,7 @@ import { mentionCompose, replyCompose } from 'soapbox/actions/compose';
import { favourite, reblog, unfavourite, unreblog } from 'soapbox/actions/interactions';
import { openModal } from 'soapbox/actions/modals';
import { getSettings } from 'soapbox/actions/settings';
import { hideStatus, revealStatus } from 'soapbox/actions/statuses';
import { toggleStatusHidden } from 'soapbox/actions/statuses';
import ScrollableList from 'soapbox/components/scrollable-list';
import StatusActionBar from 'soapbox/components/status-action-bar';
import Tombstone from 'soapbox/components/tombstone';
@ -18,10 +18,10 @@ import { Stack } from 'soapbox/components/ui';
import PlaceholderStatus from 'soapbox/features/placeholder/components/placeholder-status';
import { HotKeys } from 'soapbox/features/ui/components/hotkeys';
import PendingStatus from 'soapbox/features/ui/components/pending-status';
import { useAppDispatch, useAppSelector, useSettings } from 'soapbox/hooks';
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
import { RootState } from 'soapbox/store';
import { type Account, type Status } from 'soapbox/types/entities';
import { defaultMediaVisibility, textForScreenReader } from 'soapbox/utils/status';
import { textForScreenReader } from 'soapbox/utils/status';
import DetailedStatus from './detailed-status';
import ThreadStatus from './thread-status';
@ -90,9 +90,6 @@ const Thread = (props: IThread) => {
const dispatch = useAppDispatch();
const history = useHistory();
const intl = useIntl();
const { displayMedia } = useSettings();
const isUnderReview = status?.visibility === 'self';
const { ancestorsIds, descendantsIds } = useAppSelector((state) => {
let ancestorsIds = ImmutableOrderedSet<string>();
@ -116,16 +113,10 @@ const Thread = (props: IThread) => {
let initialTopMostItemIndex = ancestorsIds.size;
if (!useWindowScroll && initialTopMostItemIndex !== 0) initialTopMostItemIndex = ancestorsIds.size + 1;
const [showMedia, setShowMedia] = useState<boolean>(status?.visibility === 'self' ? false : defaultMediaVisibility(status, displayMedia));
const node = useRef<HTMLDivElement>(null);
const statusRef = useRef<HTMLDivElement>(null);
const scroller = useRef<VirtuosoHandle>(null);
const handleToggleMediaVisibility = () => {
setShowMedia(!showMedia);
};
const handleHotkeyReact = () => {
if (statusRef.current) {
const firstEmoji: HTMLButtonElement | null = statusRef.current.querySelector('.emoji-react-selector .emoji-react-selector__emoji');
@ -178,14 +169,6 @@ const Thread = (props: IThread) => {
}
};
const handleToggleHidden = (status: Status) => {
if (status.hidden) {
dispatch(revealStatus(status.id));
} else {
dispatch(hideStatus(status.id));
}
};
const handleHotkeyMoveUp = () => {
handleMoveUp(status!.id);
};
@ -218,12 +201,8 @@ const Thread = (props: IThread) => {
history.push(`/@${status!.getIn(['account', 'acct'])}`);
};
const handleHotkeyToggleHidden = () => {
handleToggleHidden(status!);
};
const handleHotkeyToggleSensitive = () => {
handleToggleMediaVisibility();
dispatch(toggleStatusHidden(status));
};
const handleMoveUp = (id: string) => {
@ -317,11 +296,6 @@ const Thread = (props: IThread) => {
});
};
// Reset media visibility if status changes.
useEffect(() => {
setShowMedia(status?.visibility === 'self' ? false : defaultMediaVisibility(status, displayMedia));
}, [status.id]);
// Scroll focused status into view when thread updates.
useEffect(() => {
scroller.current?.scrollToIndex({
@ -351,7 +325,6 @@ const Thread = (props: IThread) => {
boost: handleHotkeyBoost,
mention: handleHotkeyMention,
openProfile: handleHotkeyOpenProfile,
toggleHidden: handleHotkeyToggleHidden,
toggleSensitive: handleHotkeyToggleSensitive,
openMedia: handleHotkeyOpenMedia,
react: handleHotkeyReact,
@ -370,24 +343,18 @@ const Thread = (props: IThread) => {
<DetailedStatus
status={status}
showMedia={showMedia}
withMedia={withMedia}
onToggleMediaVisibility={handleToggleMediaVisibility}
onOpenCompareHistoryModal={handleOpenCompareHistoryModal}
/>
{!isUnderReview ? (
<>
<hr className='-mx-4 mb-2 max-w-[100vw] border-t-2 black:border-t dark:border-gray-800' />
<hr className='-mx-4 mb-2 max-w-[100vw] border-t-2 black:border-t dark:border-gray-800' />
<StatusActionBar
status={status}
expandable={false}
space='lg'
withLabels
/>
</>
) : null}
<StatusActionBar
status={status}
expandable={false}
space='lg'
withLabels
/>
</div>
</HotKeys>

View file

@ -33,8 +33,7 @@ const keyMap = {
goToBlocked: 'g b',
goToMuted: 'g m',
goToRequests: 'g r',
toggleHidden: 'x',
toggleSensitive: 'h',
toggleSensitive: ['h', 'x'],
openMedia: 'a',
};

View file

@ -1017,11 +1017,8 @@
"missing_description_modal.text": "You have not entered a description for all attachments. Continue anyway?",
"missing_indicator.label": "Not found",
"missing_indicator.sublabel": "This resource could not be found",
"moderation_overlay.contact": "Contact",
"moderation_overlay.hide": "Hide content",
"moderation_overlay.show": "Show Content",
"moderation_overlay.subtitle": "This Post has been sent to Moderation for review and is only visible to you. If you believe this is an error please contact Support.",
"moderation_overlay.title": "Content Under Review",
"mute_modal.auto_expire": "Automatically expire mute?",
"mute_modal.duration": "Duration",
"mute_modal.hide_notifications": "Hide notifications from this user?",
@ -1176,9 +1173,8 @@
"preferences.fields.demo_hint": "Use the default Soapbox logo and color scheme. Useful for taking screenshots.",
"preferences.fields.demo_label": "Demo mode",
"preferences.fields.display_media.default": "Hide posts marked as sensitive",
"preferences.fields.display_media.hide_all": "Always hide posts",
"preferences.fields.display_media.hide_all": "Always hide media posts",
"preferences.fields.display_media.show_all": "Always show posts",
"preferences.fields.expand_spoilers_label": "Always expand posts marked with content warnings",
"preferences.fields.language_label": "Display Language",
"preferences.fields.media_display_label": "Sensitive content",
"preferences.fields.missing_description_modal_label": "Show confirmation dialog before sending a post without media descriptions",

View file

@ -20,7 +20,7 @@ import { maybeFromJS } from 'soapbox/utils/normalizers';
import type { Account, Attachment, Card, Emoji, Group, Mention, Poll, EmbeddedEntity, EmojiReaction } from 'soapbox/types/entities';
export type StatusApprovalStatus = 'pending' | 'approval' | 'rejected';
export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' | 'self' | 'group';
export type StatusVisibility = 'public' | 'unlisted' | 'private' | 'direct' | 'group';
export type EventJoinMode = 'free' | 'restricted' | 'invite';
export type EventJoinState = 'pending' | 'reject' | 'accept';
@ -88,7 +88,7 @@ export const StatusRecord = ImmutableRecord({
// Internal fields
contentHtml: '',
expectsCard: false,
hidden: false,
hidden: null as boolean | null,
search_index: '',
showFiltered: true,
spoilerHtml: '',

View file

@ -106,14 +106,6 @@ describe('statuses reducer', () => {
expect(hidden).toBe(true);
});
it('expands CWs when expandSpoilers is enabled', async () => {
const status = await import('soapbox/__fixtures__/status-cw.json');
const action = { type: STATUS_IMPORT, status, expandSpoilers: true };
const hidden = reducer(undefined, action).getIn(['107831528995252317', 'hidden']);
expect(hidden).toBe(false);
});
it('parses custom emojis', async () => {
const status = await import('soapbox/__fixtures__/status-custom-emoji.json');
const action = { type: STATUS_IMPORT, status };

View file

@ -104,7 +104,6 @@ const buildSearchContent = (status: StatusRecord): string => {
export const calculateStatus = (
status: StatusRecord,
oldStatus?: StatusRecord,
expandSpoilers: boolean = false,
): StatusRecord => {
if (oldStatus && oldStatus.content === status.content && oldStatus.spoiler_text === status.spoiler_text) {
return status.merge({
@ -122,7 +121,6 @@ export const calculateStatus = (
search_index: domParser.parseFromString(searchContent, 'text/html').documentElement.textContent || '',
contentHtml: DOMPurify.sanitize(stripCompatibilityFeatures(emojify(status.content, emojiMap)), { USE_PROFILES: { html: true } }),
spoilerHtml: DOMPurify.sanitize(emojify(escapeTextContentForBrowser(spoilerText), emojiMap), { USE_PROFILES: { html: true } }),
hidden: expandSpoilers ? false : spoilerText.length > 0 || status.sensitive,
});
}
};
@ -153,22 +151,22 @@ const fixQuote = (status: StatusRecord, oldStatus?: StatusRecord): StatusRecord
}
};
const fixStatus = (state: State, status: APIEntity, expandSpoilers: boolean): ReducerStatus => {
const fixStatus = (state: State, status: APIEntity): ReducerStatus => {
const oldStatus = state.get(status.id);
return normalizeStatus(status).withMutations(status => {
fixTranslation(status, oldStatus);
fixQuote(status, oldStatus);
calculateStatus(status, oldStatus, expandSpoilers);
calculateStatus(status, oldStatus);
minifyStatus(status);
}) as ReducerStatus;
};
const importStatus = (state: State, status: APIEntity, expandSpoilers: boolean): State =>
state.set(status.id, fixStatus(state, status, expandSpoilers));
const importStatus = (state: State, status: APIEntity): State =>
state.set(status.id, fixStatus(state, status));
const importStatuses = (state: State, statuses: APIEntities, expandSpoilers: boolean): State =>
state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status, expandSpoilers)));
const importStatuses = (state: State, statuses: APIEntities): State =>
state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status)));
const deleteStatus = (state: State, id: string, references: Array<string>) => {
references.forEach(ref => {
@ -271,9 +269,9 @@ const initialState: State = ImmutableMap();
export default function statuses(state = initialState, action: AnyAction): State {
switch (action.type) {
case STATUS_IMPORT:
return importStatus(state, action.status, action.expandSpoilers);
return importStatus(state, action.status);
case STATUSES_IMPORT:
return importStatuses(state, action.statuses, action.expandSpoilers);
return importStatuses(state, action.statuses);
case STATUS_CREATE_REQUEST:
return action.editing ? state : incrementReplyCount(state, action.params);
case STATUS_CREATE_FAIL:

View file

@ -15,7 +15,6 @@ const settingsSchema = z.object({
underlineLinks: z.boolean().catch(false),
autoPlayGif: z.boolean().catch(true),
displayMedia: z.enum(['default', 'hide_all', 'show_all']).catch('default'),
expandSpoilers: z.boolean().catch(false),
preserveSpoilers: z.boolean().catch(false),
unfollowModal: z.boolean().catch(false),
boostModal: z.boolean().catch(false),

View file

@ -111,7 +111,7 @@ const transformStatus = <T extends TransformableStatus>({ pleroma, ...status }:
expectsCard: false,
event: pleroma?.event,
filtered: [],
hidden: false,
hidden: null as boolean | null,
pleroma: pleroma ? (() => {
const { event, ...rest } = pleroma;
return rest;

View file

@ -11,12 +11,6 @@ export const defaultMediaVisibility = <T extends { reblog: T | string | null } &
if (!status) return false;
status = getActualStatus(status);
const isUnderReview = status.visibility === 'self';
if (isUnderReview) {
return false;
}
return (displayMedia !== 'hide_all' && !status.sensitive || displayMedia === 'show_all');
};