import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { FormattedMessage, injectIntl } from 'react-intl'; import { FormattedDate } from 'react-intl'; import { Link, NavLink } from 'react-router-dom'; import Icon from 'soapbox/components/icon'; import QuotedStatus from 'soapbox/features/status/containers/quoted_status_container'; import { getDomain } from 'soapbox/utils/accounts'; import MediaGallery from '../../../components/media_gallery'; import StatusContent from '../../../components/status_content'; import StatusReplyMentions from '../../../components/status_reply_mentions'; import { HStack, Text } from '../../../components/ui'; import AccountContainer from '../../../containers/account_container'; import Audio from '../../audio'; import scheduleIdleTask from '../../ui/util/schedule_idle_task'; import Video from '../../video'; import Card from './card'; import StatusInteractionBar from './status_interaction_bar'; export default @injectIntl class DetailedStatus extends ImmutablePureComponent { static propTypes = { status: ImmutablePropTypes.record, onOpenMedia: PropTypes.func.isRequired, onOpenVideo: PropTypes.func.isRequired, onToggleHidden: PropTypes.func.isRequired, measureHeight: PropTypes.bool, onHeightChange: PropTypes.func, domain: PropTypes.string, compact: PropTypes.bool, showMedia: PropTypes.bool, onToggleMediaVisibility: PropTypes.func, }; state = { height: null, }; handleOpenVideo = (media, startTime) => { this.props.onOpenVideo(media, startTime); } handleExpandedToggle = () => { this.props.onToggleHidden(this.props.status); } _measureHeight(heightJustChanged) { if (this.props.measureHeight && this.node) { scheduleIdleTask(() => this.node && this.setState({ height: Math.ceil(this.node.scrollHeight) + 1 })); if (this.props.onHeightChange && heightJustChanged) { this.props.onHeightChange(); } } } setRef = c => { this.node = c; this._measureHeight(); if (c) { this.setState({ mediaWrapperWidth: c.offsetWidth }); } } componentDidUpdate(prevProps, prevState) { this._measureHeight(prevState.height !== this.state.height); } handleModalLink = e => { e.preventDefault(); let href; if (e.target.nodeName !== 'A') { href = e.target.parentNode.href; } else { href = e.target.href; } window.open(href, 'soapbox-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes'); } render() { const status = (this.props.status && this.props.status.get('reblog')) ? this.props.status.get('reblog') : this.props.status; const outerStyle = { boxSizing: 'border-box' }; const { compact } = this.props; const favicon = status.getIn(['account', 'pleroma', 'favicon']); const domain = getDomain(status.get('account')); const size = status.get('media_attachments').size; if (!status) { return null; } let media = null; let statusTypeIcon = null; if (this.props.measureHeight) { outerStyle.height = `${this.state.height}px`; } if (size > 0) { if (size === 1 && status.getIn(['media_attachments', 0, 'type']) === 'video') { const video = status.getIn(['media_attachments', 0]); const external_id = (video.get('external_video_id')); if (external_id) { const { mediaWrapperWidth } = this.state; const height = mediaWrapperWidth / (video.getIn(['meta', 'original', 'width']) / video.getIn(['meta', 'original', 'height'])); media = (