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.

68 lines
2.3 KiB

7 years ago
7 years ago
  1. import { connect } from 'react-redux';
  2. import StatusList from '../../../components/status_list';
  3. import { scrollTopTimeline } from '../../../actions/timelines';
  4. import Immutable from 'immutable';
  5. import { createSelector } from 'reselect';
  6. import { debounce } from 'lodash';
  7. const makeGetStatusIds = () => createSelector([
  8. (state, { type }) => state.getIn(['settings', type], Immutable.Map()),
  9. (state, { type }) => state.getIn(['timelines', type, 'items'], Immutable.List()),
  10. (state) => state.get('statuses'),
  11. (state) => state.getIn(['meta', 'me']),
  12. ], (columnSettings, statusIds, statuses, me) => statusIds.filter(id => {
  13. const statusForId = statuses.get(id);
  14. let showStatus = true;
  15. if (columnSettings.getIn(['shows', 'reblog']) === false) {
  16. showStatus = showStatus && statusForId.get('reblog') === null;
  17. }
  18. if (columnSettings.getIn(['shows', 'reply']) === false) {
  19. showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
  20. }
  21. if (columnSettings.getIn(['regex', 'body'], '').trim().length > 0) {
  22. try {
  23. if (showStatus) {
  24. const regex = new RegExp(columnSettings.getIn(['regex', 'body']).trim(), 'i');
  25. showStatus = !regex.test(statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index'));
  26. }
  27. } catch(e) {
  28. // Bad regex, don't affect filters
  29. }
  30. }
  31. return showStatus;
  32. }));
  33. const makeMapStateToProps = () => {
  34. const getStatusIds = makeGetStatusIds();
  35. const mapStateToProps = (state, { timelineId }) => ({
  36. statusIds: getStatusIds(state, { type: timelineId }),
  37. isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
  38. hasMore: !!state.getIn(['timelines', timelineId, 'next']),
  39. });
  40. return mapStateToProps;
  41. };
  42. const mapDispatchToProps = (dispatch, { timelineId, loadMore }) => ({
  43. onScrollToBottom: debounce(() => {
  44. dispatch(scrollTopTimeline(timelineId, false));
  45. loadMore();
  46. }, 300, { leading: true }),
  47. onScrollToTop: debounce(() => {
  48. dispatch(scrollTopTimeline(timelineId, true));
  49. }, 100),
  50. onScroll: debounce(() => {
  51. dispatch(scrollTopTimeline(timelineId, false));
  52. }, 100),
  53. });
  54. export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);