2018-10-07 17:44:58 -04: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-19 20:23:58 -04:00
|
|
|
import StatusContainer from '../../../containers/status_container';
|
2018-10-07 17:44:58 -04:00
|
|
|
|
|
|
|
export default class Conversation extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
conversationId: PropTypes.string.isRequired,
|
|
|
|
accounts: ImmutablePropTypes.list.isRequired,
|
2018-10-19 20:23:58 -04:00
|
|
|
lastStatusId: PropTypes.string,
|
2018-10-18 19:47:29 -04:00
|
|
|
unread:PropTypes.bool.isRequired,
|
2018-10-07 17:44:58 -04:00
|
|
|
onMoveUp: PropTypes.func,
|
|
|
|
onMoveDown: PropTypes.func,
|
2018-10-18 19:47:29 -04:00
|
|
|
markRead: PropTypes.func.isRequired,
|
2018-10-07 17:44:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
if (!this.context.router) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-19 20:23:58 -04:00
|
|
|
const { lastStatusId, unread, markRead } = this.props;
|
2018-10-18 19:47:29 -04:00
|
|
|
|
|
|
|
if (unread) {
|
|
|
|
markRead();
|
|
|
|
}
|
|
|
|
|
2018-10-19 20:23:58 -04:00
|
|
|
this.context.router.history.push(`/statuses/${lastStatusId}`);
|
2018-10-07 17:44:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveUp = () => {
|
|
|
|
this.props.onMoveUp(this.props.conversationId);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHotkeyMoveDown = () => {
|
|
|
|
this.props.onMoveDown(this.props.conversationId);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2018-10-19 20:23:58 -04:00
|
|
|
const { accounts, lastStatusId, unread } = this.props;
|
2018-10-07 17:44:58 -04:00
|
|
|
|
2018-10-19 20:23:58 -04:00
|
|
|
if (lastStatusId === null) {
|
2018-10-07 17:44:58 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-10-19 20:23:58 -04:00
|
|
|
<StatusContainer
|
|
|
|
id={lastStatusId}
|
|
|
|
unread={unread}
|
|
|
|
otherAccounts={accounts}
|
|
|
|
onMoveUp={this.handleHotkeyMoveUp}
|
|
|
|
onMoveDown={this.handleHotkeyMoveDown}
|
2018-10-25 19:54:58 -04:00
|
|
|
onClick={this.handleClick}
|
2018-10-19 20:23:58 -04:00
|
|
|
/>
|
2018-10-07 17:44:58 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|