diff --git a/app/javascript/mastodon/features/status/components/card.jsx b/app/javascript/mastodon/features/status/components/card.jsx
index ee1fbe0f8fe..c13a575c163 100644
--- a/app/javascript/mastodon/features/status/components/card.jsx
+++ b/app/javascript/mastodon/features/status/components/card.jsx
@@ -14,11 +14,12 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import DescriptionIcon from '@/material-icons/400-24px/description-fill.svg?react';
import OpenInNewIcon from '@/material-icons/400-24px/open_in_new.svg?react';
import PlayArrowIcon from '@/material-icons/400-24px/play_arrow-fill.svg?react';
+import VisibilityOffIcon from '@/material-icons/400-24px/visibility_off.svg?react';
import { Blurhash } from 'mastodon/components/blurhash';
import { Icon } from 'mastodon/components/icon';
import { MoreFromAuthor } from 'mastodon/components/more_from_author';
import { RelativeTimestamp } from 'mastodon/components/relative_timestamp';
-import { useBlurhash } from 'mastodon/initial_state';
+import { displayMedia, useBlurhash } from 'mastodon/initial_state';
const IDNA_PREFIX = 'xn--';
@@ -64,12 +65,14 @@ export default class Card extends PureComponent {
card: ImmutablePropTypes.map,
onOpenMedia: PropTypes.func.isRequired,
sensitive: PropTypes.bool,
+ visible: PropTypes.bool,
};
state = {
previewLoaded: false,
embedded: false,
revealed: !this.props.sensitive,
+ visible: this.props.visible !== undefined ? this.props.visible : (displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all'),
};
UNSAFE_componentWillReceiveProps (nextProps) {
@@ -80,6 +83,12 @@ export default class Card extends PureComponent {
if (this.props.sensitive !== nextProps.sensitive) {
this.setState({ revealed: !nextProps.sensitive });
}
+
+ if (nextProps.visible === undefined) {
+ this.setState({ visible: displayMedia !== 'hide_all' && !nextProps.sensitive || displayMedia === 'show_all' });
+ } else if (!Immutable.is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
+ this.setState({ visible: nextProps.visible });
+ }
}
componentDidMount () {
@@ -112,6 +121,12 @@ export default class Card extends PureComponent {
this.setState({ revealed: true });
};
+ handleOpen = (e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ this.setState({ visible: !this.state.visible });
+ };
+
renderVideo () {
const { card } = this.props;
const content = { __html: addAutoPlay(card.get('html')) };
@@ -128,7 +143,7 @@ export default class Card extends PureComponent {
render () {
const { card } = this.props;
- const { embedded, revealed } = this.state;
+ const { embedded, revealed, visible } = this.state;
if (card === null) {
return null;
@@ -165,14 +180,14 @@ export default class Card extends PureComponent {
thumbnailStyle.aspectRatio = 1;
}
- let embed;
+ let embed, spoilerButton;
let canvas = (