2019-06-09 10:07:23 +00: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 18:01:16 +00:00
|
|
|
import StatusContent from 'flavours/glitch/components/status_content';
|
|
|
|
import AttachmentList from 'flavours/glitch/components/attachment_list';
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import DropdownMenuContainer from 'flavours/glitch/containers/dropdown_menu_container';
|
|
|
|
import AvatarComposite from 'flavours/glitch/components/avatar_composite';
|
|
|
|
import Permalink from 'flavours/glitch/components/permalink';
|
|
|
|
import IconButton from 'flavours/glitch/components/icon_button';
|
|
|
|
import RelativeTimestamp from 'flavours/glitch/components/relative_timestamp';
|
|
|
|
import { HotKeys } from 'react-hotkeys';
|
2022-10-11 08:17:04 +00:00
|
|
|
import { autoPlayGif } from 'flavours/glitch/initial_state';
|
2019-12-01 06:06:20 +00:00
|
|
|
import classNames from 'classnames';
|
2019-06-09 10:07:23 +00:00
|
|
|
|
2019-09-21 18:01:16 +00: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' },
|
|
|
|
});
|
|
|
|
|
|
|
|
class Conversation extends ImmutablePureComponent {
|
2019-06-09 10:07:23 +00:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
conversationId: PropTypes.string.isRequired,
|
|
|
|
accounts: ImmutablePropTypes.list.isRequired,
|
2019-09-21 18:01:16 +00:00
|
|
|
lastStatus: ImmutablePropTypes.map,
|
2019-06-09 10:07:23 +00:00
|
|
|
unread:PropTypes.bool.isRequired,
|
2020-07-09 13:09:19 +00:00
|
|
|
scrollKey: PropTypes.string,
|
2019-06-09 10:07:23 +00:00
|
|
|
onMoveUp: PropTypes.func,
|
|
|
|
onMoveDown: PropTypes.func,
|
|
|
|
markRead: PropTypes.func.isRequired,
|
2019-10-01 13:07:58 +00:00
|
|
|
delete: PropTypes.func.isRequired,
|
2019-09-21 18:01:16 +00:00
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
isExpanded: undefined,
|
2019-06-09 10:07:23 +00:00
|
|
|
};
|
|
|
|
|
2019-09-21 18:01:16 +00:00
|
|
|
parseClick = (e, destination) => {
|
|
|
|
const { router } = this.context;
|
|
|
|
const { lastStatus, unread, markRead } = this.props;
|
|
|
|
if (!router) return;
|
|
|
|
|
|
|
|
if (e.button === 0 && !(e.ctrlKey || e.altKey || e.metaKey)) {
|
|
|
|
if (destination === undefined) {
|
|
|
|
if (unread) {
|
|
|
|
markRead();
|
|
|
|
}
|
|
|
|
destination = `/statuses/${lastStatus.get('id')}`;
|
|
|
|
}
|
2023-02-03 19:52:07 +00:00
|
|
|
let state = { ...router.history.location.state };
|
2019-09-21 18:01:16 +00:00
|
|
|
state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
|
|
|
|
router.history.push(destination, state);
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-09-21 18:01:16 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
handleMouseEnter = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
2019-10-01 15:11:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-10-01 15:11:14 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
2021-01-31 20:25:31 +00:00
|
|
|
emoji.src = emoji.getAttribute('data-original');
|
2019-10-01 15:11:14 +00:00
|
|
|
}
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-10-01 15:11:14 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
handleMouseLeave = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-01 15:11:14 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-10-01 15:11:14 +00:00
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
emoji.src = emoji.getAttribute('data-static');
|
|
|
|
}
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-10-01 15:11:14 +00:00
|
|
|
|
2019-06-09 10:07:23 +00:00
|
|
|
handleClick = () => {
|
|
|
|
if (!this.context.router) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-21 18:01:16 +00:00
|
|
|
const { lastStatus, unread, markRead } = this.props;
|
2019-06-09 10:07:23 +00:00
|
|
|
|
|
|
|
if (unread) {
|
|
|
|
markRead();
|
|
|
|
}
|
|
|
|
|
2021-09-27 05:24:04 +00:00
|
|
|
this.context.router.history.push(`/@${lastStatus.getIn(['account', 'acct'])}/${lastStatus.get('id')}`);
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-09-21 18:01:16 +00:00
|
|
|
|
|
|
|
handleMarkAsRead = () => {
|
|
|
|
this.props.markRead();
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-09-21 18:01:16 +00:00
|
|
|
|
|
|
|
handleReply = () => {
|
|
|
|
this.props.reply(this.props.lastStatus, this.context.router.history);
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-09-21 18:01:16 +00:00
|
|
|
|
|
|
|
handleDelete = () => {
|
|
|
|
this.props.delete();
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-06-09 10:07:23 +00:00
|
|
|
|
|
|
|
handleHotkeyMoveUp = () => {
|
|
|
|
this.props.onMoveUp(this.props.conversationId);
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-06-09 10:07:23 +00:00
|
|
|
|
|
|
|
handleHotkeyMoveDown = () => {
|
|
|
|
this.props.onMoveDown(this.props.conversationId);
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-06-09 10:07:23 +00:00
|
|
|
|
2019-09-21 18:01:16 +00:00
|
|
|
handleConversationMute = () => {
|
|
|
|
this.props.onMute(this.props.lastStatus);
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-09-21 18:01:16 +00:00
|
|
|
|
|
|
|
handleShowMore = () => {
|
2022-07-24 18:01:30 +00:00
|
|
|
this.props.onToggleHidden(this.props.lastStatus);
|
|
|
|
|
2019-09-21 18:01:16 +00:00
|
|
|
if (this.props.lastStatus.get('spoiler_text')) {
|
|
|
|
this.setExpansion(!this.state.isExpanded);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
setExpansion = value => {
|
|
|
|
this.setState({ isExpanded: value });
|
2023-02-03 19:52:07 +00:00
|
|
|
};
|
2019-09-21 18:01:16 +00:00
|
|
|
|
2019-06-09 10:07:23 +00:00
|
|
|
render () {
|
2020-07-09 13:09:19 +00:00
|
|
|
const { accounts, lastStatus, unread, scrollKey, intl } = this.props;
|
2019-06-09 10:07:23 +00:00
|
|
|
|
2019-09-21 18:01:16 +00:00
|
|
|
if (lastStatus === null) {
|
2019-06-09 10:07:23 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-07-24 18:01:30 +00:00
|
|
|
const isExpanded = this.props.settings.getIn(['content_warnings', 'shared_state']) ? !lastStatus.get('hidden') : this.state.isExpanded;
|
|
|
|
|
2019-09-21 18:01:16 +00: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 });
|
|
|
|
|
2021-09-26 03:46:13 +00:00
|
|
|
const names = accounts.map(a => <Permalink to={`/@${a.get('acct')}`} 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]);
|
2019-09-21 18:01:16 +00:00
|
|
|
|
|
|
|
const handlers = {
|
|
|
|
reply: this.handleReply,
|
|
|
|
open: this.handleClick,
|
|
|
|
moveUp: this.handleHotkeyMoveUp,
|
|
|
|
moveDown: this.handleHotkeyMoveDown,
|
|
|
|
toggleHidden: this.handleShowMore,
|
|
|
|
};
|
|
|
|
|
|
|
|
let media = null;
|
|
|
|
if (lastStatus.get('media_attachments').size > 0) {
|
|
|
|
media = <AttachmentList compact media={lastStatus.get('media_attachments')} />;
|
|
|
|
}
|
|
|
|
|
2019-06-09 10:07:23 +00:00
|
|
|
return (
|
2019-09-21 18:01:16 +00:00
|
|
|
<HotKeys handlers={handlers}>
|
2023-04-04 14:33:44 +00:00
|
|
|
<div className={classNames('conversation focusable muted', { 'conversation--unread': unread })} tabIndex={0}>
|
2020-03-31 17:40:23 +00:00
|
|
|
<div className='conversation__avatar' onClick={this.handleClick} role='presentation'>
|
2019-09-21 18:01:16 +00:00
|
|
|
<AvatarComposite accounts={accounts} size={48} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='conversation__content'>
|
|
|
|
<div className='conversation__content__info'>
|
|
|
|
<div className='conversation__content__relative-time'>
|
2019-12-01 06:06:20 +00:00
|
|
|
{unread && <span className='conversation__unread' />} <RelativeTimestamp timestamp={lastStatus.get('created_at')} />
|
2019-09-21 18:01:16 +00:00
|
|
|
</div>
|
|
|
|
|
2021-01-31 20:25:31 +00:00
|
|
|
<div className='conversation__content__names' onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
|
2019-09-21 18:01:16 +00:00
|
|
|
<FormattedMessage id='conversation.with' defaultMessage='With {names}' values={{ names: <span>{names}</span> }} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<StatusContent
|
|
|
|
status={lastStatus}
|
|
|
|
parseClick={this.parseClick}
|
|
|
|
expanded={isExpanded}
|
|
|
|
onExpandedToggle={this.handleShowMore}
|
2023-04-14 09:01:23 +00:00
|
|
|
collapsible
|
2019-09-21 18:01:16 +00:00
|
|
|
media={media}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<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'>
|
2020-07-09 13:09:19 +00:00
|
|
|
<DropdownMenuContainer
|
|
|
|
scrollKey={scrollKey}
|
|
|
|
status={lastStatus}
|
|
|
|
items={menu}
|
|
|
|
icon='ellipsis-h'
|
|
|
|
size={18}
|
|
|
|
direction='right'
|
|
|
|
title={intl.formatMessage(messages.more)}
|
|
|
|
/>
|
2019-09-21 18:01:16 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</HotKeys>
|
2019-06-09 10:07:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 22:15:25 +00:00
|
|
|
|
|
|
|
export default injectIntl(Conversation);
|