import classNames from 'classnames'; import { History } from 'history'; import React from 'react'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { defineMessages, injectIntl, FormattedMessage, IntlShape, FormattedList } from 'react-intl'; import { withRouter } from 'react-router-dom'; import AttachmentThumbs from 'soapbox/components/attachment-thumbs'; import { Stack, Text } from 'soapbox/components/ui'; import AccountContainer from 'soapbox/containers/account_container'; import type { Account as AccountEntity, Status as StatusEntity } from 'soapbox/types/entities'; const messages = defineMessages({ cancel: { id: 'reply_indicator.cancel', defaultMessage: 'Cancel' }, }); interface IQuotedStatus { status?: StatusEntity, onCancel?: Function, intl: IntlShape, compose?: boolean, history: History, } class QuotedStatus extends ImmutablePureComponent { handleExpandClick = (e: React.MouseEvent) => { const { compose, status } = this.props; if (!status) return; const account = status.account as AccountEntity; if (!compose && e.button === 0) { if (!this.props.history) { return; } this.props.history.push(`/@${account.acct}/posts/${status.id}`); e.stopPropagation(); e.preventDefault(); } } handleClose = () => { if (this.props.onCancel) { this.props.onCancel(); } } renderReplyMentions = () => { const { status } = this.props; if (!status?.in_reply_to_id) { return null; } const account = status.account as AccountEntity; const to = status.mentions || []; if (to.size === 0) { if (status.in_reply_to_account_id === account.id) { return (
); } else { return (
); } } const accounts = to.slice(0, 2).map(account => <>@{account.username}).toArray(); if (to.size > 2) { accounts.push( , ); } return (
, }} />
); } render() { const { status, onCancel, intl, compose } = this.props; if (!status) { return null; } const account = status.account as AccountEntity; let actions = {}; if (onCancel) { actions = { onActionClick: this.handleClose, actionIcon: require('@tabler/icons/icons/x.svg'), actionAlignment: 'top', actionTitle: intl.formatMessage(messages.cancel), }; } const quotedStatus = ( {this.renderReplyMentions()} {status.media_attachments.size > 0 && ( )} ); return quotedStatus; } } export default withRouter(injectIntl(QuotedStatus) as any);