import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { FormattedMessage, defineMessages, injectIntl } from 'react-intl' import { me, isStaff, boostModal, deleteModal } from '../../initial_state' import { makeGetStatus } from '../../selectors' import { repost, unrepost, pin, unpin, isPin, bookmark, unbookmark, isBookmark, } from '../../actions/interactions'; import { muteAccount, unmuteAccount, } from '../../actions/accounts'; import { deleteStatus, editStatus, } from '../../actions/statuses'; import { quoteCompose } from '../../actions/compose' import { fetchBookmarkCollections, updateBookmarkCollectionStatus, } from '../../actions/bookmarks' import { fetchGroupRelationships, createRemovedAccount, groupRemoveStatus, pinGroupStatus, unpinGroupStatus, isPinnedGroupStatus, } from '../../actions/groups' import { initReport } from '../../actions/reports' import { openModal } from '../../actions/modal' import { closePopover, openPopover, } from '../../actions/popover' import { MODAL_PRO_UPGRADE, POPOVER_SHARE, } from '../../constants' import PopoverLayout from './popover_layout' import Button from '../button' import List from '../list' import Text from '../text' class StatusOptionsPopover extends ImmutablePureComponent { static contextTypes = { router: PropTypes.object, } state = { showingBookmarkCollections: false, } componentDidMount() { const { status, statusId, groupRelationships, } = this.props if (status.get('pinnable')) { this.props.fetchIsPin(statusId) } this.props.fetchIsBookmark(statusId) if (!!status.get('group')) { this.props.fetchIsPinnedGroupStatus(status.getIn(['group', 'id'], null), statusId) } if (!this.props.groupRelationships && this.props.groupId) { this.props.onFetchGroupRelationships(this.props.groupId) } } handleGroupRemoveAccount = () => { const { status } = this.props this.props.onGroupRemoveAccount(status.getIn(['group', 'id']), status.getIn(['account', 'id'])) } handleGroupRemovePost = () => { const { status } = this.props this.props.onGroupRemoveStatus(status.getIn(['group', 'id']), status.get('id')) } handleReport = () => { this.props.onReport(this.props.status) } handleBlockClick = () => { this.props.onBlock(this.props.status) } handleMuteClick = () => { this.props.onMute(this.props.status.get('account')) } handlePinClick = () => { this.props.onPin(this.props.status) } handleGroupPinStatus = () => { this.props.onPinGroupStatus(this.props.status) } handleBookmarkClick = () => { // : todo : add to specific bookmark collection if (this.props.isPro) { this.props.onBookmark(this.props.status) } else { this.props.onOpenProUpgradeModal() } } handleBookmarkChangeClick = () => { if (!this.props.bookmarkCollectionsIsFetched) this.props.onFetchBookmarkCollections() this.setState({ showingBookmarkCollections: true }) } handleBookmarkChangeBackClick = () => { this.setState({ showingBookmarkCollections: false }) } handleBookmarkChangeSelectClick = (bookmarkCollectionId) => { this.props.onUpdateBookmarkCollectionStatus(this.props.status.get('id'), bookmarkCollectionId) } handleDeleteClick = () => { this.props.onDelete(this.props.status) } handleEditClick = () => { this.props.onEdit(this.props.status) } handleRepostClick = (e) => { this.props.onRepost(this.props.status, e) } handleQuoteClick = (e) => { this.props.onQuote(this.props.status, this.context.router) } handleOnOpenSharePopover = () => { this.props.onOpenSharePopover(this.props.innerRef, this.props.status) } handleClosePopover = () => { this.props.onClosePopover() } render() { const { isXS, intl, status, groupRelationships, bookmarkCollections, } = this.props const { showingBookmarkCollections } = this.state if (!status) return
const mutingConversation = status.get('muted') const publicStatus = ['public', 'unlisted'].includes(status.get('visibility')) const isReply = !!status.get('in_reply_to_id') const withGroupAdmin = !!groupRelationships ? (groupRelationships.get('admin') || groupRelationships.get('moderator')) : false let menu = [] if (me) { if (isReply) { menu.push({ icon: 'pencil', hideArrow: true, title: intl.formatMessage(messages.repostWithComment), onClick: this.handleQuoteClick, }) } menu.push({ icon: 'bookmark', hideArrow: status.get('bookmarked'), title: intl.formatMessage(status.get('bookmarked') ? messages.unbookmark : messages.bookmark), onClick: this.handleBookmarkClick, }) if (status.get('bookmarked')) { // : todo : // menu.push({ // icon: 'bookmark', // title: 'Update bookmark collection', // onClick: this.handleBookmarkChangeClick, // }) } if (status.getIn(['account', 'id']) === me) { if (publicStatus) { menu.push({ icon: 'pin', hideArrow: true, title: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), onClick: this.handlePinClick, }) } menu.push({ icon: 'trash', hideArrow: true, title: intl.formatMessage(messages.delete), onClick: this.handleDeleteClick, }) menu.push({ icon: 'pencil', hideArrow: true, title: intl.formatMessage(messages.edit), onClick: this.handleEditClick, }) } else { menu.push({ icon: 'audio-mute', hideArrow: true, title: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), onClick: this.handleMuteClick, }) menu.push({ icon: 'block', hideArrow: true, title: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), onClick: this.handleBlockClick, }) menu.push({ icon: 'warning', hideArrow: true, title: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), onClick: this.handleReport, }) } } if (withGroupAdmin || (!!groupRelationships && isStaff)) { menu.push(null) menu.push({ icon: 'trash', hideArrow: true, title: intl.formatMessage(messages.group_remove_account), onClick: this.handleGroupRemoveAccount, }) menu.push({ icon: 'trash', hideArrow: true, title: intl.formatMessage(messages.group_remove_post), onClick: this.handleGroupRemovePost, }) menu.push(null) menu.push({ icon: 'pin', hideArrow: true, title: intl.formatMessage(status.get('pinned_by_group') ? messages.groupUnpin : messages.groupPin), onClick: this.handleGroupPinStatus, }) } menu.push(null) menu.push({ icon: 'share', hideArrow: true, title: intl.formatMessage(messages.share), onClick: this.handleOnOpenSharePopover, }) if (isStaff) { menu.push(null) menu.push({ title: intl.formatMessage(messages.admin_account, { name: status.getIn(['account', 'username']) }), href: `/admin/accounts/${status.getIn(['account', 'id'])}` }) menu.push({ title: intl.formatMessage(messages.admin_status), href: `/admin/accounts/${status.getIn(['account', 'id'])}/statuses/${status.get('id')}` }) } const popoverWidth = !isStaff ? 260 : 362 let bookmarkCollectionItems = !!bookmarkCollections ? bookmarkCollections.map((bookmarkCollection) => ({ hideArrow: true, onClick: () => this.handleBookmarkChangeSelectClick(bookmarkCollection.get('id')), title: bookmarkCollection.get('title'), isActive: bookmarkCollection.get('id') === status.get('bookmark_collection_id'), })) : [] bookmarkCollectionItems = bookmarkCollectionItems.unshift({ hideArrow: true, onClick: () => this.handleBookmarkChangeSelectClick('saved'), title: 'Saved', isActive: !status.get('bookmark_collection_id'), }) return (