The code powering m.abunchtell.com https://m.abunchtell.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

86 lines
2.5 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import StatusContent from '../../../components/status_content';
  6. import RelativeTimestamp from '../../../components/relative_timestamp';
  7. import DisplayName from '../../../components/display_name';
  8. import Avatar from '../../../components/avatar';
  9. import AttachmentList from '../../../components/attachment_list';
  10. import { HotKeys } from 'react-hotkeys';
  11. export default class Conversation extends ImmutablePureComponent {
  12. static contextTypes = {
  13. router: PropTypes.object,
  14. };
  15. static propTypes = {
  16. conversationId: PropTypes.string.isRequired,
  17. accounts: ImmutablePropTypes.list.isRequired,
  18. lastStatus: ImmutablePropTypes.map.isRequired,
  19. onMoveUp: PropTypes.func,
  20. onMoveDown: PropTypes.func,
  21. };
  22. handleClick = () => {
  23. if (!this.context.router) {
  24. return;
  25. }
  26. const { lastStatus } = this.props;
  27. this.context.router.history.push(`/statuses/${lastStatus.get('id')}`);
  28. }
  29. handleHotkeyMoveUp = () => {
  30. this.props.onMoveUp(this.props.conversationId);
  31. }
  32. handleHotkeyMoveDown = () => {
  33. this.props.onMoveDown(this.props.conversationId);
  34. }
  35. render () {
  36. const { accounts, lastStatus, lastAccount } = this.props;
  37. if (lastStatus === null) {
  38. return null;
  39. }
  40. const handlers = {
  41. moveDown: this.handleHotkeyMoveDown,
  42. moveUp: this.handleHotkeyMoveUp,
  43. open: this.handleClick,
  44. };
  45. let media;
  46. if (lastStatus.get('media_attachments').size > 0) {
  47. media = <AttachmentList compact media={lastStatus.get('media_attachments')} />;
  48. }
  49. return (
  50. <HotKeys handlers={handlers}>
  51. <div className='conversation focusable' tabIndex='0' onClick={this.handleClick} role='button'>
  52. <div className='conversation__header'>
  53. <div className='conversation__avatars'>
  54. <div>{accounts.map(account => <Avatar key={account.get('id')} size={36} account={account} />)}</div>
  55. </div>
  56. <div className='conversation__time'>
  57. <RelativeTimestamp timestamp={lastStatus.get('created_at')} />
  58. <br />
  59. <DisplayName account={lastAccount} withAcct={false} />
  60. </div>
  61. </div>
  62. <StatusContent status={lastStatus} onClick={this.handleClick} />
  63. {media}
  64. </div>
  65. </HotKeys>
  66. );
  67. }
  68. }