|
|
@ -1,7 +1,7 @@
|
|
|
|
import React from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { FormattedMessage, injectIntl } from 'react-intl';
|
|
|
|
import Permalink from './permalink';
|
|
|
|
import Permalink from './permalink';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import PollContainer from 'mastodon/containers/poll_container';
|
|
|
|
import PollContainer from 'mastodon/containers/poll_container';
|
|
|
@ -10,7 +10,8 @@ import { autoPlayGif } from 'mastodon/initial_state';
|
|
|
|
|
|
|
|
|
|
|
|
const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top)
|
|
|
|
const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top)
|
|
|
|
|
|
|
|
|
|
|
|
export default class StatusContent extends React.PureComponent {
|
|
|
|
export default @injectIntl
|
|
|
|
|
|
|
|
class StatusContent extends React.PureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
router: PropTypes.object,
|
|
|
@ -21,9 +22,11 @@ export default class StatusContent extends React.PureComponent {
|
|
|
|
expanded: PropTypes.bool,
|
|
|
|
expanded: PropTypes.bool,
|
|
|
|
showThread: PropTypes.bool,
|
|
|
|
showThread: PropTypes.bool,
|
|
|
|
onExpandedToggle: PropTypes.func,
|
|
|
|
onExpandedToggle: PropTypes.func,
|
|
|
|
|
|
|
|
onTranslate: PropTypes.func,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
collapsable: PropTypes.bool,
|
|
|
|
collapsable: PropTypes.bool,
|
|
|
|
onCollapsedToggle: PropTypes.func,
|
|
|
|
onCollapsedToggle: PropTypes.func,
|
|
|
|
|
|
|
|
intl: PropTypes.object,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
state = {
|
|
|
|
state = {
|
|
|
@ -163,20 +166,26 @@ export default class StatusContent extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleTranslate = () => {
|
|
|
|
|
|
|
|
this.props.onTranslate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setRef = (c) => {
|
|
|
|
setRef = (c) => {
|
|
|
|
this.node = c;
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
const { status } = this.props;
|
|
|
|
const { status, intl } = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
|
|
|
|
const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
|
|
|
|
const renderReadMore = this.props.onClick && status.get('collapsed');
|
|
|
|
const renderReadMore = this.props.onClick && status.get('collapsed');
|
|
|
|
const renderViewThread = this.props.showThread && status.get('in_reply_to_id') && status.get('in_reply_to_account_id') === status.getIn(['account', 'id']);
|
|
|
|
const renderViewThread = this.props.showThread && status.get('in_reply_to_id') && status.get('in_reply_to_account_id') === status.getIn(['account', 'id']);
|
|
|
|
|
|
|
|
const renderTranslate = this.props.onTranslate && ['public', 'unlisted'].includes(status.get('visibility')) && intl.locale !== status.get('language');
|
|
|
|
|
|
|
|
const languageNames = new Intl.DisplayNames([intl.locale], { type: 'language' });
|
|
|
|
|
|
|
|
|
|
|
|
const content = { __html: status.get('contentHtml') };
|
|
|
|
const content = { __html: status.get('translation') ? status.getIn(['translation', 'content']) : status.get('contentHtml') };
|
|
|
|
const spoilerContent = { __html: status.get('spoilerHtml') };
|
|
|
|
const spoilerContent = { __html: status.get('spoilerHtml') };
|
|
|
|
const lang = status.get('language');
|
|
|
|
const lang = status.get('translation') ? intl.locale : status.get('language');
|
|
|
|
const classNames = classnames('status__content', {
|
|
|
|
const classNames = classnames('status__content', {
|
|
|
|
'status__content--with-action': this.props.onClick && this.context.router,
|
|
|
|
'status__content--with-action': this.props.onClick && this.context.router,
|
|
|
|
'status__content--with-spoiler': status.get('spoiler_text').length > 0,
|
|
|
|
'status__content--with-spoiler': status.get('spoiler_text').length > 0,
|
|
|
@ -195,6 +204,12 @@ export default class StatusContent extends React.PureComponent {
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const translateButton = (
|
|
|
|
|
|
|
|
<button className='status__content__read-more-button' onClick={this.handleTranslate}>
|
|
|
|
|
|
|
|
{status.get('translation') ? <span><FormattedMessage id='status.translated_from' defaultMessage='Translated from {lang}' values={{ lang: languageNames.of(status.get('language')) }} /> · <FormattedMessage id='status.show_original' defaultMessage='Show original' /></span> : <FormattedMessage id='status.translate' defaultMessage='Translate' />}
|
|
|
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (status.get('spoiler_text').length > 0) {
|
|
|
|
if (status.get('spoiler_text').length > 0) {
|
|
|
|
let mentionsPlaceholder = '';
|
|
|
|
let mentionsPlaceholder = '';
|
|
|
|
|
|
|
|
|
|
|
@ -223,7 +238,7 @@ export default class StatusContent extends React.PureComponent {
|
|
|
|
<div tabIndex={!hidden ? 0 : null} className={`status__content__text ${!hidden ? 'status__content__text--visible' : ''} translate`} lang={lang} dangerouslySetInnerHTML={content} />
|
|
|
|
<div tabIndex={!hidden ? 0 : null} className={`status__content__text ${!hidden ? 'status__content__text--visible' : ''} translate`} lang={lang} dangerouslySetInnerHTML={content} />
|
|
|
|
|
|
|
|
|
|
|
|
{!hidden && !!status.get('poll') && <PollContainer pollId={status.get('poll')} />}
|
|
|
|
{!hidden && !!status.get('poll') && <PollContainer pollId={status.get('poll')} />}
|
|
|
|
|
|
|
|
{!hidden && renderTranslate && translateButton}
|
|
|
|
{renderViewThread && showThreadButton}
|
|
|
|
{renderViewThread && showThreadButton}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -233,7 +248,7 @@ export default class StatusContent extends React.PureComponent {
|
|
|
|
<div className='status__content__text status__content__text--visible translate' lang={lang} dangerouslySetInnerHTML={content} />
|
|
|
|
<div className='status__content__text status__content__text--visible translate' lang={lang} dangerouslySetInnerHTML={content} />
|
|
|
|
|
|
|
|
|
|
|
|
{!!status.get('poll') && <PollContainer pollId={status.get('poll')} />}
|
|
|
|
{!!status.get('poll') && <PollContainer pollId={status.get('poll')} />}
|
|
|
|
|
|
|
|
{renderTranslate && translateButton}
|
|
|
|
{renderViewThread && showThreadButton}
|
|
|
|
{renderViewThread && showThreadButton}
|
|
|
|
</div>,
|
|
|
|
</div>,
|
|
|
|
];
|
|
|
|
];
|
|
|
@ -249,7 +264,7 @@ export default class StatusContent extends React.PureComponent {
|
|
|
|
<div className='status__content__text status__content__text--visible translate' lang={lang} dangerouslySetInnerHTML={content} />
|
|
|
|
<div className='status__content__text status__content__text--visible translate' lang={lang} dangerouslySetInnerHTML={content} />
|
|
|
|
|
|
|
|
|
|
|
|
{!!status.get('poll') && <PollContainer pollId={status.get('poll')} />}
|
|
|
|
{!!status.get('poll') && <PollContainer pollId={status.get('poll')} />}
|
|
|
|
|
|
|
|
{renderTranslate && translateButton}
|
|
|
|
{renderViewThread && showThreadButton}
|
|
|
|
{renderViewThread && showThreadButton}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|