import PropTypes from 'prop-types'; import { PureComponent } from 'react'; import { defineMessages, injectIntl, FormattedMessage, FormattedDate } from 'react-intl'; import classNames from 'classnames'; import { withRouter } from 'react-router-dom'; import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { ReactComponent as AddIcon } from '@material-symbols/svg-600/outlined/add.svg'; import { ReactComponent as ChevronLeftIcon } from '@material-symbols/svg-600/outlined/chevron_left.svg'; import { ReactComponent as ChevronRightIcon } from '@material-symbols/svg-600/outlined/chevron_right.svg'; import TransitionMotion from 'react-motion/lib/TransitionMotion'; import spring from 'react-motion/lib/spring'; import ReactSwipeableViews from 'react-swipeable-views'; import elephantUIPlane from 'mastodon/../images/elephant_ui_plane.svg'; import { AnimatedNumber } from 'mastodon/components/animated_number'; import { Icon } from 'mastodon/components/icon'; import { IconButton } from 'mastodon/components/icon_button'; import EmojiPickerDropdown from 'mastodon/features/compose/containers/emoji_picker_dropdown_container'; import { unicodeMapping } from 'mastodon/features/emoji/emoji_unicode_mapping_light'; import { autoPlayGif, reduceMotion, disableSwiping, mascot } from 'mastodon/initial_state'; import { assetHost } from 'mastodon/utils/config'; import { WithRouterPropTypes } from 'mastodon/utils/react_router'; const messages = defineMessages({ close: { id: 'lightbox.close', defaultMessage: 'Close' }, previous: { id: 'lightbox.previous', defaultMessage: 'Previous' }, next: { id: 'lightbox.next', defaultMessage: 'Next' }, }); class ContentWithRouter extends ImmutablePureComponent { static propTypes = { announcement: ImmutablePropTypes.map.isRequired, ...WithRouterPropTypes, }; setRef = c => { this.node = c; }; componentDidMount () { this._updateLinks(); } componentDidUpdate () { this._updateLinks(); } _updateLinks () { const node = this.node; if (!node) { return; } const links = node.querySelectorAll('a'); for (var i = 0; i < links.length; ++i) { let link = links[i]; if (link.classList.contains('status-link')) { continue; } link.classList.add('status-link'); let mention = this.props.announcement.get('mentions').find(item => link.href === item.get('url')); if (mention) { link.addEventListener('click', this.onMentionClick.bind(this, mention), false); link.setAttribute('title', mention.get('acct')); } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) { link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false); } else { let status = this.props.announcement.get('statuses').find(item => link.href === item.get('url')); if (status) { link.addEventListener('click', this.onStatusClick.bind(this, status), false); } link.setAttribute('title', link.href); link.classList.add('unhandled-link'); } link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); } } onMentionClick = (mention, e) => { if (this.props.history && e.button === 0 && !(e.ctrlKey || e.metaKey)) { e.preventDefault(); this.props.history.push(`/@${mention.get('acct')}`); } }; onHashtagClick = (hashtag, e) => { hashtag = hashtag.replace(/^#/, ''); if (this.props.history&& e.button === 0 && !(e.ctrlKey || e.metaKey)) { e.preventDefault(); this.props.history.push(`/tags/${hashtag}`); } }; onStatusClick = (status, e) => { if (this.props.history && e.button === 0 && !(e.ctrlKey || e.metaKey)) { e.preventDefault(); this.props.history.push(`/@${status.getIn(['account', 'acct'])}/${status.get('id')}`); } }; handleMouseEnter = ({ currentTarget }) => { if (autoPlayGif) { return; } const emojis = currentTarget.querySelectorAll('.custom-emoji'); for (var i = 0; i < emojis.length; i++) { let emoji = emojis[i]; emoji.src = emoji.getAttribute('data-original'); } }; handleMouseLeave = ({ currentTarget }) => { if (autoPlayGif) { return; } const emojis = currentTarget.querySelectorAll('.custom-emoji'); for (var i = 0; i < emojis.length; i++) { let emoji = emojis[i]; emoji.src = emoji.getAttribute('data-static'); } }; render () { const { announcement } = this.props; return (
); } } const Content = withRouter(ContentWithRouter); class Emoji extends PureComponent { static propTypes = { emoji: PropTypes.string.isRequired, emojiMap: ImmutablePropTypes.map.isRequired, hovered: PropTypes.bool.isRequired, }; render () { const { emoji, emojiMap, hovered } = this.props; if (unicodeMapping[emoji]) { const { filename, shortCode } = unicodeMapping[this.props.emoji]; const title = shortCode ? `:${shortCode}:` : ''; return ( ); } else if (emojiMap.get(emoji)) { const filename = (autoPlayGif || hovered) ? emojiMap.getIn([emoji, 'url']) : emojiMap.getIn([emoji, 'static_url']); const shortCode = `:${emoji}:`; return ( ); } else { return null; } } } class Reaction extends ImmutablePureComponent { static propTypes = { announcementId: PropTypes.string.isRequired, reaction: ImmutablePropTypes.map.isRequired, addReaction: PropTypes.func.isRequired, removeReaction: PropTypes.func.isRequired, emojiMap: ImmutablePropTypes.map.isRequired, style: PropTypes.object, }; state = { hovered: false, }; handleClick = () => { const { reaction, announcementId, addReaction, removeReaction } = this.props; if (reaction.get('me')) { removeReaction(announcementId, reaction.get('name')); } else { addReaction(announcementId, reaction.get('name')); } }; handleMouseEnter = () => this.setState({ hovered: true }); handleMouseLeave = () => this.setState({ hovered: false }); render () { const { reaction } = this.props; let shortCode = reaction.get('name'); if (unicodeMapping[shortCode]) { shortCode = unicodeMapping[shortCode].shortCode; } return ( ); } } class ReactionsBar extends ImmutablePureComponent { static propTypes = { announcementId: PropTypes.string.isRequired, reactions: ImmutablePropTypes.list.isRequired, addReaction: PropTypes.func.isRequired, removeReaction: PropTypes.func.isRequired, emojiMap: ImmutablePropTypes.map.isRequired, }; handleEmojiPick = data => { const { addReaction, announcementId } = this.props; addReaction(announcementId, data.native.replace(/:/g, '')); }; willEnter () { return { scale: reduceMotion ? 1 : 0 }; } willLeave () { return { scale: reduceMotion ? 0 : spring(0, { stiffness: 170, damping: 26 }) }; } render () { const { reactions } = this.props; const visibleReactions = reactions.filter(x => x.get('count') > 0); const styles = visibleReactions.map(reaction => ({ key: reaction.get('name'), data: reaction, style: { scale: reduceMotion ? 1 : spring(1, { stiffness: 150, damping: 13 }) }, })).toArray(); return (