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.

63 lines
2.2 KiB

7 years ago
  1. import { connect } from 'react-redux';
  2. import StatusList from '../../../components/status_list';
  3. import { scrollTopTimeline, loadPending } from '../../../actions/timelines';
  4. import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
  5. import { createSelector } from 'reselect';
  6. import { debounce } from 'lodash';
  7. import { me } from '../../../initial_state';
  8. const makeGetStatusIds = (pending = false) => createSelector([
  9. (state, { type }) => state.getIn(['settings', type], ImmutableMap()),
  10. (state, { type }) => state.getIn(['timelines', type, pending ? 'pendingItems' : 'items'], ImmutableList()),
  11. (state) => state.get('statuses'),
  12. ], (columnSettings, statusIds, statuses) => {
  13. return statusIds.filter(id => {
  14. if (id === null) return true;
  15. const statusForId = statuses.get(id);
  16. let showStatus = true;
  17. if (statusForId.get('account') === me) return true;
  18. if (columnSettings.getIn(['shows', 'reblog']) === false) {
  19. showStatus = showStatus && statusForId.get('reblog') === null;
  20. }
  21. if (columnSettings.getIn(['shows', 'reply']) === false) {
  22. showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
  23. }
  24. return showStatus;
  25. });
  26. });
  27. const makeMapStateToProps = () => {
  28. const getStatusIds = makeGetStatusIds();
  29. const getPendingStatusIds = makeGetStatusIds(true);
  30. const mapStateToProps = (state, { timelineId }) => ({
  31. statusIds: getStatusIds(state, { type: timelineId }),
  32. isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
  33. isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
  34. hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
  35. numPending: getPendingStatusIds(state, { type: timelineId }).size,
  36. });
  37. return mapStateToProps;
  38. };
  39. const mapDispatchToProps = (dispatch, { timelineId }) => ({
  40. onScrollToTop: debounce(() => {
  41. dispatch(scrollTopTimeline(timelineId, true));
  42. }, 100),
  43. onScroll: debounce(() => {
  44. dispatch(scrollTopTimeline(timelineId, false));
  45. }, 100),
  46. onLoadPending: () => dispatch(loadPending(timelineId)),
  47. });
  48. export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);