2016-11-06 01:20:05 +11:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import StatusList from '../../../components/status_list';
|
2016-12-04 07:04:57 +11:00
|
|
|
import { expandTimeline, scrollTopTimeline } from '../../../actions/timelines';
|
2016-11-06 01:20:05 +11:00
|
|
|
import Immutable from 'immutable';
|
2017-01-11 03:25:10 +11:00
|
|
|
import { createSelector } from 'reselect';
|
2017-05-06 19:05:32 +10:00
|
|
|
import { debounce } from 'lodash';
|
2017-01-11 03:25:10 +11:00
|
|
|
|
2017-02-21 10:10:49 +11:00
|
|
|
const makeGetStatusIds = () => createSelector([
|
2017-01-11 03:33:32 +11:00
|
|
|
(state, { type }) => state.getIn(['settings', type], Immutable.Map()),
|
2017-01-11 03:25:10 +11:00
|
|
|
(state, { type }) => state.getIn(['timelines', type, 'items'], Immutable.List()),
|
2017-02-05 12:02:46 +11:00
|
|
|
(state) => state.get('statuses'),
|
2017-05-21 01:31:47 +10:00
|
|
|
(state) => state.getIn(['meta', 'me']),
|
2017-02-05 12:02:46 +11:00
|
|
|
], (columnSettings, statusIds, statuses, me) => statusIds.filter(id => {
|
2017-01-11 03:25:10 +11:00
|
|
|
const statusForId = statuses.get(id);
|
|
|
|
let showStatus = true;
|
|
|
|
|
|
|
|
if (columnSettings.getIn(['shows', 'reblog']) === false) {
|
|
|
|
showStatus = showStatus && statusForId.get('reblog') === null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (columnSettings.getIn(['shows', 'reply']) === false) {
|
2017-02-05 12:02:46 +11:00
|
|
|
showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
|
2017-01-11 03:25:10 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
if (columnSettings.getIn(['regex', 'body'], '').trim().length > 0) {
|
|
|
|
try {
|
2017-04-17 00:33:38 +10:00
|
|
|
if (showStatus) {
|
|
|
|
const regex = new RegExp(columnSettings.getIn(['regex', 'body']).trim(), 'i');
|
2017-05-05 07:48:48 +10:00
|
|
|
showStatus = !regex.test(statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index'));
|
2017-04-17 00:33:38 +10:00
|
|
|
}
|
2017-01-11 03:25:10 +11:00
|
|
|
} catch(e) {
|
|
|
|
// Bad regex, don't affect filters
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return showStatus;
|
|
|
|
}));
|
2016-09-04 22:04:26 +10:00
|
|
|
|
2017-02-21 10:10:49 +11:00
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getStatusIds = makeGetStatusIds();
|
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => ({
|
2017-04-24 12:49:08 +10:00
|
|
|
scrollKey: props.scrollKey,
|
|
|
|
shouldUpdateScroll: props.shouldUpdateScroll,
|
2017-02-21 10:10:49 +11:00
|
|
|
statusIds: getStatusIds(state, props),
|
|
|
|
isLoading: state.getIn(['timelines', props.type, 'isLoading'], true),
|
2017-02-23 02:30:09 +11:00
|
|
|
isUnread: state.getIn(['timelines', props.type, 'unread']) > 0,
|
2017-05-21 01:31:47 +10:00
|
|
|
hasMore: !!state.getIn(['timelines', props.type, 'next']),
|
2017-02-21 10:10:49 +11:00
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
2016-08-25 01:56:44 +10:00
|
|
|
|
2017-01-11 03:25:10 +11:00
|
|
|
const mapDispatchToProps = (dispatch, { type, id }) => ({
|
2016-12-04 07:04:57 +11:00
|
|
|
|
2017-05-06 19:05:32 +10:00
|
|
|
onScrollToBottom: debounce(() => {
|
2017-01-11 03:25:10 +11:00
|
|
|
dispatch(scrollTopTimeline(type, false));
|
|
|
|
dispatch(expandTimeline(type, id));
|
2017-05-06 19:05:32 +10:00
|
|
|
}, 300, {leading: true}),
|
2016-12-04 07:04:57 +11:00
|
|
|
|
2017-05-06 19:05:32 +10:00
|
|
|
onScrollToTop: debounce(() => {
|
2017-01-11 03:25:10 +11:00
|
|
|
dispatch(scrollTopTimeline(type, true));
|
2017-05-06 19:05:32 +10:00
|
|
|
}, 100),
|
2017-01-11 03:25:10 +11:00
|
|
|
|
2017-05-06 19:05:32 +10:00
|
|
|
onScroll: debounce(() => {
|
2017-01-11 03:25:10 +11:00
|
|
|
dispatch(scrollTopTimeline(type, false));
|
2017-05-21 01:31:47 +10:00
|
|
|
}, 100),
|
2017-01-11 03:25:10 +11:00
|
|
|
|
|
|
|
});
|
2016-09-01 06:58:10 +10:00
|
|
|
|
2017-02-21 10:10:49 +11:00
|
|
|
export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);
|