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.
 
 
 
 

102 lines
2.7 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. @connect(mapStateToProps)
  18. @injectIntl
  19. export default class DirectTimeline extends React.PureComponent {
  20. static propTypes = {
  21. dispatch: PropTypes.func.isRequired,
  22. columnId: PropTypes.string,
  23. intl: PropTypes.object.isRequired,
  24. hasUnread: PropTypes.bool,
  25. multiColumn: PropTypes.bool,
  26. };
  27. handlePin = () => {
  28. const { columnId, dispatch } = this.props;
  29. if (columnId) {
  30. dispatch(removeColumn(columnId));
  31. } else {
  32. dispatch(addColumn('DIRECT', {}));
  33. }
  34. }
  35. handleMove = (dir) => {
  36. const { columnId, dispatch } = this.props;
  37. dispatch(moveColumn(columnId, dir));
  38. }
  39. handleHeaderClick = () => {
  40. this.column.scrollTop();
  41. }
  42. componentDidMount () {
  43. const { dispatch } = this.props;
  44. dispatch(expandDirectTimeline());
  45. this.disconnect = dispatch(connectDirectStream());
  46. }
  47. componentWillUnmount () {
  48. if (this.disconnect) {
  49. this.disconnect();
  50. this.disconnect = null;
  51. }
  52. }
  53. setRef = c => {
  54. this.column = c;
  55. }
  56. handleLoadMore = maxId => {
  57. this.props.dispatch(expandDirectTimeline({ maxId }));
  58. }
  59. render () {
  60. const { intl, hasUnread, columnId, multiColumn } = this.props;
  61. const pinned = !!columnId;
  62. return (
  63. <Column ref={this.setRef}>
  64. <ColumnHeader
  65. icon='envelope'
  66. active={hasUnread}
  67. title={intl.formatMessage(messages.title)}
  68. onPin={this.handlePin}
  69. onMove={this.handleMove}
  70. onClick={this.handleHeaderClick}
  71. pinned={pinned}
  72. multiColumn={multiColumn}
  73. />
  74. <StatusListContainer
  75. trackScroll={!pinned}
  76. scrollKey={`direct_timeline-${columnId}`}
  77. timelineId='direct'
  78. onLoadMore={this.handleLoadMore}
  79. 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." />}
  80. />
  81. </Column>
  82. );
  83. }
  84. }