闭社主体 forked from https://github.com/tootsuite/mastodon
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.9 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. shouldUpdateScroll: PropTypes.func,
  20. columnId: PropTypes.string,
  21. intl: PropTypes.object.isRequired,
  22. hasUnread: PropTypes.bool,
  23. multiColumn: PropTypes.bool,
  24. };
  25. handlePin = () => {
  26. const { columnId, dispatch } = this.props;
  27. if (columnId) {
  28. dispatch(removeColumn(columnId));
  29. } else {
  30. dispatch(addColumn('DIRECT', {}));
  31. }
  32. }
  33. handleMove = (dir) => {
  34. const { columnId, dispatch } = this.props;
  35. dispatch(moveColumn(columnId, dir));
  36. }
  37. handleHeaderClick = () => {
  38. this.column.scrollTop();
  39. }
  40. componentDidMount () {
  41. const { dispatch } = this.props;
  42. dispatch(mountConversations());
  43. dispatch(expandConversations());
  44. this.disconnect = dispatch(connectDirectStream());
  45. }
  46. componentWillUnmount () {
  47. this.props.dispatch(unmountConversations());
  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(expandConversations({ maxId }));
  58. }
  59. render () {
  60. const { intl, hasUnread, columnId, multiColumn, shouldUpdateScroll } = this.props;
  61. const pinned = !!columnId;
  62. return (
  63. <Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.title)}>
  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. <ConversationsListContainer
  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. shouldUpdateScroll={shouldUpdateScroll}
  81. />
  82. </Column>
  83. );
  84. }
  85. }