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.9 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import StatusListContainer from 'flavours/glitch/features/ui/containers/status_list_container';
  5. import Column from 'flavours/glitch/components/column';
  6. import ColumnHeader from 'flavours/glitch/components/column_header';
  7. import { expandDirectTimeline } from 'flavours/glitch/actions/timelines';
  8. import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/columns';
  9. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  10. import ColumnSettingsContainer from './containers/column_settings_container';
  11. import { connectDirectStream } from 'flavours/glitch/actions/streaming';
  12. const messages = defineMessages({
  13. title: { id: 'column.direct', defaultMessage: 'Direct messages' },
  14. });
  15. const mapStateToProps = state => ({
  16. hasUnread: state.getIn(['timelines', 'direct', 'unread']) > 0,
  17. });
  18. @connect(mapStateToProps)
  19. @injectIntl
  20. export default class DirectTimeline extends React.PureComponent {
  21. static propTypes = {
  22. dispatch: PropTypes.func.isRequired,
  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, 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. <ColumnSettingsContainer />
  76. </ColumnHeader>
  77. <StatusListContainer
  78. trackScroll={!pinned}
  79. scrollKey={`direct_timeline-${columnId}`}
  80. timelineId='direct'
  81. onLoadMore={this.handleLoadMore}
  82. 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." />}
  83. />
  84. </Column>
  85. );
  86. }
  87. }