2016-11-05 09:20:05 -05:00
|
|
|
import { connect } from 'react-redux';
|
2017-12-04 01:26:40 -06:00
|
|
|
import StatusList from 'flavours/glitch/components/status_list';
|
|
|
|
import { scrollTopTimeline } from 'flavours/glitch/actions/timelines';
|
2017-07-10 18:00:14 -05:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
2017-01-10 10:25:10 -06:00
|
|
|
import { createSelector } from 'reselect';
|
2017-05-06 04:05:32 -05:00
|
|
|
import { debounce } from 'lodash';
|
2017-12-04 01:26:40 -06:00
|
|
|
import { me } from 'flavours/glitch/util/initial_state';
|
2017-01-10 10:25:10 -06:00
|
|
|
|
2017-02-20 17:10:49 -06:00
|
|
|
const makeGetStatusIds = () => createSelector([
|
2017-07-10 18:00:14 -05:00
|
|
|
(state, { type }) => state.getIn(['settings', type], ImmutableMap()),
|
|
|
|
(state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()),
|
2017-02-04 19:02:46 -06:00
|
|
|
(state) => state.get('statuses'),
|
2017-10-30 21:27:48 -05:00
|
|
|
], (columnSettings, statusIds, statuses) => {
|
2017-07-18 08:20:38 -05:00
|
|
|
const rawRegex = columnSettings.getIn(['regex', 'body'], '').trim();
|
|
|
|
let regex = null;
|
2017-01-10 10:25:10 -06:00
|
|
|
|
2017-07-18 08:20:38 -05:00
|
|
|
try {
|
|
|
|
regex = rawRegex && new RegExp(rawRegex, 'i');
|
|
|
|
} catch (e) {
|
|
|
|
// Bad regex, don't affect filters
|
2017-01-10 10:25:10 -06:00
|
|
|
}
|
|
|
|
|
2017-07-18 08:20:38 -05:00
|
|
|
return statusIds.filter(id => {
|
|
|
|
const statusForId = statuses.get(id);
|
|
|
|
let showStatus = true;
|
2017-01-10 10:25:10 -06:00
|
|
|
|
2017-07-18 08:20:38 -05:00
|
|
|
if (columnSettings.getIn(['shows', 'reblog']) === false) {
|
|
|
|
showStatus = showStatus && statusForId.get('reblog') === null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (columnSettings.getIn(['shows', 'reply']) === false) {
|
|
|
|
showStatus = showStatus && (statusForId.get('in_reply_to_id') === null || statusForId.get('in_reply_to_account_id') === me);
|
2017-01-10 10:25:10 -06:00
|
|
|
}
|
|
|
|
|
2017-12-06 19:50:27 -06:00
|
|
|
if (columnSettings.getIn(['shows', 'direct']) === false) {
|
|
|
|
showStatus = showStatus && statusForId.get('visibility') !== 'direct';
|
|
|
|
}
|
|
|
|
|
2017-07-18 08:20:38 -05:00
|
|
|
if (showStatus && regex && statusForId.get('account') !== me) {
|
|
|
|
const searchIndex = statusForId.get('reblog') ? statuses.getIn([statusForId.get('reblog'), 'search_index']) : statusForId.get('search_index');
|
|
|
|
showStatus = !regex.test(searchIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return showStatus;
|
|
|
|
});
|
|
|
|
});
|
2016-09-04 07:04:26 -05:00
|
|
|
|
2017-02-20 17:10:49 -06:00
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getStatusIds = makeGetStatusIds();
|
|
|
|
|
2017-06-11 10:07:35 -05:00
|
|
|
const mapStateToProps = (state, { timelineId }) => ({
|
|
|
|
statusIds: getStatusIds(state, { type: timelineId }),
|
|
|
|
isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
|
2018-01-18 10:25:37 -06:00
|
|
|
isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
|
2017-06-11 10:07:35 -05:00
|
|
|
hasMore: !!state.getIn(['timelines', timelineId, 'next']),
|
2017-02-20 17:10:49 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
2016-08-24 10:56:44 -05:00
|
|
|
|
2017-06-11 10:07:35 -05:00
|
|
|
const mapDispatchToProps = (dispatch, { timelineId, loadMore }) => ({
|
2016-12-03 14:04:57 -06:00
|
|
|
|
2017-05-06 04:05:32 -05:00
|
|
|
onScrollToBottom: debounce(() => {
|
2017-06-11 10:07:35 -05:00
|
|
|
dispatch(scrollTopTimeline(timelineId, false));
|
|
|
|
loadMore();
|
2017-06-01 10:25:10 -05:00
|
|
|
}, 300, { leading: true }),
|
2016-12-03 14:04:57 -06:00
|
|
|
|
2017-05-06 04:05:32 -05:00
|
|
|
onScrollToTop: debounce(() => {
|
2017-06-11 10:07:35 -05:00
|
|
|
dispatch(scrollTopTimeline(timelineId, true));
|
2017-05-06 04:05:32 -05:00
|
|
|
}, 100),
|
2017-01-10 10:25:10 -06:00
|
|
|
|
2017-05-06 04:05:32 -05:00
|
|
|
onScroll: debounce(() => {
|
2017-06-11 10:07:35 -05:00
|
|
|
dispatch(scrollTopTimeline(timelineId, false));
|
2017-05-20 10:31:47 -05:00
|
|
|
}, 100),
|
2017-01-10 10:25:10 -06:00
|
|
|
|
|
|
|
});
|
2016-08-31 15:58:10 -05:00
|
|
|
|
2017-02-20 17:10:49 -06:00
|
|
|
export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);
|