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