@ -18,6 +18,7 @@ import classNames from 'classnames';
import Icon from 'mastodon/components/icon' ;
import PollContainer from 'mastodon/containers/poll_container' ;
import { displayMedia } from '../initial_state' ;
import { is } from 'immutable' ;
// We use the component (and not the container) since we do not want
// to use the progress bar to show download progress
@ -40,6 +41,18 @@ export const textForScreenReader = (intl, status, rebloggedByText = false) => {
return values . join ( ', ' ) ;
} ;
export const defaultMediaVisibility = ( status ) => {
if ( ! status ) {
return undefined ;
}
if ( status . get ( 'reblog' , null ) !== null && typeof status . get ( 'reblog' ) === 'object' ) {
status = status . get ( 'reblog' ) ;
}
return ( displayMedia !== 'hide_all' && ! status . get ( 'sensitive' ) || displayMedia === 'show_all' ) ;
} ;
export default @ injectIntl
class Status extends ImmutablePureComponent {
@ -87,7 +100,7 @@ class Status extends ImmutablePureComponent {
] ;
state = {
showMedia : d isplayMedia !== 'hide_all' && ! this . props . status .get ( 'sensitive' ) || displayMedia === 'show_all' ,
showMedia : d efaultMediaVisibility( this . props . status ),
} ;
// Track height changes we know about to compensate scrolling
@ -103,11 +116,19 @@ class Status extends ImmutablePureComponent {
}
}
componentWillReceiveProps ( nextProps ) {
if ( ! is ( nextProps . status , this . props . status ) && nextProps . status ) {
this . setState ( { showMedia : defaultMediaVisibility ( nextProps . status ) } ) ;
}
}
// Compensate height changes
componentDidUpdate ( prevProps , prevState , snapshot ) {
const doShowCard = ! this . props . muted && ! this . props . hidden && this . props . status && this . props . status . get ( 'card' ) ;
if ( doShowCard && ! this . didShowCard ) {
this . didShowCard = true ;
if ( snapshot !== null && this . props . updateScrollBottom ) {
if ( this . node && this . node . offsetTop < snapshot . top ) {
this . props . updateScrollBottom ( snapshot . height - snapshot . top ) ;