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.
 
 
 
 

104 lines
2.8 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import StatusListContainer from '../ui/containers/status_list_container';
  5. import Column from '../../components/column';
  6. import ColumnHeader from '../../components/column_header';
  7. import { expandDirectTimeline } from '../../actions/timelines';
  8. import { addColumn, removeColumn, moveColumn } from '../../actions/columns';
  9. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  10. import { connectDirectStream } from '../../actions/streaming';
  11. const messages = defineMessages({
  12. title: { id: 'column.direct', defaultMessage: 'Direct messages' },
  13. });
  14. const mapStateToProps = state => ({
  15. hasUnread: state.getIn(['timelines', 'direct', 'unread']) > 0,
  16. });
  17. export default @connect(mapStateToProps)
  18. @injectIntl
  19. class DirectTimeline extends React.PureComponent {
  20. static propTypes = {
  21. dispatch: PropTypes.func.isRequired,
  22. shouldUpdateScroll: PropTypes.func,
  23. columnId: PropTypes.string,
  24. intl: PropTypes.object.isRequired,
  25. hasUnread: PropTypes.bool,
  26. multiColumn: PropTypes.bool,
  27. };
  28. handlePin = () => {
  29. const { columnId, dispatch } = this.props;
  30. if (columnId) {
  31. dispatch(removeColumn(columnId));
  32. } else {
  33. dispatch(addColumn('DIRECT', {}));
  34. }
  35. }
  36. handleMove = (dir) => {
  37. const { columnId, dispatch } = this.props;
  38. dispatch(moveColumn(columnId, dir));
  39. }
  40. handleHeaderClick = () => {
  41. this.column.scrollTop();
  42. }
  43. componentDidMount () {
  44. const { dispatch } = this.props;
  45. dispatch(expandDirectTimeline());
  46. this.disconnect = dispatch(connectDirectStream());
  47. }
  48. componentWillUnmount () {
  49. if (this.disconnect) {
  50. this.disconnect();
  51. this.disconnect = null;
  52. }
  53. }
  54. setRef = c => {
  55. this.column = c;
  56. }
  57. handleLoadMore = maxId => {
  58. this.props.dispatch(expandDirectTimeline({ maxId }));
  59. }
  60. render () {
  61. const { intl, shouldUpdateScroll, hasUnread, columnId, multiColumn } = this.props;
  62. const pinned = !!columnId;
  63. return (
  64. <Column ref={this.setRef} label={intl.formatMessage(messages.title)}>
  65. <ColumnHeader
  66. icon='envelope'
  67. active={hasUnread}
  68. title={intl.formatMessage(messages.title)}
  69. onPin={this.handlePin}
  70. onMove={this.handleMove}
  71. onClick={this.handleHeaderClick}
  72. pinned={pinned}
  73. multiColumn={multiColumn}
  74. />
  75. <StatusListContainer
  76. trackScroll={!pinned}
  77. scrollKey={`direct_timeline-${columnId}`}
  78. timelineId='direct'
  79. onLoadMore={this.handleLoadMore}
  80. emptyMessage={<FormattedMessage id='empty_column.direct' defaultMessage="You don't have any direct messages yet. When you send or receive one, it will show up here." />}
  81. shouldUpdateScroll={shouldUpdateScroll}
  82. />
  83. </Column>
  84. );
  85. }
  86. }