You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
6.0 KiB
160 lines
6.0 KiB
7 years ago
|
// Package imports //
|
||
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import { defineMessages, injectIntl } from 'react-intl';
|
||
8 years ago
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||
7 years ago
|
|
||
|
// Mastodon imports //
|
||
|
import RelativeTimestamp from '../../../mastodon/components/relative_timestamp';
|
||
|
import IconButton from '../../../mastodon/components/icon_button';
|
||
|
import DropdownMenu from '../../../mastodon/components/dropdown_menu';
|
||
8 years ago
|
|
||
|
const messages = defineMessages({
|
||
|
delete: { id: 'status.delete', defaultMessage: 'Delete' },
|
||
8 years ago
|
mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
|
||
8 years ago
|
mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
|
||
8 years ago
|
block: { id: 'account.block', defaultMessage: 'Block @{name}' },
|
||
8 years ago
|
reply: { id: 'status.reply', defaultMessage: 'Reply' },
|
||
8 years ago
|
replyAll: { id: 'status.replyAll', defaultMessage: 'Reply to thread' },
|
||
8 years ago
|
reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
|
||
|
cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
|
||
8 years ago
|
favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
|
||
8 years ago
|
open: { id: 'status.open', defaultMessage: 'Expand this status' },
|
||
8 years ago
|
report: { id: 'status.report', defaultMessage: 'Report @{name}' },
|
||
|
muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
|
||
|
unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
7 years ago
|
@injectIntl
|
||
|
export default class StatusActionBar extends ImmutablePureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static contextTypes = {
|
||
8 years ago
|
router: PropTypes.object,
|
||
8 years ago
|
};
|
||
|
|
||
|
static propTypes = {
|
||
|
status: ImmutablePropTypes.map.isRequired,
|
||
|
onReply: PropTypes.func,
|
||
|
onFavourite: PropTypes.func,
|
||
|
onReblog: PropTypes.func,
|
||
|
onDelete: PropTypes.func,
|
||
|
onMention: PropTypes.func,
|
||
|
onMute: PropTypes.func,
|
||
|
onBlock: PropTypes.func,
|
||
|
onReport: PropTypes.func,
|
||
8 years ago
|
onMuteConversation: PropTypes.func,
|
||
8 years ago
|
me: PropTypes.number.isRequired,
|
||
8 years ago
|
withDismiss: PropTypes.bool,
|
||
8 years ago
|
intl: PropTypes.object.isRequired,
|
||
8 years ago
|
};
|
||
|
|
||
8 years ago
|
// Avoid checking props that are functions (and whose equality will always
|
||
|
// evaluate to false. See react-immutable-pure-component for usage.
|
||
|
updateOnProps = [
|
||
|
'status',
|
||
|
'me',
|
||
|
'withDismiss',
|
||
|
]
|
||
|
|
||
8 years ago
|
handleReplyClick = () => {
|
||
7 years ago
|
this.props.onReply(this.props.status, this.context.router.history);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleFavouriteClick = () => {
|
||
8 years ago
|
this.props.onFavourite(this.props.status);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleReblogClick = (e) => {
|
||
8 years ago
|
this.props.onReblog(this.props.status, e);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleDeleteClick = () => {
|
||
8 years ago
|
this.props.onDelete(this.props.status);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleMentionClick = () => {
|
||
7 years ago
|
this.props.onMention(this.props.status.get('account'), this.context.router.history);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleMuteClick = () => {
|
||
8 years ago
|
this.props.onMute(this.props.status.get('account'));
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleBlockClick = () => {
|
||
8 years ago
|
this.props.onBlock(this.props.status.get('account'));
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleOpen = () => {
|
||
7 years ago
|
this.context.router.history.push(`/statuses/${this.props.status.get('id')}`);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleReport = () => {
|
||
8 years ago
|
this.props.onReport(this.props.status);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
handleConversationMuteClick = () => {
|
||
|
this.props.onMuteConversation(this.props.status);
|
||
|
}
|
||
|
|
||
8 years ago
|
render () {
|
||
8 years ago
|
const { status, me, intl, withDismiss } = this.props;
|
||
8 years ago
|
const reblogDisabled = status.get('visibility') === 'private' || status.get('visibility') === 'direct';
|
||
8 years ago
|
const mutingConversation = status.get('muted');
|
||
8 years ago
|
|
||
8 years ago
|
let menu = [];
|
||
8 years ago
|
let reblogIcon = 'retweet';
|
||
|
let replyIcon;
|
||
|
let replyTitle;
|
||
8 years ago
|
|
||
8 years ago
|
menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
|
||
8 years ago
|
menu.push(null);
|
||
8 years ago
|
|
||
8 years ago
|
if (withDismiss) {
|
||
|
menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
|
||
|
menu.push(null);
|
||
|
}
|
||
|
|
||
8 years ago
|
if (status.getIn(['account', 'id']) === me) {
|
||
8 years ago
|
menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
|
||
8 years ago
|
} else {
|
||
8 years ago
|
menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
|
||
|
menu.push(null);
|
||
8 years ago
|
menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
|
||
8 years ago
|
menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
|
||
|
menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
/*
|
||
8 years ago
|
if (status.get('visibility') === 'direct') {
|
||
|
reblogIcon = 'envelope';
|
||
|
} else if (status.get('visibility') === 'private') {
|
||
|
reblogIcon = 'lock';
|
||
|
}
|
||
7 years ago
|
*/
|
||
8 years ago
|
|
||
8 years ago
|
if (status.get('in_reply_to_id', null) === null) {
|
||
8 years ago
|
replyIcon = 'reply';
|
||
8 years ago
|
replyTitle = intl.formatMessage(messages.reply);
|
||
8 years ago
|
} else {
|
||
8 years ago
|
replyIcon = 'reply-all';
|
||
8 years ago
|
replyTitle = intl.formatMessage(messages.replyAll);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<div className='status__action-bar'>
|
||
8 years ago
|
<IconButton className='status__action-bar-button' title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} />
|
||
|
<IconButton className='status__action-bar-button' disabled={reblogDisabled} active={status.get('reblogged')} title={reblogDisabled ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} />
|
||
8 years ago
|
<IconButton className='status__action-bar-button star-icon' animate active={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} />
|
||
8 years ago
|
|
||
8 years ago
|
<div className='status__action-bar-dropdown'>
|
||
8 years ago
|
<DropdownMenu items={menu} icon='ellipsis-h' size={18} direction='right' ariaLabel='More' />
|
||
8 years ago
|
</div>
|
||
7 years ago
|
|
||
|
<a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
|
||
8 years ago
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|