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.

100 lines
2.8 KiB

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