2018-10-08 08:44:58 +11:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
import classNames from 'classnames';
|
2023-10-20 04:44:55 +11:00
|
|
|
import { Link, withRouter } from 'react-router-dom';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2018-10-08 08:44:58 +11:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2024-01-12 21:31:24 +11:00
|
|
|
import MoreHorizIcon from '@material-symbols/svg-600/outlined/more_horiz.svg?react';
|
|
|
|
import ReplyIcon from '@material-symbols/svg-600/outlined/reply.svg?react';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { HotKeys } from 'react-hotkeys';
|
|
|
|
|
2019-09-22 04:01:16 +10:00
|
|
|
import AttachmentList from 'mastodon/components/attachment_list';
|
|
|
|
import AvatarComposite from 'mastodon/components/avatar_composite';
|
2023-05-09 11:11:56 +10:00
|
|
|
import { IconButton } from 'mastodon/components/icon_button';
|
|
|
|
import { RelativeTimestamp } from 'mastodon/components/relative_timestamp';
|
2023-05-24 01:15:17 +10:00
|
|
|
import StatusContent from 'mastodon/components/status_content';
|
|
|
|
import DropdownMenuContainer from 'mastodon/containers/dropdown_menu_container';
|
2019-10-02 01:11:14 +10:00
|
|
|
import { autoPlayGif } from 'mastodon/initial_state';
|
2023-10-20 04:44:55 +11:00
|
|
|
import { WithRouterPropTypes } from 'mastodon/utils/react_router';
|
2018-10-08 08:44:58 +11:00
|
|
|
|
2019-09-22 04:01:16 +10: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 {
|
2018-10-08 08:44:58 +11:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
conversationId: PropTypes.string.isRequired,
|
|
|
|
accounts: ImmutablePropTypes.list.isRequired,
|
2019-09-22 04:01:16 +10:00
|
|
|
lastStatus: ImmutablePropTypes.map,
|
2018-10-19 10:47:29 +11:00
|
|
|
unread:PropTypes.bool.isRequired,
|
2020-07-09 23:09:19 +10:00
|
|
|
scrollKey: PropTypes.string,
|
2018-10-08 08:44:58 +11:00
|
|
|
onMoveUp: PropTypes.func,
|
|
|
|
onMoveDown: PropTypes.func,
|
2018-10-19 10:47:29 +11:00
|
|
|
markRead: PropTypes.func.isRequired,
|
2019-10-01 23:07:58 +10:00
|
|
|
delete: PropTypes.func.isRequired,
|
2019-09-22 04:01:16 +10:00
|
|
|
intl: PropTypes.object.isRequired,
|
2023-10-20 04:44:55 +11:00
|
|
|
...WithRouterPropTypes,
|
2018-10-08 08:44:58 +11:00
|
|
|
};
|
|
|
|
|
2021-02-01 07:25:31 +11:00
|
|
|
handleMouseEnter = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
2019-10-02 01:11:14 +10:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-01 07:25:31 +11:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-10-02 01:11:14 +10:00
|
|
|
|
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
2021-02-01 07:25:31 +11:00
|
|
|
emoji.src = emoji.getAttribute('data-original');
|
2019-10-02 01:11:14 +10:00
|
|
|
}
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-10-02 01:11:14 +10:00
|
|
|
|
2021-02-01 07:25:31 +11:00
|
|
|
handleMouseLeave = ({ currentTarget }) => {
|
|
|
|
if (autoPlayGif) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-02 01:11:14 +10:00
|
|
|
|
2021-02-01 07:25:31 +11:00
|
|
|
const emojis = currentTarget.querySelectorAll('.custom-emoji');
|
2019-10-02 01:11:14 +10:00
|
|
|
|
2021-02-01 07:25:31 +11:00
|
|
|
for (var i = 0; i < emojis.length; i++) {
|
|
|
|
let emoji = emojis[i];
|
|
|
|
emoji.src = emoji.getAttribute('data-static');
|
|
|
|
}
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-10-02 01:11:14 +10:00
|
|
|
|
2018-10-08 08:44:58 +11:00
|
|
|
handleClick = () => {
|
2023-10-20 04:44:55 +11:00
|
|
|
if (!this.props.history) {
|
2018-10-08 08:44:58 +11:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-22 04:01:16 +10:00
|
|
|
const { lastStatus, unread, markRead } = this.props;
|
2018-10-19 10:47:29 +11:00
|
|
|
|
|
|
|
if (unread) {
|
|
|
|
markRead();
|
|
|
|
}
|
|
|
|
|
2023-10-20 04:44:55 +11:00
|
|
|
this.props.history.push(`/@${lastStatus.getIn(['account', 'acct'])}/${lastStatus.get('id')}`);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-09-22 04:01:16 +10:00
|
|
|
|
|
|
|
handleMarkAsRead = () => {
|
|
|
|
this.props.markRead();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-09-22 04:01:16 +10:00
|
|
|
|
|
|
|
handleReply = () => {
|
2023-10-20 04:44:55 +11:00
|
|
|
this.props.reply(this.props.lastStatus, this.props.history);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-09-22 04:01:16 +10:00
|
|
|
|
|
|
|
handleDelete = () => {
|
|
|
|
this.props.delete();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2018-10-08 08:44:58 +11:00
|
|
|
|
|
|
|
handleHotkeyMoveUp = () => {
|
|
|
|
this.props.onMoveUp(this.props.conversationId);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2018-10-08 08:44:58 +11:00
|
|
|
|
|
|
|
handleHotkeyMoveDown = () => {
|
|
|
|
this.props.onMoveDown(this.props.conversationId);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2018-10-08 08:44:58 +11:00
|
|
|
|
2019-09-22 04:01:16 +10:00
|
|
|
handleConversationMute = () => {
|
|
|
|
this.props.onMute(this.props.lastStatus);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-09-22 04:01:16 +10:00
|
|
|
|
|
|
|
handleShowMore = () => {
|
|
|
|
this.props.onToggleHidden(this.props.lastStatus);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2019-09-22 04:01:16 +10:00
|
|
|
|
2018-10-08 08:44:58 +11:00
|
|
|
render () {
|
2020-07-09 23:09:19 +10:00
|
|
|
const { accounts, lastStatus, unread, scrollKey, intl } = this.props;
|
2018-10-08 08:44:58 +11:00
|
|
|
|
2019-09-22 04:01:16 +10:00
|
|
|
if (lastStatus === null) {
|
2018-10-08 08:44:58 +11:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-09-22 04:01:16 +10: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 });
|
|
|
|
|
2022-11-14 07:10:20 +11:00
|
|
|
const names = accounts.map(a => <Link to={`/@${a.get('acct')}`} key={a.get('id')} title={a.get('acct')}><bdi><strong className='display-name__html' dangerouslySetInnerHTML={{ __html: a.get('display_name_html') }} /></bdi></Link>).reduce((prev, cur) => [prev, ', ', cur]);
|
2019-09-22 04:01:16 +10:00
|
|
|
|
|
|
|
const handlers = {
|
|
|
|
reply: this.handleReply,
|
|
|
|
open: this.handleClick,
|
|
|
|
moveUp: this.handleHotkeyMoveUp,
|
|
|
|
moveDown: this.handleHotkeyMoveDown,
|
|
|
|
toggleHidden: this.handleShowMore,
|
|
|
|
};
|
|
|
|
|
2018-10-08 08:44:58 +11:00
|
|
|
return (
|
2019-09-22 04:01:16 +10:00
|
|
|
<HotKeys handlers={handlers}>
|
2023-04-05 00:33:44 +10:00
|
|
|
<div className={classNames('conversation focusable muted', { 'conversation--unread': unread })} tabIndex={0}>
|
2020-04-01 04:40:23 +11:00
|
|
|
<div className='conversation__avatar' onClick={this.handleClick} role='presentation'>
|
2019-09-22 04:01:16 +10: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 17:06:20 +11:00
|
|
|
{unread && <span className='conversation__unread' />} <RelativeTimestamp timestamp={lastStatus.get('created_at')} />
|
2019-09-22 04:01:16 +10:00
|
|
|
</div>
|
|
|
|
|
2021-02-01 07:25:31 +11:00
|
|
|
<div className='conversation__content__names' onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
|
2019-09-22 04:01:16 +10: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}
|
2023-04-14 19:01:23 +10:00
|
|
|
collapsible
|
2019-09-22 04:01:16 +10:00
|
|
|
/>
|
|
|
|
|
|
|
|
{lastStatus.get('media_attachments').size > 0 && (
|
|
|
|
<AttachmentList
|
|
|
|
compact
|
|
|
|
media={lastStatus.get('media_attachments')}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className='status__action-bar'>
|
2023-10-25 04:45:08 +11:00
|
|
|
<IconButton className='status__action-bar-button' title={intl.formatMessage(messages.reply)} icon='reply' iconComponent={ReplyIcon} onClick={this.handleReply} />
|
2019-09-22 04:01:16 +10:00
|
|
|
|
|
|
|
<div className='status__action-bar-dropdown'>
|
2020-07-09 23:09:19 +10:00
|
|
|
<DropdownMenuContainer
|
|
|
|
scrollKey={scrollKey}
|
|
|
|
status={lastStatus}
|
|
|
|
items={menu}
|
|
|
|
icon='ellipsis-h'
|
2023-10-25 04:45:08 +11:00
|
|
|
iconComponent={MoreHorizIcon}
|
2020-07-09 23:09:19 +10:00
|
|
|
size={18}
|
|
|
|
direction='right'
|
|
|
|
title={intl.formatMessage(messages.more)}
|
|
|
|
/>
|
2019-09-22 04:01:16 +10:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</HotKeys>
|
2018-10-08 08:44:58 +11:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 13:17:53 +11:00
|
|
|
|
2023-10-20 04:44:55 +11:00
|
|
|
export default withRouter(injectIntl(Conversation));
|