2018-10-08 00:44:58 +03:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-09-21 21:01:16 +03:00
|
|
|
import StatusContent from 'mastodon/components/status_content';
|
|
|
|
import AttachmentList from 'mastodon/components/attachment_list';
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import DropdownMenuContainer from 'mastodon/containers/dropdown_menu_container';
|
|
|
|
import AvatarComposite from 'mastodon/components/avatar_composite';
|
|
|
|
import Permalink from 'mastodon/components/permalink';
|
|
|
|
import IconButton from 'mastodon/components/icon_button';
|
|
|
|
import RelativeTimestamp from 'mastodon/components/relative_timestamp';
|
|
|
|
import { HotKeys } from 'react-hotkeys';
|
2019-10-01 18:11:14 +03:00
|
|
|
import { autoPlayGif } from 'mastodon/initial_state';
|
2018-10-08 00:44:58 +03:00
|
|
|
|
2019-09-21 21:01:16 +03:00
|
|
|
const messages = defineMessages({
|
|
|
|
more: { id: 'status.more', defaultMessage: 'More' },
|
|
|
|
open: { id: 'conversation.open', defaultMessage: 'View conversation' },
|
|
|
|
reply: { id: 'status.reply', defaultMessage: 'Reply' },
|
|
|
|
markAsRead: { id: 'conversation.mark_as_read', defaultMessage: 'Mark as read' },
|
|
|
|
delete: { id: 'conversation.delete', defaultMessage: 'Delete conversation' },
|
|
|
|
muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
|
|
|
|
unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
|
|
|
|
});
|
|
|
|
|
|
|
|
export default @injectIntl
|
|
|
|
class Conversation extends ImmutablePureComponent {
|
2018-10-08 00:44:58 +03:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
conversationId: PropTypes.string.isRequired,
|
|
|
|
accounts: ImmutablePropTypes.list.isRequired,
|
2019-09-21 21:01:16 +03:00
|
|
|
lastStatus: ImmutablePropTypes.map,
|
2018-10-19 02:47:29 +03:00
|
|
|
unread:PropTypes.bool.isRequired,
|
2018-10-08 00:44:58 +03:00
|
|
|
onMoveUp: PropTypes.func,
|
|
|
|
onMoveDown: PropTypes.func,
|
2018-10-19 02:47:29 +03:00
|
|
|
markRead: PropTypes.func.isRequired,
|
2019-10-01 16:07:58 +03:00
|
|
|
delete: PropTypes.func.isRequired,
|
2019-09-21 21:01:16 +03:00
|
|
|
intl: PropTypes.object.isRequired,
|
2018-10-08 00:44:58 +03:00
|
|
|
};
|
|
|
|
|
2019-10-01 18:11:14 +03:00
|
|
|
_updateEmojis () {
|
|
|
|
const node = this.namesNode;
|
|
|
|
|
|
|
|
if (!node || autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const emojis = node.querySelectorAll('.custom-emoji');
|
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
if (emoji.classList.contains('status-emoji')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
emoji.classList.add('status-emoji');
|
|
|
|
|
|
|
|
emoji.addEventListener('mouseenter', this.handleEmojiMouseEnter, false);
|
|
|
|
emoji.addEventListener('mouseleave', this.handleEmojiMouseLeave, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this._updateEmojis();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate () {
|
|
|
|
this._updateEmojis();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEmojiMouseEnter = ({ target }) => {
|
|
|
|
target.src = target.getAttribute('data-original');
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEmojiMouseLeave = ({ target }) => {
|
|
|
|
target.src = target.getAttribute('data-static');
|
|
|
|
}
|
|
|
|
|
2018-10-08 00:44:58 +03:00
|
|
|
handleClick = () => {
|
|
|
|
if (!this.context.router) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-21 21:01:16 +03:00
|
|
|
const { lastStatus, unread, markRead } = this.props;
|
2018-10-19 02:47:29 +03:00
|
|
|
|
|
|
|
if (unread) {
|
|
|
|
markRead();
|
|
|
|
}
|
|
|
|
|
2019-09-21 21:01:16 +03:00
|
|
|
this.context.router.history.push(`/statuses/${lastStatus.get('id')}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMarkAsRead = () => {
|
|
|
|
this.props.markRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleReply = () => {
|
|
|
|
this.props.reply(this.props.lastStatus, this.context.router.history);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDelete = () => {
|
|
|
|
this.props.delete();
|
2018-10-08 00:44:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveUp = () => {
|
|
|
|
this.props.onMoveUp(this.props.conversationId);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveDown = () => {
|
|
|
|
this.props.onMoveDown(this.props.conversationId);
|
|
|
|
}
|
|
|
|
|
2019-09-21 21:01:16 +03:00
|
|
|
handleConversationMute = () => {
|
|
|
|
this.props.onMute(this.props.lastStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleShowMore = () => {
|
|
|
|
this.props.onToggleHidden(this.props.lastStatus);
|
|
|
|
}
|
|
|
|
|
2019-10-01 18:11:14 +03:00
|
|
|
setNamesRef = (c) => {
|
|
|
|
this.namesNode = c;
|
|
|
|
}
|
|
|
|
|
2018-10-08 00:44:58 +03:00
|
|
|
render () {
|
2019-09-21 21:01:16 +03:00
|
|
|
const { accounts, lastStatus, unread, intl } = this.props;
|
2018-10-08 00:44:58 +03:00
|
|
|
|
2019-09-21 21:01:16 +03:00
|
|
|
if (lastStatus === null) {
|
2018-10-08 00:44:58 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-21 21:01:16 +03:00
|
|
|
const menu = [
|
|
|
|
{ text: intl.formatMessage(messages.open), action: this.handleClick },
|
|
|
|
null,
|
|
|
|
];
|
|
|
|
|
|
|
|
menu.push({ text: intl.formatMessage(lastStatus.get('muted') ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMute });
|
|
|
|
|
|
|
|
if (unread) {
|
|
|
|
menu.push({ text: intl.formatMessage(messages.markAsRead), action: this.handleMarkAsRead });
|
|
|
|
menu.push(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDelete });
|
|
|
|
|
|
|
|
const names = accounts.map(a => <Permalink to={`/accounts/${a.get('id')}`} href={a.get('url')} key={a.get('id')} title={a.get('acct')}><bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: a.get('display_name_html') }} /></bdi></Permalink>).reduce((prev, cur) => [prev, ', ', cur]);
|
|
|
|
|
|
|
|
const handlers = {
|
|
|
|
reply: this.handleReply,
|
|
|
|
open: this.handleClick,
|
|
|
|
moveUp: this.handleHotkeyMoveUp,
|
|
|
|
moveDown: this.handleHotkeyMoveDown,
|
|
|
|
toggleHidden: this.handleShowMore,
|
|
|
|
};
|
|
|
|
|
2018-10-08 00:44:58 +03:00
|
|
|
return (
|
2019-09-21 21:01:16 +03:00
|
|
|
<HotKeys handlers={handlers}>
|
|
|
|
<div className='conversation focusable muted' tabIndex='0'>
|
|
|
|
<div className='conversation__avatar'>
|
|
|
|
<AvatarComposite accounts={accounts} size={48} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='conversation__content'>
|
|
|
|
<div className='conversation__content__info'>
|
|
|
|
<div className='conversation__content__relative-time'>
|
|
|
|
<RelativeTimestamp timestamp={lastStatus.get('created_at')} />
|
|
|
|
</div>
|
|
|
|
|
2019-10-01 18:11:14 +03:00
|
|
|
<div className='conversation__content__names' ref={this.setNamesRef}>
|
2019-09-21 21:01:16 +03:00
|
|
|
<FormattedMessage id='conversation.with' defaultMessage='With {names}' values={{ names: <span>{names}</span> }} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<StatusContent
|
|
|
|
status={lastStatus}
|
|
|
|
onClick={this.handleClick}
|
|
|
|
expanded={!lastStatus.get('hidden')}
|
|
|
|
onExpandedToggle={this.handleShowMore}
|
|
|
|
collapsable
|
|
|
|
/>
|
|
|
|
|
|
|
|
{lastStatus.get('media_attachments').size > 0 && (
|
|
|
|
<AttachmentList
|
|
|
|
compact
|
|
|
|
media={lastStatus.get('media_attachments')}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className='status__action-bar'>
|
|
|
|
<IconButton className='status__action-bar-button' title={intl.formatMessage(messages.reply)} icon='reply' onClick={this.handleReply} />
|
|
|
|
|
|
|
|
<div className='status__action-bar-dropdown'>
|
|
|
|
<DropdownMenuContainer status={lastStatus} items={menu} icon='ellipsis-h' size={18} direction='right' title={intl.formatMessage(messages.more)} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</HotKeys>
|
2018-10-08 00:44:58 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|