2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-05-02 07:25:55 +01:00
|
|
|
import { injectIntl } from 'react-intl'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import StatusCard from './status_card'
|
|
|
|
import { MediaGallery, Video } from '../features/ui/util/async_components'
|
|
|
|
import Poll from './poll'
|
|
|
|
|
|
|
|
// We use the component (and not the container) since we do not want
|
|
|
|
// to use the progress bar to show download progress
|
|
|
|
import Bundle from '../features/ui/util/bundle'
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
class StatusMedia extends ImmutablePureComponent {
|
2020-05-02 07:25:55 +01:00
|
|
|
|
|
|
|
// Avoid checking props that are functions (and whose equality will always
|
|
|
|
// evaluate to false. See react-immutable-pure-component for usage.
|
|
|
|
updateOnProps = [
|
|
|
|
'status',
|
|
|
|
'isChild',
|
|
|
|
'isComment',
|
|
|
|
'cacheWidth',
|
|
|
|
'defaultWidth',
|
|
|
|
'visible',
|
|
|
|
'width',
|
2020-05-07 00:40:54 +01:00
|
|
|
'isComposeModalOpen',
|
2020-05-02 07:25:55 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
renderLoadingMedia() {
|
|
|
|
return <div className={_s.backgroundColorPanel} style={{ height: '110px' }} />
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
status,
|
|
|
|
isChild,
|
|
|
|
isComment,
|
|
|
|
onOpenMedia,
|
|
|
|
onOpenVideo,
|
|
|
|
width,
|
|
|
|
onToggleVisibility,
|
|
|
|
visible,
|
|
|
|
defaultWidth,
|
|
|
|
cacheWidth,
|
2020-05-07 00:40:54 +01:00
|
|
|
isComposeModalOpen,
|
2020-08-06 05:27:35 +01:00
|
|
|
isStatusCard,
|
2020-05-02 07:25:55 +01:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (!status) return null
|
|
|
|
|
|
|
|
let media = null
|
|
|
|
|
|
|
|
if (status.get('poll')) {
|
|
|
|
media = <Poll pollId={status.get('poll')} />
|
|
|
|
} else if (status.get('media_attachments').size > 0) {
|
|
|
|
if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
|
|
|
|
const video = status.getIn(['media_attachments', 0])
|
|
|
|
|
|
|
|
media = (
|
|
|
|
<Bundle fetchComponent={Video} loading={this.renderLoadingMedia}>
|
|
|
|
{Component => (
|
|
|
|
<Component
|
|
|
|
inline
|
2020-05-06 05:33:54 +01:00
|
|
|
isComment={isComment}
|
2020-05-02 07:25:55 +01:00
|
|
|
preview={video.get('preview_url')}
|
|
|
|
blurhash={video.get('blurhash')}
|
|
|
|
src={video.get('url')}
|
2020-12-22 17:11:22 +00:00
|
|
|
sourceMp4={video.get('source_mp4')}
|
2020-05-02 07:25:55 +01:00
|
|
|
alt={video.get('description')}
|
|
|
|
aspectRatio={video.getIn(['meta', 'small', 'aspect'])}
|
2020-12-22 06:36:38 +00:00
|
|
|
fileContentType={video.get('file_content_type')}
|
2020-05-02 07:25:55 +01:00
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
height={110}
|
|
|
|
width={width}
|
|
|
|
onOpenVideo={onOpenVideo}
|
|
|
|
cacheWidth={cacheWidth}
|
|
|
|
visible={visible}
|
|
|
|
onToggleVisibility={onToggleVisibility}
|
2020-06-10 22:05:53 +01:00
|
|
|
meta={video.get('meta')}
|
2020-05-02 07:25:55 +01:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Bundle>
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
media = (
|
|
|
|
<Bundle fetchComponent={MediaGallery} loading={this.renderLoadingMedia}>
|
|
|
|
{Component => (
|
|
|
|
<Component
|
2020-05-06 05:33:54 +01:00
|
|
|
isComment={isComment}
|
2020-05-02 07:25:55 +01:00
|
|
|
reduced={isChild}
|
|
|
|
media={status.get('media_attachments')}
|
|
|
|
sensitive={status.get('sensitive')}
|
|
|
|
onOpenMedia={onOpenMedia}
|
|
|
|
cacheWidth={cacheWidth}
|
|
|
|
defaultWidth={defaultWidth}
|
|
|
|
visible={visible}
|
|
|
|
onToggleVisibility={onToggleVisibility}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Bundle>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else if (status.get('spoiler_text').length === 0 && status.get('card')) {
|
|
|
|
media = (
|
|
|
|
<StatusCard
|
|
|
|
card={status.get('card')}
|
|
|
|
onOpenMedia={onOpenMedia}
|
|
|
|
cacheWidth={cacheWidth}
|
|
|
|
defaultWidth={defaultWidth}
|
2020-09-11 23:55:05 +01:00
|
|
|
isVertical={isComment || isChild}
|
2020-08-06 05:27:35 +01:00
|
|
|
isReduced={isStatusCard || isComposeModalOpen}
|
2020-05-02 07:25:55 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return media
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 01:57:35 +01:00
|
|
|
|
|
|
|
StatusMedia.propTypes = {
|
|
|
|
status: ImmutablePropTypes.map,
|
|
|
|
isChild: PropTypes.bool,
|
|
|
|
isComment: PropTypes.bool,
|
|
|
|
onOpenMedia: PropTypes.func,
|
|
|
|
onOpenVideo: PropTypes.func,
|
|
|
|
width: PropTypes.number,
|
|
|
|
onToggleVisibility: PropTypes.func,
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
defaultWidth: PropTypes.number,
|
|
|
|
cacheWidth: PropTypes.number,
|
|
|
|
isComposeModalOpen: PropTypes.bool,
|
|
|
|
isStatusCard: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default StatusMedia
|