2018-10-07 22:44:58 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2018-10-20 01:23:58 +01:00
|
|
|
import StatusContainer from '../../../containers/status_container';
|
2018-10-07 22:44:58 +01:00
|
|
|
|
|
|
|
export default class Conversation extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
conversationId: PropTypes.string.isRequired,
|
|
|
|
accounts: ImmutablePropTypes.list.isRequired,
|
2018-10-20 01:23:58 +01:00
|
|
|
lastStatusId: PropTypes.string,
|
2018-10-19 00:47:29 +01:00
|
|
|
unread:PropTypes.bool.isRequired,
|
2018-10-07 22:44:58 +01:00
|
|
|
onMoveUp: PropTypes.func,
|
|
|
|
onMoveDown: PropTypes.func,
|
2018-10-19 00:47:29 +01:00
|
|
|
markRead: PropTypes.func.isRequired,
|
2018-10-07 22:44:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
if (!this.context.router) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-20 01:23:58 +01:00
|
|
|
const { lastStatusId, unread, markRead } = this.props;
|
2018-10-19 00:47:29 +01:00
|
|
|
|
|
|
|
if (unread) {
|
|
|
|
markRead();
|
|
|
|
}
|
|
|
|
|
2018-10-20 01:23:58 +01:00
|
|
|
this.context.router.history.push(`/statuses/${lastStatusId}`);
|
2018-10-07 22:44:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveUp = () => {
|
|
|
|
this.props.onMoveUp(this.props.conversationId);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveDown = () => {
|
|
|
|
this.props.onMoveDown(this.props.conversationId);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-10-20 01:23:58 +01:00
|
|
|
const { accounts, lastStatusId, unread } = this.props;
|
2018-10-07 22:44:58 +01:00
|
|
|
|
2018-10-20 01:23:58 +01:00
|
|
|
if (lastStatusId === null) {
|
2018-10-07 22:44:58 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-10-20 01:23:58 +01:00
|
|
|
<StatusContainer
|
|
|
|
id={lastStatusId}
|
|
|
|
unread={unread}
|
|
|
|
otherAccounts={accounts}
|
|
|
|
onMoveUp={this.handleHotkeyMoveUp}
|
|
|
|
onMoveDown={this.handleHotkeyMoveDown}
|
2018-10-26 00:54:58 +01:00
|
|
|
onClick={this.handleClick}
|
2018-10-20 01:23:58 +01:00
|
|
|
/>
|
2018-10-07 22:44:58 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|