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.

107 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 {
  8. refreshDirectTimeline,
  9. expandDirectTimeline,
  10. } from 'flavours/glitch/actions/timelines';
  11. import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/columns';
  12. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  13. import ColumnSettingsContainer from './containers/column_settings_container';
  14. import { connectDirectStream } from 'flavours/glitch/actions/streaming';
  15. const messages = defineMessages({
  16. title: { id: 'column.direct', defaultMessage: 'Direct messages' },
  17. });
  18. const mapStateToProps = state => ({
  19. hasUnread: state.getIn(['timelines', 'direct', 'unread']) > 0,
  20. });
  21. @connect(mapStateToProps)
  22. @injectIntl
  23. export default class DirectTimeline extends React.PureComponent {
  24. static propTypes = {
  25. dispatch: PropTypes.func.isRequired,
  26. columnId: PropTypes.string,
  27. intl: PropTypes.object.isRequired,
  28. hasUnread: PropTypes.bool,
  29. multiColumn: PropTypes.bool,
  30. };
  31. handlePin = () => {
  32. const { columnId, dispatch } = this.props;
  33. if (columnId) {
  34. dispatch(removeColumn(columnId));
  35. } else {
  36. dispatch(addColumn('DIRECT', {}));
  37. }
  38. }
  39. handleMove = (dir) => {
  40. const { columnId, dispatch } = this.props;
  41. dispatch(moveColumn(columnId, dir));
  42. }
  43. handleHeaderClick = () => {
  44. this.column.scrollTop();
  45. }
  46. componentDidMount () {
  47. const { dispatch } = this.props;
  48. dispatch(refreshDirectTimeline());
  49. this.disconnect = dispatch(connectDirectStream());
  50. }
  51. componentWillUnmount () {
  52. if (this.disconnect) {
  53. this.disconnect();
  54. this.disconnect = null;
  55. }
  56. }
  57. setRef = c => {
  58. this.column = c;
  59. }
  60. handleLoadMore = () => {
  61. this.props.dispatch(expandDirectTimeline());
  62. }
  63. render () {
  64. const { intl, hasUnread, columnId, multiColumn } = this.props;
  65. const pinned = !!columnId;
  66. return (
  67. <Column ref={this.setRef}>
  68. <ColumnHeader
  69. icon='envelope'
  70. active={hasUnread}
  71. title={intl.formatMessage(messages.title)}
  72. onPin={this.handlePin}
  73. onMove={this.handleMove}
  74. onClick={this.handleHeaderClick}
  75. pinned={pinned}
  76. multiColumn={multiColumn}
  77. >
  78. <ColumnSettingsContainer />
  79. </ColumnHeader>
  80. <StatusListContainer
  81. trackScroll={!pinned}
  82. scrollKey={`direct_timeline-${columnId}`}
  83. timelineId='direct'
  84. loadMore={this.handleLoadMore}
  85. 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." />}
  86. />
  87. </Column>
  88. );
  89. }
  90. }