logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

status_list_container.js (2396B)


  1. import { connect } from 'react-redux';
  2. import StatusList from '../../../components/status_list';
  3. import { scrollTopTimeline } 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 = () => createSelector([
  9. (state, { type }) => state.getIn(['settings', type], ImmutableMap()),
  10. (state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()),
  11. (state) => state.get('statuses'),
  12. ], (columnSettings, statusIds, statuses) => {
  13. const rawRegex = columnSettings.getIn(['regex', 'body'], '').trim();
  14. let regex = null;
  15. try {
  16. regex = rawRegex && new RegExp(rawRegex, 'i');
  17. } catch (e) {
  18. // Bad regex, don't affect filters
  19. }
  20. return statusIds.filter(id => {
  21. const statusForId = statuses.get(id);
  22. let showStatus = true;
  23. if (columnSettings.getIn(['shows', 'reblog']) === false) {
  24. showStatus = showStatus && statusForId.get('reblog') === null;
  25. }
  26. if (columnSettings.getIn(['shows', 'reply']) === false) {
  27. showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
  28. }
  29. if (showStatus && regex && statusForId.get('account') !== me) {
  30. const searchIndex = statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index');
  31. showStatus = !regex.test(searchIndex);
  32. }
  33. return showStatus;
  34. });
  35. });
  36. const makeMapStateToProps = () => {
  37. const getStatusIds = makeGetStatusIds();
  38. const mapStateToProps = (state, { timelineId }) => ({
  39. statusIds: getStatusIds(state, { type: timelineId }),
  40. isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
  41. isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
  42. hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
  43. });
  44. return mapStateToProps;
  45. };
  46. const mapDispatchToProps = (dispatch, { timelineId }) => ({
  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);