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.

62 lines
2.1 KiB

7 years ago
7 years ago
  1. import { connect } from 'react-redux';
  2. import StatusList from '../../../components/status_list';
  3. import { expandTimeline, scrollTopTimeline } from '../../../actions/timelines';
  4. import Immutable from 'immutable';
  5. import { createSelector } from 'reselect';
  6. import { debounce } from 'react-decoration';
  7. const getStatusIds = 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. const regex = new RegExp(columnSettings.getIn(['regex', 'body']).trim(), 'i');
  24. showStatus = showStatus && !regex.test(statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'content']) : statusForId.get('content'));
  25. } catch(e) {
  26. // Bad regex, don't affect filters
  27. }
  28. }
  29. return showStatus;
  30. }));
  31. const mapStateToProps = (state, props) => ({
  32. statusIds: getStatusIds(state, props),
  33. isLoading: state.getIn(['timelines', props.type, 'isLoading'], true)
  34. });
  35. const mapDispatchToProps = (dispatch, { type, id }) => ({
  36. @debounce(300, true)
  37. onScrollToBottom () {
  38. dispatch(scrollTopTimeline(type, false));
  39. dispatch(expandTimeline(type, id));
  40. },
  41. @debounce(300, true)
  42. onScrollToTop () {
  43. dispatch(scrollTopTimeline(type, true));
  44. },
  45. @debounce(500)
  46. onScroll () {
  47. dispatch(scrollTopTimeline(type, false));
  48. }
  49. });
  50. export default connect(mapStateToProps, mapDispatchToProps)(StatusList);