|
|
@ -3,18 +3,24 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; |
|
|
|
import PropTypes from 'prop-types'; |
|
|
|
import PropTypes from 'prop-types'; |
|
|
|
import Avatar from './avatar'; |
|
|
|
import Avatar from './avatar'; |
|
|
|
import AvatarOverlay from './avatar_overlay'; |
|
|
|
import AvatarOverlay from './avatar_overlay'; |
|
|
|
import RelativeTimestamp from './relative_timestamp'; |
|
|
|
|
|
|
|
import DisplayName from './display_name'; |
|
|
|
import DisplayName from './display_name'; |
|
|
|
import MediaGallery from './media_gallery'; |
|
|
|
import MediaGallery from './media_gallery'; |
|
|
|
import VideoPlayer from './video_player'; |
|
|
|
import VideoPlayer from './video_player'; |
|
|
|
import StatusContent from './status_content'; |
|
|
|
import StatusContent from './status_content'; |
|
|
|
import StatusActionBar from './status_action_bar'; |
|
|
|
import StatusActionBar from './status_action_bar'; |
|
|
|
import { FormattedMessage } from 'react-intl'; |
|
|
|
import IconButton from './icon_button'; |
|
|
|
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; |
|
|
|
import emojify from '../emoji'; |
|
|
|
import emojify from '../emoji'; |
|
|
|
import escapeTextContentForBrowser from 'escape-html'; |
|
|
|
import escapeTextContentForBrowser from 'escape-html'; |
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'; |
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'; |
|
|
|
import scheduleIdleTask from '../features/ui/util/schedule_idle_task'; |
|
|
|
import scheduleIdleTask from '../features/ui/util/schedule_idle_task'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const messages = defineMessages({ |
|
|
|
|
|
|
|
collapse: { id: 'status.collapse', defaultMessage: 'Collapse' }, |
|
|
|
|
|
|
|
uncollapse: { id: 'status.uncollapse', defaultMessage: 'Uncollapse' }, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@injectIntl |
|
|
|
export default class Status extends ImmutablePureComponent { |
|
|
|
export default class Status extends ImmutablePureComponent { |
|
|
|
|
|
|
|
|
|
|
|
static contextTypes = { |
|
|
|
static contextTypes = { |
|
|
@ -37,12 +43,14 @@ export default class Status extends ImmutablePureComponent { |
|
|
|
autoPlayGif: PropTypes.bool, |
|
|
|
autoPlayGif: PropTypes.bool, |
|
|
|
muted: PropTypes.bool, |
|
|
|
muted: PropTypes.bool, |
|
|
|
intersectionObserverWrapper: PropTypes.object, |
|
|
|
intersectionObserverWrapper: PropTypes.object, |
|
|
|
|
|
|
|
intl: PropTypes.object.isRequired, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
state = { |
|
|
|
state = { |
|
|
|
isExpanded: false, |
|
|
|
isExpanded: false, |
|
|
|
isIntersecting: true, // assume intersecting until told otherwise
|
|
|
|
isIntersecting: true, // assume intersecting until told otherwise
|
|
|
|
isHidden: false, // set to true in requestIdleCallback to trigger un-render
|
|
|
|
isHidden: false, // set to true in requestIdleCallback to trigger un-render
|
|
|
|
|
|
|
|
isCollapsed: false, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Avoid checking props that are functions (and whose equality will always
|
|
|
|
// Avoid checking props that are functions (and whose equality will always
|
|
|
@ -60,7 +68,11 @@ export default class Status extends ImmutablePureComponent { |
|
|
|
updateOnStates = ['isExpanded'] |
|
|
|
updateOnStates = ['isExpanded'] |
|
|
|
|
|
|
|
|
|
|
|
shouldComponentUpdate (nextProps, nextState) { |
|
|
|
shouldComponentUpdate (nextProps, nextState) { |
|
|
|
if (!nextState.isIntersecting && nextState.isHidden) { |
|
|
|
if (nextState.isCollapsed !== this.state.isCollapsed) { |
|
|
|
|
|
|
|
// If the collapsed state of the element has changed then we definitely
|
|
|
|
|
|
|
|
// need to re-update.
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} else if (!nextState.isIntersecting && nextState.isHidden) { |
|
|
|
// It's only if we're not intersecting (i.e. offscreen) and isHidden is true
|
|
|
|
// It's only if we're not intersecting (i.e. offscreen) and isHidden is true
|
|
|
|
// that either "isIntersecting" or "isHidden" matter, and then they're
|
|
|
|
// that either "isIntersecting" or "isHidden" matter, and then they're
|
|
|
|
// the only things that matter.
|
|
|
|
// the only things that matter.
|
|
|
@ -75,6 +87,8 @@ export default class Status extends ImmutablePureComponent { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentDidMount () { |
|
|
|
componentDidMount () { |
|
|
|
|
|
|
|
const node = this.node; |
|
|
|
|
|
|
|
|
|
|
|
if (!this.props.intersectionObserverWrapper) { |
|
|
|
if (!this.props.intersectionObserverWrapper) { |
|
|
|
// TODO: enable IntersectionObserver optimization for notification statuses.
|
|
|
|
// TODO: enable IntersectionObserver optimization for notification statuses.
|
|
|
|
// These are managed in notifications/index.js rather than status_list.js
|
|
|
|
// These are managed in notifications/index.js rather than status_list.js
|
|
|
@ -86,6 +100,8 @@ export default class Status extends ImmutablePureComponent { |
|
|
|
this.handleIntersection |
|
|
|
this.handleIntersection |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (node.clientHeight > 400) this.setState({ isCollapsed: true }); |
|
|
|
|
|
|
|
|
|
|
|
this.componentMounted = true; |
|
|
|
this.componentMounted = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -150,14 +166,18 @@ export default class Status extends ImmutablePureComponent { |
|
|
|
this.setState({ isExpanded: !this.state.isExpanded }); |
|
|
|
this.setState({ isExpanded: !this.state.isExpanded }); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleCollapsedClick = () => { |
|
|
|
|
|
|
|
this.setState({ isCollapsed: !this.state.isCollapsed }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
render () { |
|
|
|
let media = null; |
|
|
|
let media = null; |
|
|
|
let statusAvatar; |
|
|
|
let statusAvatar; |
|
|
|
|
|
|
|
|
|
|
|
// Exclude intersectionObserverWrapper from `other` variable
|
|
|
|
// Exclude intersectionObserverWrapper from `other` variable
|
|
|
|
// because intersection is managed in here.
|
|
|
|
// because intersection is managed in here.
|
|
|
|
const { status, account, intersectionObserverWrapper, ...other } = this.props; |
|
|
|
const { status, account, intersectionObserverWrapper, intl ...other } = this.props; |
|
|
|
const { isExpanded, isIntersecting, isHidden } = this.state; |
|
|
|
const { isExpanded, isIntersecting, isHidden, isCollapsed } = this.state; |
|
|
|
|
|
|
|
|
|
|
|
if (status === null) { |
|
|
|
if (status === null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -210,9 +230,17 @@ export default class Status extends ImmutablePureComponent { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className={`status ${this.props.muted ? 'muted' : ''} status-${status.get('visibility')}`} data-id={status.get('id')} ref={this.handleRef}> |
|
|
|
<div className={`status ${this.props.muted ? 'muted' : ''} status-${status.get('visibility')} ${isCollapsed ? 'status-collapsed' : ''}`} data-id={status.get('id')} ref={this.handleRef}> |
|
|
|
<div className='status__info'> |
|
|
|
<div className='status__info'> |
|
|
|
<a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a> |
|
|
|
|
|
|
|
|
|
|
|
<IconButton |
|
|
|
|
|
|
|
className='status__collapse-button' |
|
|
|
|
|
|
|
animate flip |
|
|
|
|
|
|
|
active={isCollapsed} |
|
|
|
|
|
|
|
title={isCollapsed ? intl.formatMessage(messages.uncollapse) : intl.formatMessage(messages.collapse)} |
|
|
|
|
|
|
|
icon='angle-double-down' |
|
|
|
|
|
|
|
onClick={this.handleCollapsedClick} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
|
|
<a onClick={this.handleAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name'> |
|
|
|
<a onClick={this.handleAccountClick} data-id={status.getIn(['account', 'id'])} href={status.getIn(['account', 'url'])} className='status__display-name'> |
|
|
|
<div className='status__avatar'> |
|
|
|
<div className='status__avatar'> |
|
|
@ -221,13 +249,14 @@ export default class Status extends ImmutablePureComponent { |
|
|
|
|
|
|
|
|
|
|
|
<DisplayName account={status.get('account')} /> |
|
|
|
<DisplayName account={status.get('account')} /> |
|
|
|
</a> |
|
|
|
</a> |
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<StatusContent status={status} onClick={this.handleClick} expanded={isExpanded} onExpandedToggle={this.handleExpandedToggle} onHeightUpdate={this.saveHeight} /> |
|
|
|
<StatusContent status={status} onClick={this.handleClick} expanded={isExpanded} onExpandedToggle={this.handleExpandedToggle} onHeightUpdate={this.saveHeight} /> |
|
|
|
|
|
|
|
|
|
|
|
{media} |
|
|
|
{isCollapsed ? null : media} |
|
|
|
|
|
|
|
|
|
|
|
<StatusActionBar {...this.props} /> |
|
|
|
{isCollapsed ? null : <StatusActionBar {...this.props} />} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|